1 # $Id: init.py,v 1.12 2001-08-05 07:43:52 richard Exp $
3 import os, shutil, sys, errno
5 import roundup.instance
7 def copytree(src, dst, symlinks=0):
8 """Recursively copy a directory tree using copy2().
10 The destination directory os allowed to exist.
12 If the optional symlinks flag is true, symbolic links in the
13 source tree result in symbolic links in the destination tree; if
14 it is false, the contents of the files pointed to by symbolic
15 links are copied.
17 XXX copied from shutil.py in std lib
19 """
20 names = os.listdir(src)
21 try:
22 os.mkdir(dst)
23 except OSError, error:
24 if error.errno != errno.EEXIST: raise
25 for name in names:
26 srcname = os.path.join(src, name)
27 dstname = os.path.join(dst, name)
28 if symlinks and os.path.islink(srcname):
29 linkto = os.readlink(srcname)
30 os.symlink(linkto, dstname)
31 elif os.path.isdir(srcname):
32 copytree(srcname, dstname, symlinks)
33 else:
34 shutil.copy2(srcname, dstname)
36 def init(instance_home, template, backend, adminpw):
37 ''' initialise an instance using the named template
38 '''
39 # first, copy the template dir over
40 import roundup.templatebuilder
42 template_dir = os.path.split(__file__)[0]
43 template_name = template
44 template = os.path.join(template_dir, 'templates', template)
45 copytree(template, instance_home)
47 roundup.templatebuilder.installHtmlBase(template_name, instance_home)
49 # now select database
50 db = '''# WARNING: DO NOT EDIT THIS FILE!!!
51 from roundup.backends.back_%s import Database'''%backend
52 open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
54 # now import the instance and call its init
55 instance = roundup.instance.open(instance_home)
56 instance.init(adminpw)
58 #
59 # $Log: not supported by cvs2svn $
60 # Revision 1.11 2001/08/04 22:42:43 richard
61 # Fixed sf.net bug #447671 - typo
62 #
63 # Revision 1.10 2001/08/03 01:28:33 richard
64 # Used the much nicer load_package, pointed out by Steve Majewski.
65 #
66 # Revision 1.9 2001/08/03 00:59:34 richard
67 # Instance import now imports the instance using imp.load_module so that
68 # we can have instance homes of "roundup" or other existing python package
69 # names.
70 #
71 # Revision 1.8 2001/07/29 07:01:39 richard
72 # Added vim command to all source so that we don't get no steenkin' tabs :)
73 #
74 # Revision 1.7 2001/07/28 07:59:53 richard
75 # Replaced errno integers with their module values.
76 # De-tabbed templatebuilder.py
77 #
78 # Revision 1.6 2001/07/24 11:18:25 anthonybaxter
79 # oops. left a print in
80 #
81 # Revision 1.5 2001/07/24 10:54:11 anthonybaxter
82 # oops. Html.
83 #
84 # Revision 1.4 2001/07/24 10:46:22 anthonybaxter
85 # Added templatebuilder module. two functions - one to pack up the html base,
86 # one to unpack it. Packed up the two standard templates into htmlbases.
87 # Modified __init__ to install them.
88 #
89 # __init__.py magic was needed for the rather high levels of wierd import magic.
90 # Reducing level of import magic == (good, future)
91 #
92 # Revision 1.3 2001/07/23 08:45:28 richard
93 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
94 # workable instance_home set up :)
95 # _and_ anydbm has had its first test :)
96 #
97 # Revision 1.2 2001/07/22 12:09:32 richard
98 # Final commit of Grande Splite
99 #
100 #
101 # vim: set filetype=python ts=4 sw=4 et si