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