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.20 2002-02-15 07:08:44 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 # Now initialise the schema. Must do this each time.
51 pri = Class(db, "priority",
52 name=String(), order=String())
53 pri.setkey("name")
55 stat = Class(db, "status",
56 name=String(), order=String())
57 stat.setkey("name")
59 keywords = Class(db, "keyword",
60 name=String())
61 keywords.setkey("name")
63 user = Class(db, "user",
64 username=String(), password=Password(),
65 address=String(), realname=String(),
66 phone=String(), organisation=String(),
67 alternate_addresses=String())
68 user.setkey("username")
70 msg = FileClass(db, "msg",
71 author=Link("user"), recipients=Multilink("user"),
72 date=Date(), summary=String(),
73 files=Multilink("file"),
74 messageid=String(), inreplyto=String())
76 file = FileClass(db, "file",
77 name=String(), type=String())
79 # bugs and support calls etc
80 rate = Class(db, "rate",
81 name=String(), order=String())
82 rate.setkey("name")
84 source = Class(db, "source",
85 name=String(), order=String())
86 source.setkey("name")
88 platform = Class(db, "platform",
89 name=String(), order=String())
90 platform.setkey("name")
92 product = Class(db, "product",
93 name=String(), order=String())
94 product.setkey("name")
96 timelog = Class(db, "timelog",
97 date=Date(), time=String(),
98 performedby=Link("user"), description=String())
100 support = IssueClass(db, "support",
101 assignedto=Link("user"), status=Link("status"),
102 rate=Link("rate"), source=Link("source"),
103 product=Link("product"), platform=Multilink("platform"),
104 version=String(), timelog=Multilink("timelog"),
105 customername=String())
107 issue = IssueClass(db, "issue",
108 assignedto=Link("user"), priority=Link("priority"),
109 status=Link("status"), product=Link("product"),
110 platform=Multilink("platform"), version=String(),
111 targetversion=String(), supportcall=Multilink("support"))
113 import detectors
114 detectors.init(db)
116 return db
118 def init(adminpw):
119 ''' as from the roundupdb method initDB
121 Open the new database, and set up a bunch of attributes.
123 '''
124 dbdir = os.path.join(instance_config.DATABASE, 'files')
125 if not os.path.isdir(dbdir):
126 os.makedirs(dbdir)
128 db = open("admin")
129 db.clear()
131 pri = db.getclass('priority')
132 pri.create(name="fatal-bug", order="1")
133 pri.create(name="bug", order="2")
134 pri.create(name="usability", order="3")
135 pri.create(name="feature", order="4")
137 stat = db.getclass('status')
138 stat.create(name="unread", order="1")
139 stat.create(name="deferred", order="2")
140 stat.create(name="chatting", order="3")
141 stat.create(name="need-eg", order="4")
142 stat.create(name="in-progress", order="5")
143 stat.create(name="testing", order="6")
144 stat.create(name="done-cbb", order="7")
145 stat.create(name="resolved", order="8")
147 rate = db.getclass("rate")
148 rate.create(name='basic', order="1")
149 rate.create(name='premium', order="2")
150 rate.create(name='internal', order="3")
152 source = db.getclass("source")
153 source.create(name='phone', order="1")
154 source.create(name='e-mail', order="2")
155 source.create(name='internal', order="3")
156 source.create(name='internal-qa', order="4")
158 platform = db.getclass("platform")
159 platform.create(name='linux', order="1")
160 platform.create(name='windows', order="2")
161 platform.create(name='mac', order="3")
163 product = db.getclass("product")
164 product.create(name='Bizar Shop', order="1")
165 product.create(name='Bizar Shop Developer', order="2")
166 product.create(name='Bizar Shop Manual', order="3")
167 product.create(name='Bizar Shop Developer Manual', order="4")
169 user = db.getclass('user')
170 user.create(username="admin", password=adminpw,
171 address=instance_config.ADMIN_EMAIL)
173 db.commit()
175 #
176 # $Log: not supported by cvs2svn $
177 # Revision 1.19 2002/01/14 02:20:15 richard
178 # . changed all config accesses so they access either the instance or the
179 # config attriubute on the db. This means that all config is obtained from
180 # instance_config instead of the mish-mash of classes. This will make
181 # switching to a ConfigParser setup easier too, I hope.
182 #
183 # At a minimum, this makes migration a _little_ easier (a lot easier in the
184 # 0.5.0 switch, I hope!)
185 #
186 # Revision 1.18 2002/01/02 02:31:38 richard
187 # Sorry for the huge checkin message - I was only intending to implement #496356
188 # but I found a number of places where things had been broken by transactions:
189 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
190 # for _all_ roundup-generated smtp messages to be sent to.
191 # . the transaction cache had broken the roundupdb.Class set() reactors
192 # . newly-created author users in the mailgw weren't being committed to the db
193 #
194 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
195 # on when I found that stuff :):
196 # . #496356 ] Use threading in messages
197 # . detectors were being registered multiple times
198 # . added tests for mailgw
199 # . much better attaching of erroneous messages in the mail gateway
200 #
201 # Revision 1.17 2001/12/02 05:06:16 richard
202 # . We now use weakrefs in the Classes to keep the database reference, so
203 # the close() method on the database is no longer needed.
204 # I bumped the minimum python requirement up to 2.1 accordingly.
205 # . #487480 ] roundup-server
206 # . #487476 ] INSTALL.txt
207 #
208 # I also cleaned up the change message / post-edit stuff in the cgi client.
209 # There's now a clearly marked "TODO: append the change note" where I believe
210 # the change note should be added there. The "changes" list will obviously
211 # have to be modified to be a dict of the changes, or somesuch.
212 #
213 # More testing needed.
214 #
215 # Revision 1.16 2001/12/01 07:17:50 richard
216 # . We now have basic transaction support! Information is only written to
217 # the database when the commit() method is called. Only the anydbm
218 # backend is modified in this way - neither of the bsddb backends have been.
219 # The mail, admin and cgi interfaces all use commit (except the admin tool
220 # doesn't have a commit command, so interactive users can't commit...)
221 # . Fixed login/registration forwarding the user to the right page (or not,
222 # on a failure)
223 #
224 # Revision 1.15 2001/11/26 22:55:56 richard
225 # Feature:
226 # . Added INSTANCE_NAME to configuration - used in web and email to identify
227 # the instance.
228 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
229 # signature info in e-mails.
230 # . Some more flexibility in the mail gateway and more error handling.
231 # . Login now takes you to the page you back to the were denied access to.
232 #
233 # Fixed:
234 # . Lots of bugs, thanks Roché and others on the devel mailing list!
235 #
236 # Revision 1.14 2001/11/21 02:34:18 richard
237 # Added a target version field to the extended issue schema
238 #
239 # Revision 1.13 2001/10/30 00:54:45 richard
240 # Features:
241 # . #467129 ] Lossage when username=e-mail-address
242 # . #473123 ] Change message generation for author
243 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
244 #
245 # Revision 1.12 2001/10/09 07:25:59 richard
246 # Added the Password property type. See "pydoc roundup.password" for
247 # implementation details. Have updated some of the documentation too.
248 #
249 # Revision 1.11 2001/08/07 00:24:43 richard
250 # stupid typo
251 #
252 # Revision 1.10 2001/08/07 00:15:51 richard
253 # Added the copyright/license notice to (nearly) all files at request of
254 # Bizar Software.
255 #
256 # Revision 1.9 2001/08/02 06:38:17 richard
257 # Roundupdb now appends "mailing list" information to its messages which
258 # include the e-mail address and web interface address. Templates may
259 # override this in their db classes to include specific information (support
260 # instructions, etc).
261 #
262 # Revision 1.8 2001/07/30 01:26:59 richard
263 # Big changes:
264 # . split off the support priority into its own class
265 # . added "new support, new user" to the page head
266 # . fixed the display options for the heading links
267 #
268 # Revision 1.7 2001/07/29 07:01:39 richard
269 # Added vim command to all source so that we don't get no steenkin' tabs :)
270 #
271 # Revision 1.6 2001/07/25 01:23:07 richard
272 # Added the Roundup spec to the new documentation directory.
273 #
274 # Revision 1.5 2001/07/23 23:20:35 richard
275 # forgot to remove the interfaces from the dbinit module ;)
276 #
277 # Revision 1.4 2001/07/23 08:45:28 richard
278 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
279 # workable instance_home set up :)
280 # _and_ anydbm has had its first test :)
281 #
282 # Revision 1.3 2001/07/23 07:14:41 richard
283 # Moved the database backends off into backends.
284 #
285 # Revision 1.2 2001/07/23 06:25:50 richard
286 # relfected the move to roundup/backends
287 #
288 # Revision 1.1 2001/07/23 04:33:21 anthonybaxter
289 # split __init__.py into 2. dbinit and instance_config.
290 #
291 # Revision 1.1 2001/07/23 03:50:46 anthonybaxter
292 # moved templates to proper location
293 #
294 # Revision 1.2 2001/07/22 12:09:32 richard
295 # Final commit of Grande Splite
296 #
297 #
298 # vim: set filetype=python ts=4 sw=4 et si