4174afc8a0167ad99aa33159b1006d5dc66f493d
1 import os, shutil, sys
3 def copytree(src, dst, symlinks=0):
4 """Recursively copy a directory tree using copy2().
6 The destination directory os allowed to exist.
8 If the optional symlinks flag is true, symbolic links in the
9 source tree result in symbolic links in the destination tree; if
10 it is false, the contents of the files pointed to by symbolic
11 links are copied.
13 XXX copied from shutil.py in std lib
15 """
16 names = os.listdir(src)
17 try:
18 os.mkdir(dst)
19 except OSError, error:
20 if error.errno != 17: raise
21 for name in names:
22 srcname = os.path.join(src, name)
23 dstname = os.path.join(dst, name)
24 if symlinks and os.path.islink(srcname):
25 linkto = os.readlink(srcname)
26 os.symlink(linkto, dstname)
27 elif os.path.isdir(srcname):
28 copytree(srcname, dstname, symlinks)
29 else:
30 shutil.copy2(srcname, dstname)
32 def init(instance, template, adminpw):
33 ''' initialise an instance using the named template
34 '''
35 # first, copy the template dir over
36 template_dir = os.path.split(__file__)[0]
37 template = os.path.join(template_dir, 'templates', template)
38 copytree(template, instance)
40 # now import the instance and call its init
41 path, instance = os.path.split(instance)
42 sys.path.insert(0, path)
43 instance = __import__(instance)
44 instance.init(adminpw)