b1156fedb59a819590708f307a702ae841be0cc8
1 # $Id: init.py,v 1.5 2001-07-24 10:54:11 anthonybaxter 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 print "making", dst
22 except OSError, error:
23 if error.errno != 17: raise
24 for name in names:
25 srcname = os.path.join(src, name)
26 dstname = os.path.join(dst, name)
27 if symlinks and os.path.islink(srcname):
28 linkto = os.readlink(srcname)
29 os.symlink(linkto, dstname)
30 elif os.path.isdir(srcname):
31 copytree(srcname, dstname, symlinks)
32 else:
33 shutil.copy2(srcname, dstname)
35 def init(instance, template, backend, adminpw):
36 ''' initialise an instance using the named template
37 '''
38 # first, copy the template dir over
39 import roundup.templatebuilder
41 template_dir = os.path.split(__file__)[0]
42 template_name = template
43 template = os.path.join(template_dir, 'templates', template)
44 copytree(template, instance)
46 roundup.templatebuilder.installHtmlBase(template_name, instance)
48 # now select database
49 db = '''# WARNING: DO NOT EDIT THIS FILE!!!
50 from roundup.backends.back_%s import Database'''%backend
51 open(os.path.join(instance, 'select_db.py'), 'w').write(db)
53 # now import the instance and call its init
54 path, instance = os.path.split(instance)
55 sys.path.insert(0, path)
56 instance = __import__(instance)
57 instance.init(adminpw)
59 #
60 # $Log: not supported by cvs2svn $
61 # Revision 1.4 2001/07/24 10:46:22 anthonybaxter
62 # Added templatebuilder module. two functions - one to pack up the html base,
63 # one to unpack it. Packed up the two standard templates into htmlbases.
64 # Modified __init__ to install them.
65 #
66 # __init__.py magic was needed for the rather high levels of wierd import magic.
67 # Reducing level of import magic == (good, future)
68 #
69 # Revision 1.3 2001/07/23 08:45:28 richard
70 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
71 # workable instance_home set up :)
72 # _and_ anydbm has had its first test :)
73 #
74 # Revision 1.2 2001/07/22 12:09:32 richard
75 # Final commit of Grande Splite
76 #
77 #