Code

Added the copyright/license notice to (nearly) all files at request of
[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 THE 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.14 2001-08-07 00:15:51 richard Exp $
20 import os, shutil, sys, errno
22 import roundup.instance
24 def copytree(src, dst, symlinks=0):
25     """Recursively copy a directory tree using copy2().
27     The destination directory os allowed to exist.
29     If the optional symlinks flag is true, symbolic links in the
30     source tree result in symbolic links in the destination tree; if
31     it is false, the contents of the files pointed to by symbolic
32     links are copied.
34     XXX copied from shutil.py in std lib
36     """
37     names = os.listdir(src)
38     try:
39         os.mkdir(dst)
40     except OSError, error:
41         if error.errno != errno.EEXIST: raise
42     for name in names:
43         srcname = os.path.join(src, name)
44         dstname = os.path.join(dst, name)
45         if symlinks and os.path.islink(srcname):
46             linkto = os.readlink(srcname)
47             os.symlink(linkto, dstname)
48         elif os.path.isdir(srcname):
49             copytree(srcname, dstname, symlinks)
50         else:
51             shutil.copy2(srcname, dstname)
53 def init(instance_home, template, backend, adminpw):
54     '''Initialise an instance using the named template and backend.
56     instance_home - the directory to place the instance data in
57     template - the template to use in creating the instance data
58     backend - the database to use to store the instance data
59     adminpw - the password for the "admin" user
61     The instance_home directory will be created using the files found in
62     the named template (roundup.templates.<name>). A standard instance_home
63     contains:
64         . instance_config.py
65           - simple configuration of things like the email address for the
66             mail gateway, the mail domain, the mail host, ...
67         . dbinit.py and select_db.py
68           - defines the schema for the hyperdatabase and indicates which
69             backend to use.
70         . interfaces.py
71           - defines the CGI Client and mail gateway MailGW classes that are
72             used by roundup.cgi, roundup-server and roundup-mailgw.
73         . __init__.py
74           - ties together all the instance information into one interface
75         . db/
76           - the actual database that stores the instance's data
77         . html/
78           - the html templates that are used by the CGI Client
79         . detectors/
80           - the auditor and reactor modules for this instance
82     The html directory is typically extracted from the htmlbase module in
83     the template.
84     '''
85     # first, copy the template dir over
86     import roundup.templatebuilder
88     template_dir = os.path.split(__file__)[0]
89     template_name = template
90     template = os.path.join(template_dir, 'templates', template)
91     copytree(template, instance_home)
93     roundup.templatebuilder.installHtmlBase(template_name, instance_home)
95     # now select database
96     db = '''# WARNING: DO NOT EDIT THIS FILE!!!
97 from roundup.backends.back_%s import Database'''%backend
98     open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
100     # now import the instance and call its init
101     instance = roundup.instance.open(instance_home)
102     instance.init(adminpw)
105 # $Log: not supported by cvs2svn $
106 # Revision 1.13  2001/08/06 01:20:00  richard
107 # Added documentaion.
109 # Revision 1.12  2001/08/05 07:43:52  richard
110 # Instances are now opened by a special function that generates a unique
111 # module name for the instances on import time.
113 # Revision 1.11  2001/08/04 22:42:43  richard
114 # Fixed sf.net bug #447671 - typo
116 # Revision 1.10  2001/08/03 01:28:33  richard
117 # Used the much nicer load_package, pointed out by Steve Majewski.
119 # Revision 1.9  2001/08/03 00:59:34  richard
120 # Instance import now imports the instance using imp.load_module so that
121 # we can have instance homes of "roundup" or other existing python package
122 # names.
124 # Revision 1.8  2001/07/29 07:01:39  richard
125 # Added vim command to all source so that we don't get no steenkin' tabs :)
127 # Revision 1.7  2001/07/28 07:59:53  richard
128 # Replaced errno integers with their module values.
129 # De-tabbed templatebuilder.py
131 # Revision 1.6  2001/07/24 11:18:25  anthonybaxter
132 # oops. left a print in
134 # Revision 1.5  2001/07/24 10:54:11  anthonybaxter
135 # oops. Html.
137 # Revision 1.4  2001/07/24 10:46:22  anthonybaxter
138 # Added templatebuilder module. two functions - one to pack up the html base,
139 # one to unpack it. Packed up the two standard templates into htmlbases.
140 # Modified __init__ to install them.
142 # __init__.py magic was needed for the rather high levels of wierd import magic.
143 # Reducing level of import magic == (good, future)
145 # Revision 1.3  2001/07/23 08:45:28  richard
146 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
147 # workable instance_home set up :)
148 # _and_ anydbm has had its first test :)
150 # Revision 1.2  2001/07/22 12:09:32  richard
151 # Final commit of Grande Splite
154 # vim: set filetype=python ts=4 sw=4 et si