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