Code

Added documentaion.
[roundup.git] / roundup / init.py
1 # $Id: init.py,v 1.13 2001-08-06 01:20:00 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 and backend.
39     instance_home - the directory to place the instance data in
40     template - the template to use in creating the instance data
41     backend - the database to use to store the instance data
42     adminpw - the password for the "admin" user
44     The instance_home directory will be created using the files found in
45     the named template (roundup.templates.<name>). A standard instance_home
46     contains:
47         . instance_config.py
48           - simple configuration of things like the email address for the
49             mail gateway, the mail domain, the mail host, ...
50         . dbinit.py and select_db.py
51           - defines the schema for the hyperdatabase and indicates which
52             backend to use.
53         . interfaces.py
54           - defines the CGI Client and mail gateway MailGW classes that are
55             used by roundup.cgi, roundup-server and roundup-mailgw.
56         . __init__.py
57           - ties together all the instance information into one interface
58         . db/
59           - the actual database that stores the instance's data
60         . html/
61           - the html templates that are used by the CGI Client
62         . detectors/
63           - the auditor and reactor modules for this instance
65     The html directory is typically extracted from the htmlbase module in
66     the template.
67     '''
68     # first, copy the template dir over
69     import roundup.templatebuilder
71     template_dir = os.path.split(__file__)[0]
72     template_name = template
73     template = os.path.join(template_dir, 'templates', template)
74     copytree(template, instance_home)
76     roundup.templatebuilder.installHtmlBase(template_name, instance_home)
78     # now select database
79     db = '''# WARNING: DO NOT EDIT THIS FILE!!!
80 from roundup.backends.back_%s import Database'''%backend
81     open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
83     # now import the instance and call its init
84     instance = roundup.instance.open(instance_home)
85     instance.init(adminpw)
87 #
88 # $Log: not supported by cvs2svn $
89 # Revision 1.12  2001/08/05 07:43:52  richard
90 # Instances are now opened by a special function that generates a unique
91 # module name for the instances on import time.
92 #
93 # Revision 1.11  2001/08/04 22:42:43  richard
94 # Fixed sf.net bug #447671 - typo
95 #
96 # Revision 1.10  2001/08/03 01:28:33  richard
97 # Used the much nicer load_package, pointed out by Steve Majewski.
98 #
99 # Revision 1.9  2001/08/03 00:59:34  richard
100 # Instance import now imports the instance using imp.load_module so that
101 # we can have instance homes of "roundup" or other existing python package
102 # names.
104 # Revision 1.8  2001/07/29 07:01:39  richard
105 # Added vim command to all source so that we don't get no steenkin' tabs :)
107 # Revision 1.7  2001/07/28 07:59:53  richard
108 # Replaced errno integers with their module values.
109 # De-tabbed templatebuilder.py
111 # Revision 1.6  2001/07/24 11:18:25  anthonybaxter
112 # oops. left a print in
114 # Revision 1.5  2001/07/24 10:54:11  anthonybaxter
115 # oops. Html.
117 # Revision 1.4  2001/07/24 10:46:22  anthonybaxter
118 # Added templatebuilder module. two functions - one to pack up the html base,
119 # one to unpack it. Packed up the two standard templates into htmlbases.
120 # Modified __init__ to install them.
122 # __init__.py magic was needed for the rather high levels of wierd import magic.
123 # Reducing level of import magic == (good, future)
125 # Revision 1.3  2001/07/23 08:45:28  richard
126 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
127 # workable instance_home set up :)
128 # _and_ anydbm has had its first test :)
130 # Revision 1.2  2001/07/22 12:09:32  richard
131 # Final commit of Grande Splite
134 # vim: set filetype=python ts=4 sw=4 et si