1 # $Id: init.py,v 1.11 2001-08-04 22:42:43 richard Exp $
3 import os, shutil, sys, errno, imp
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 != errno.EEXIST: 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_home, template, backend, adminpw):
35 ''' initialise an instance using the named template
36 '''
37 # first, copy the template dir over
38 import roundup.templatebuilder
40 template_dir = os.path.split(__file__)[0]
41 template_name = template
42 template = os.path.join(template_dir, 'templates', template)
43 copytree(template, instance_home)
45 roundup.templatebuilder.installHtmlBase(template_name, instance_home)
47 # now select database
48 db = '''# WARNING: DO NOT EDIT THIS FILE!!!
49 from roundup.backends.back_%s import Database'''%backend
50 open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
52 # now import the instance and call its init
53 instance = imp.load_package('instance', instance_home)
54 instance.init(adminpw)
56 #
57 # $Log: not supported by cvs2svn $
58 # Revision 1.10 2001/08/03 01:28:33 richard
59 # Used the much nicer load_package, pointed out by Steve Majewski.
60 #
61 # Revision 1.9 2001/08/03 00:59:34 richard
62 # Instance import now imports the instance using imp.load_module so that
63 # we can have instance homes of "roundup" or other existing python package
64 # names.
65 #
66 # Revision 1.8 2001/07/29 07:01:39 richard
67 # Added vim command to all source so that we don't get no steenkin' tabs :)
68 #
69 # Revision 1.7 2001/07/28 07:59:53 richard
70 # Replaced errno integers with their module values.
71 # De-tabbed templatebuilder.py
72 #
73 # Revision 1.6 2001/07/24 11:18:25 anthonybaxter
74 # oops. left a print in
75 #
76 # Revision 1.5 2001/07/24 10:54:11 anthonybaxter
77 # oops. Html.
78 #
79 # Revision 1.4 2001/07/24 10:46:22 anthonybaxter
80 # Added templatebuilder module. two functions - one to pack up the html base,
81 # one to unpack it. Packed up the two standard templates into htmlbases.
82 # Modified __init__ to install them.
83 #
84 # __init__.py magic was needed for the rather high levels of wierd import magic.
85 # Reducing level of import magic == (good, future)
86 #
87 # Revision 1.3 2001/07/23 08:45:28 richard
88 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
89 # workable instance_home set up :)
90 # _and_ anydbm has had its first test :)
91 #
92 # Revision 1.2 2001/07/22 12:09:32 richard
93 # Final commit of Grande Splite
94 #
95 #
96 # vim: set filetype=python ts=4 sw=4 et si