Code

. re-open the database as the author in mail handling
[roundup.git] / roundup / init.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17
18 # $Id: init.py,v 1.17 2001-11-12 23:17:38 jhermann Exp $
20 import os, sys, errno
22 import roundup.instance, password
23 from roundup import install_util
25 def copytree(src, dst, symlinks=0):
26     """Recursively copy a directory tree using copyDigestedFile().
28     The destination directory os allowed to exist.
30     If the optional symlinks flag is true, symbolic links in the
31     source tree result in symbolic links in the destination tree; if
32     it is false, the contents of the files pointed to by symbolic
33     links are copied.
35     XXX copied from shutil.py in std lib
37     """
38     names = os.listdir(src)
39     try:
40         os.mkdir(dst)
41     except OSError, error:
42         if error.errno != errno.EEXIST: raise
43     for name in names:
44         srcname = os.path.join(src, name)
45         dstname = os.path.join(dst, name)
46         if symlinks and os.path.islink(srcname):
47             linkto = os.readlink(srcname)
48             os.symlink(linkto, dstname)
49         elif os.path.isdir(srcname):
50             copytree(srcname, dstname, symlinks)
51         else:
52             install_util.copyDigestedFile(srcname, dstname)
54 def init(instance_home, template, backend, adminpw):
55     '''Initialise an instance using the named template and backend.
57     instance_home - the directory to place the instance data in
58     template - the template to use in creating the instance data
59     backend - the database to use to store the instance data
60     adminpw - the password for the "admin" user
62     The instance_home directory will be created using the files found in
63     the named template (roundup.templates.<name>). A standard instance_home
64     contains:
65         . instance_config.py
66           - simple configuration of things like the email address for the
67             mail gateway, the mail domain, the mail host, ...
68         . dbinit.py and select_db.py
69           - defines the schema for the hyperdatabase and indicates which
70             backend to use.
71         . interfaces.py
72           - defines the CGI Client and mail gateway MailGW classes that are
73             used by roundup.cgi, roundup-server and roundup-mailgw.
74         . __init__.py
75           - ties together all the instance information into one interface
76         . db/
77           - the actual database that stores the instance's data
78         . html/
79           - the html templates that are used by the CGI Client
80         . detectors/
81           - the auditor and reactor modules for this instance
83     The html directory is typically extracted from the htmlbase module in
84     the template.
85     '''
86     # first, copy the template dir over
87     import roundup.templatebuilder
89     template_dir = os.path.split(__file__)[0]
90     template_name = template
91     template = os.path.join(template_dir, 'templates', template)
92     copytree(template, instance_home)
94     roundup.templatebuilder.installHtmlBase(template_name, instance_home)
96     # now select database
97     db = '''# WARNING: DO NOT EDIT THIS FILE!!!
98 from roundup.backends.back_%s import Database'''%backend
99     open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
101     # now import the instance and call its init
102     instance = roundup.instance.open(instance_home)
103     instance.init(password.Password(adminpw))
106 # $Log: not supported by cvs2svn $
107 # Revision 1.16  2001/10/09 07:25:59  richard
108 # Added the Password property type. See "pydoc roundup.password" for
109 # implementation details. Have updated some of the documentation too.
111 # Revision 1.15  2001/08/07 00:24:42  richard
112 # stupid typo
114 # Revision 1.14  2001/08/07 00:15:51  richard
115 # Added the copyright/license notice to (nearly) all files at request of
116 # Bizar Software.
118 # Revision 1.13  2001/08/06 01:20:00  richard
119 # Added documentaion.
121 # Revision 1.12  2001/08/05 07:43:52  richard
122 # Instances are now opened by a special function that generates a unique
123 # module name for the instances on import time.
125 # Revision 1.11  2001/08/04 22:42:43  richard
126 # Fixed sf.net bug #447671 - typo
128 # Revision 1.10  2001/08/03 01:28:33  richard
129 # Used the much nicer load_package, pointed out by Steve Majewski.
131 # Revision 1.9  2001/08/03 00:59:34  richard
132 # Instance import now imports the instance using imp.load_module so that
133 # we can have instance homes of "roundup" or other existing python package
134 # names.
136 # Revision 1.8  2001/07/29 07:01:39  richard
137 # Added vim command to all source so that we don't get no steenkin' tabs :)
139 # Revision 1.7  2001/07/28 07:59:53  richard
140 # Replaced errno integers with their module values.
141 # De-tabbed templatebuilder.py
143 # Revision 1.6  2001/07/24 11:18:25  anthonybaxter
144 # oops. left a print in
146 # Revision 1.5  2001/07/24 10:54:11  anthonybaxter
147 # oops. Html.
149 # Revision 1.4  2001/07/24 10:46:22  anthonybaxter
150 # Added templatebuilder module. two functions - one to pack up the html base,
151 # one to unpack it. Packed up the two standard templates into htmlbases.
152 # Modified __init__ to install them.
154 # __init__.py magic was needed for the rather high levels of wierd import magic.
155 # Reducing level of import magic == (good, future)
157 # Revision 1.3  2001/07/23 08:45:28  richard
158 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
159 # workable instance_home set up :)
160 # _and_ anydbm has had its first test :)
162 # Revision 1.2  2001/07/22 12:09:32  richard
163 # Final commit of Grande Splite
166 # vim: set filetype=python ts=4 sw=4 et si