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.24 2002-09-10 12:44:42 richard Exp $
20 __doc__ = """
21 Init (create) a roundup instance.
22 """
24 import os, sys, errno
26 import roundup.instance, password
27 from roundup import install_util
29 def copytree(src, dst, symlinks=0):
30 """Recursively copy a directory tree using copyDigestedFile().
32 The destination directory os allowed to exist.
34 If the optional symlinks flag is true, symbolic links in the
35 source tree result in symbolic links in the destination tree; if
36 it is false, the contents of the files pointed to by symbolic
37 links are copied.
39 This was copied from shutil.py in std lib.
41 """
42 names = os.listdir(src)
43 try:
44 os.mkdir(dst)
45 except OSError, error:
46 if error.errno != errno.EEXIST: raise
47 for name in names:
48 srcname = os.path.join(src, name)
49 dstname = os.path.join(dst, name)
50 if symlinks and os.path.islink(srcname):
51 linkto = os.readlink(srcname)
52 os.symlink(linkto, dstname)
53 elif os.path.isdir(srcname):
54 copytree(srcname, dstname, symlinks)
55 else:
56 install_util.copyDigestedFile(srcname, dstname)
58 def install(instance_home, template, backend):
59 '''Install an instance using the named template and backend.
61 instance_home - the directory to place the instance data in
62 template - the template to use in creating the instance data
63 backend - the database to use to store the instance data
65 The instance_home directory will be created using the files found in
66 the named template (roundup.templates.<name>). A standard instance_home
67 contains:
68 . config.py
69 - simple configuration of things like the email address for the
70 mail gateway, the mail domain, the mail host, ...
71 . dbinit.py and select_db.py
72 - defines the schema for the hyperdatabase and indicates which
73 backend to use.
74 . interfaces.py
75 - defines the CGI Client and mail gateway MailGW classes that are
76 used by roundup.cgi, roundup-server and roundup-mailgw.
77 . __init__.py
78 - ties together all the instance information into one interface
79 . db/
80 - the actual database that stores the instance's data
81 . html/
82 - the html templates that are used by the CGI Client
83 . detectors/
84 - the auditor and reactor modules for this instance
86 The html directory is typically extracted from the htmlbase module in
87 the template.
88 '''
89 # first, copy the template dir over
90 from roundup.templates import builder
92 # copy the roundup.templates.<template> package contents to the instance dir
93 template_dir = os.path.split(__file__)[0]
94 template_name = template
95 template = os.path.join(template_dir, 'templates', template)
96 copytree(template, instance_home)
98 builder.installHtmlBase(template_name, instance_home)
100 # now select database
101 db = '''# WARNING: DO NOT EDIT THIS FILE!!!
102 from roundup.backends.back_%s import Database, Class, FileClass, IssueClass
103 '''%backend
104 open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
107 def initialise(instance_home, adminpw):
108 '''Initialise an instance's database
110 adminpw - the password for the "admin" user
111 '''
112 # now import the instance and call its init
113 instance = roundup.instance.open(instance_home)
114 instance.init(password.Password(adminpw))
116 # vim: set filetype=python ts=4 sw=4 et si