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: dbinit.py,v 1.13 2002-01-02 02:31:38 richard Exp $
20 import os
22 import instance_config
23 from roundup import roundupdb
24 import select_db
26 from roundup.roundupdb import Class, FileClass
28 class Database(roundupdb.Database, select_db.Database):
29 ''' Creates a hybrid database from:
30 . the selected database back-end from select_db
31 . the roundup extensions from roundupdb
32 '''
33 pass
35 class IssueClass(roundupdb.IssueClass):
36 ''' issues need the email information
37 '''
38 INSTANCE_NAME = instance_config.INSTANCE_NAME
39 ISSUE_TRACKER_WEB = instance_config.ISSUE_TRACKER_WEB
40 ISSUE_TRACKER_EMAIL = instance_config.ISSUE_TRACKER_EMAIL
41 ADMIN_EMAIL = instance_config.ADMIN_EMAIL
42 MAILHOST = instance_config.MAILHOST
43 MESSAGES_TO_AUTHOR = instance_config.MESSAGES_TO_AUTHOR
44 EMAIL_SIGNATURE_POSITION = instance_config.EMAIL_SIGNATURE_POSITION
47 def open(name=None):
48 ''' as from the roundupdb method openDB
50 '''
51 from roundup.hyperdb import String, Password, Date, Link, Multilink
53 # open the database
54 db = Database(instance_config.DATABASE, name)
56 # Now initialise the schema. Must do this each time.
57 pri = Class(db, "priority",
58 name=String(), order=String())
59 pri.setkey("name")
61 stat = Class(db, "status",
62 name=String(), order=String())
63 stat.setkey("name")
65 keyword = Class(db, "keyword",
66 name=String())
67 keyword.setkey("name")
69 user = Class(db, "user",
70 username=String(), password=Password(),
71 address=String(), realname=String(),
72 phone=String(), organisation=String())
73 user.setkey("username")
75 msg = FileClass(db, "msg",
76 author=Link("user"), recipients=Multilink("user"),
77 date=Date(), summary=String(),
78 files=Multilink("file"),
79 messageid=String(), inreplyto=String())
81 file = FileClass(db, "file",
82 name=String(), type=String())
84 issue = IssueClass(db, "issue",
85 assignedto=Link("user"), topic=Multilink("keyword"),
86 priority=Link("priority"), status=Link("status"))
87 issue.setkey('title')
89 import detectors
90 detectors.init(db)
92 return db
94 def init(adminpw):
95 ''' as from the roundupdb method initDB
97 Open the new database, and set up a bunch of attributes.
99 '''
100 dbdir = os.path.join(instance_config.DATABASE, 'files')
101 if not os.path.isdir(dbdir):
102 os.makedirs(dbdir)
104 db = open("admin")
105 db.clear()
107 pri = db.getclass('priority')
108 pri.create(name="critical", order="1")
109 pri.create(name="urgent", order="2")
110 pri.create(name="bug", order="3")
111 pri.create(name="feature", order="4")
112 pri.create(name="wish", order="5")
114 stat = db.getclass('status')
115 stat.create(name="unread", order="1")
116 stat.create(name="deferred", order="2")
117 stat.create(name="chatting", order="3")
118 stat.create(name="need-eg", order="4")
119 stat.create(name="in-progress", order="5")
120 stat.create(name="testing", order="6")
121 stat.create(name="done-cbb", order="7")
122 stat.create(name="resolved", order="8")
124 user = db.getclass('user')
125 user.create(username="admin", password=adminpw,
126 address=instance_config.ADMIN_EMAIL)
127 db.commit()
129 #
130 # $Log: not supported by cvs2svn $
131 # Revision 1.12 2001/12/02 05:06:16 richard
132 # . We now use weakrefs in the Classes to keep the database reference, so
133 # the close() method on the database is no longer needed.
134 # I bumped the minimum python requirement up to 2.1 accordingly.
135 # . #487480 ] roundup-server
136 # . #487476 ] INSTALL.txt
137 #
138 # I also cleaned up the change message / post-edit stuff in the cgi client.
139 # There's now a clearly marked "TODO: append the change note" where I believe
140 # the change note should be added there. The "changes" list will obviously
141 # have to be modified to be a dict of the changes, or somesuch.
142 #
143 # More testing needed.
144 #
145 # Revision 1.11 2001/12/01 07:17:50 richard
146 # . We now have basic transaction support! Information is only written to
147 # the database when the commit() method is called. Only the anydbm
148 # backend is modified in this way - neither of the bsddb backends have been.
149 # The mail, admin and cgi interfaces all use commit (except the admin tool
150 # doesn't have a commit command, so interactive users can't commit...)
151 # . Fixed login/registration forwarding the user to the right page (or not,
152 # on a failure)
153 #
154 # Revision 1.10 2001/11/26 22:55:56 richard
155 # Feature:
156 # . Added INSTANCE_NAME to configuration - used in web and email to identify
157 # the instance.
158 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
159 # signature info in e-mails.
160 # . Some more flexibility in the mail gateway and more error handling.
161 # . Login now takes you to the page you back to the were denied access to.
162 #
163 # Fixed:
164 # . Lots of bugs, thanks Roché and others on the devel mailing list!
165 #
166 # Revision 1.9 2001/10/30 00:54:45 richard
167 # Features:
168 # . #467129 ] Lossage when username=e-mail-address
169 # . #473123 ] Change message generation for author
170 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
171 #
172 # Revision 1.8 2001/10/09 07:25:59 richard
173 # Added the Password property type. See "pydoc roundup.password" for
174 # implementation details. Have updated some of the documentation too.
175 #
176 # Revision 1.7 2001/08/07 00:24:43 richard
177 # stupid typo
178 #
179 # Revision 1.6 2001/08/07 00:15:51 richard
180 # Added the copyright/license notice to (nearly) all files at request of
181 # Bizar Software.
182 #
183 # Revision 1.5 2001/08/02 06:38:17 richard
184 # Roundupdb now appends "mailing list" information to its messages which
185 # include the e-mail address and web interface address. Templates may
186 # override this in their db classes to include specific information (support
187 # instructions, etc).
188 #
189 # Revision 1.4 2001/07/29 07:01:39 richard
190 # Added vim command to all source so that we don't get no steenkin' tabs :)
191 #
192 # Revision 1.3 2001/07/24 10:46:22 anthonybaxter
193 # Added templatebuilder module. two functions - one to pack up the html base,
194 # one to unpack it. Packed up the two standard templates into htmlbases.
195 # Modified __init__ to install them.
196 #
197 # __init__.py magic was needed for the rather high levels of wierd import magic.
198 # Reducing level of import magic == (good, future)
199 #
200 # Revision 1.2 2001/07/24 01:06:43 richard
201 # Oops - accidentally duped the keywords class
202 #
203 # Revision 1.1 2001/07/23 23:28:43 richard
204 # Adding the classic template
205 #
206 # Revision 1.4 2001/07/23 08:45:28 richard
207 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
208 # workable instance_home set up :)
209 # _and_ anydbm has had its first test :)
210 #
211 # Revision 1.3 2001/07/23 07:14:41 richard
212 # Moved the database backends off into backends.
213 #
214 # Revision 1.2 2001/07/23 06:25:50 richard
215 # relfected the move to roundup/backends
216 #
217 # Revision 1.1 2001/07/23 04:33:21 anthonybaxter
218 # split __init__.py into 2. dbinit and instance_config.
219 #
220 # Revision 1.1 2001/07/23 03:50:46 anthonybaxter
221 # moved templates to proper location
222 #
223 # Revision 1.2 2001/07/22 12:09:32 richard
224 # Final commit of Grande Splite
225 #
226 #
227 # vim: set filetype=python ts=4 sw=4 et si