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.17 2002-05-24 04:03:23 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 pass
41 def open(name=None):
42 ''' as from the roundupdb method openDB
44 '''
45 from roundup.hyperdb import String, Password, Date, Link, Multilink
47 # open the database
48 db = Database(instance_config, name)
50 #
51 # Now initialise the schema. Must do this each time the database is
52 # opened.
53 #
55 # Class automatically gets these properties:
56 # creation = Date()
57 # activity = Date()
58 # creator = Link('user')
59 pri = Class(db, "priority",
60 name=String(), order=String())
61 pri.setkey("name")
63 stat = Class(db, "status",
64 name=String(), order=String())
65 stat.setkey("name")
67 keyword = Class(db, "keyword",
68 name=String())
69 keyword.setkey("name")
71 user = Class(db, "user",
72 username=String(), password=Password(),
73 address=String(), realname=String(),
74 phone=String(), organisation=String(),
75 alternate_addresses=String())
76 user.setkey("username")
78 # FileClass automatically gets these properties:
79 # content = String() [saved to disk in <instance home>/db/files/]
80 # (it also gets the Class properties creation, activity and creator)
81 msg = FileClass(db, "msg",
82 author=Link("user"), recipients=Multilink("user"),
83 date=Date(), summary=String(),
84 files=Multilink("file"),
85 messageid=String(), inreplyto=String())
87 file = FileClass(db, "file",
88 name=String(), type=String())
90 # IssueClass automatically gets these properties:
91 # title = String()
92 # messages = Multilink("msg")
93 # files = Multilink("file")
94 # nosy = Multilink("user")
95 # superseder = Multilink("issue")
96 # (it also gets the Class properties creation, activity and creator)
97 issue = IssueClass(db, "issue",
98 assignedto=Link("user"), topic=Multilink("keyword"),
99 priority=Link("priority"), status=Link("status"))
101 import detectors
102 detectors.init(db)
104 return db
106 def init(adminpw):
107 ''' as from the roundupdb method initDB
109 Open the new database, and add new nodes - used for initialisation. You
110 can edit this before running the "roundup-admin initialise" command to
111 change the initial database entries.
112 '''
113 dbdir = os.path.join(instance_config.DATABASE, 'files')
114 if not os.path.isdir(dbdir):
115 os.makedirs(dbdir)
117 db = open("admin")
118 db.clear()
120 pri = db.getclass('priority')
121 pri.create(name="critical", order="1")
122 pri.create(name="urgent", order="2")
123 pri.create(name="bug", order="3")
124 pri.create(name="feature", order="4")
125 pri.create(name="wish", order="5")
127 stat = db.getclass('status')
128 stat.create(name="unread", order="1")
129 stat.create(name="deferred", order="2")
130 stat.create(name="chatting", order="3")
131 stat.create(name="need-eg", order="4")
132 stat.create(name="in-progress", order="5")
133 stat.create(name="testing", order="6")
134 stat.create(name="done-cbb", order="7")
135 stat.create(name="resolved", order="8")
137 user = db.getclass('user')
138 user.create(username="admin", password=adminpw,
139 address=instance_config.ADMIN_EMAIL)
140 db.commit()
142 #
143 # $Log: not supported by cvs2svn $
144 # Revision 1.16 2002/02/16 08:06:14 richard
145 # Removed the key property restriction on title of the classic issue class.
146 #
147 # Revision 1.15 2002/02/15 07:08:44 richard
148 # . Alternate email addresses are now available for users. See the MIGRATION
149 # file for info on how to activate the feature.
150 #
151 # Revision 1.14 2002/01/14 02:20:15 richard
152 # . changed all config accesses so they access either the instance or the
153 # config attriubute on the db. This means that all config is obtained from
154 # instance_config instead of the mish-mash of classes. This will make
155 # switching to a ConfigParser setup easier too, I hope.
156 #
157 # At a minimum, this makes migration a _little_ easier (a lot easier in the
158 # 0.5.0 switch, I hope!)
159 #
160 # Revision 1.13 2002/01/02 02:31:38 richard
161 # Sorry for the huge checkin message - I was only intending to implement #496356
162 # but I found a number of places where things had been broken by transactions:
163 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
164 # for _all_ roundup-generated smtp messages to be sent to.
165 # . the transaction cache had broken the roundupdb.Class set() reactors
166 # . newly-created author users in the mailgw weren't being committed to the db
167 #
168 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
169 # on when I found that stuff :):
170 # . #496356 ] Use threading in messages
171 # . detectors were being registered multiple times
172 # . added tests for mailgw
173 # . much better attaching of erroneous messages in the mail gateway
174 #
175 # Revision 1.12 2001/12/02 05:06:16 richard
176 # . We now use weakrefs in the Classes to keep the database reference, so
177 # the close() method on the database is no longer needed.
178 # I bumped the minimum python requirement up to 2.1 accordingly.
179 # . #487480 ] roundup-server
180 # . #487476 ] INSTALL.txt
181 #
182 # I also cleaned up the change message / post-edit stuff in the cgi client.
183 # There's now a clearly marked "TODO: append the change note" where I believe
184 # the change note should be added there. The "changes" list will obviously
185 # have to be modified to be a dict of the changes, or somesuch.
186 #
187 # More testing needed.
188 #
189 # Revision 1.11 2001/12/01 07:17:50 richard
190 # . We now have basic transaction support! Information is only written to
191 # the database when the commit() method is called. Only the anydbm
192 # backend is modified in this way - neither of the bsddb backends have been.
193 # The mail, admin and cgi interfaces all use commit (except the admin tool
194 # doesn't have a commit command, so interactive users can't commit...)
195 # . Fixed login/registration forwarding the user to the right page (or not,
196 # on a failure)
197 #
198 # Revision 1.10 2001/11/26 22:55:56 richard
199 # Feature:
200 # . Added INSTANCE_NAME to configuration - used in web and email to identify
201 # the instance.
202 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
203 # signature info in e-mails.
204 # . Some more flexibility in the mail gateway and more error handling.
205 # . Login now takes you to the page you back to the were denied access to.
206 #
207 # Fixed:
208 # . Lots of bugs, thanks Roché and others on the devel mailing list!
209 #
210 # Revision 1.9 2001/10/30 00:54:45 richard
211 # Features:
212 # . #467129 ] Lossage when username=e-mail-address
213 # . #473123 ] Change message generation for author
214 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
215 #
216 # Revision 1.8 2001/10/09 07:25:59 richard
217 # Added the Password property type. See "pydoc roundup.password" for
218 # implementation details. Have updated some of the documentation too.
219 #
220 # Revision 1.7 2001/08/07 00:24:43 richard
221 # stupid typo
222 #
223 # Revision 1.6 2001/08/07 00:15:51 richard
224 # Added the copyright/license notice to (nearly) all files at request of
225 # Bizar Software.
226 #
227 # Revision 1.5 2001/08/02 06:38:17 richard
228 # Roundupdb now appends "mailing list" information to its messages which
229 # include the e-mail address and web interface address. Templates may
230 # override this in their db classes to include specific information (support
231 # instructions, etc).
232 #
233 # Revision 1.4 2001/07/29 07:01:39 richard
234 # Added vim command to all source so that we don't get no steenkin' tabs :)
235 #
236 # Revision 1.3 2001/07/24 10:46:22 anthonybaxter
237 # Added templatebuilder module. two functions - one to pack up the html base,
238 # one to unpack it. Packed up the two standard templates into htmlbases.
239 # Modified __init__ to install them.
240 #
241 # __init__.py magic was needed for the rather high levels of wierd import magic.
242 # Reducing level of import magic == (good, future)
243 #
244 # Revision 1.2 2001/07/24 01:06:43 richard
245 # Oops - accidentally duped the keywords class
246 #
247 # Revision 1.1 2001/07/23 23:28:43 richard
248 # Adding the classic template
249 #
250 # Revision 1.4 2001/07/23 08:45:28 richard
251 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
252 # workable instance_home set up :)
253 # _and_ anydbm has had its first test :)
254 #
255 # Revision 1.3 2001/07/23 07:14:41 richard
256 # Moved the database backends off into backends.
257 #
258 # Revision 1.2 2001/07/23 06:25:50 richard
259 # relfected the move to roundup/backends
260 #
261 # Revision 1.1 2001/07/23 04:33:21 anthonybaxter
262 # split __init__.py into 2. dbinit and instance_config.
263 #
264 # Revision 1.1 2001/07/23 03:50:46 anthonybaxter
265 # moved templates to proper location
266 #
267 # Revision 1.2 2001/07/22 12:09:32 richard
268 # Final commit of Grande Splite
269 #
270 #
271 # vim: set filetype=python ts=4 sw=4 et si