Code

Sorry for the huge checkin message - I was only intending to implement #496356
[roundup.git] / roundup / templates / extended / dbinit.py
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.18 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
46  
47 def open(name=None):
48     ''' as from the roundupdb method openDB 
49  
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     keywords = Class(db, "keyword", 
66                     name=String())
67     keywords.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     # bugs and support calls etc
85     rate = Class(db, "rate", 
86                     name=String(),       order=String())
87     rate.setkey("name")
89     source = Class(db, "source", 
90                     name=String(),       order=String())
91     source.setkey("name")
93     platform = Class(db, "platform", 
94                     name=String(),       order=String())
95     platform.setkey("name")
97     product = Class(db, "product", 
98                     name=String(),       order=String())
99     product.setkey("name")
101     timelog = Class(db, "timelog", 
102                     date=Date(),         time=String(),
103                     performedby=Link("user"), description=String())
105     support = IssueClass(db, "support", 
106                     assignedto=Link("user"), status=Link("status"),
107                     rate=Link("rate"), source=Link("source"),
108                     product=Link("product"), platform=Multilink("platform"),
109                     version=String(), timelog=Multilink("timelog"),
110                     customername=String())
112     issue = IssueClass(db, "issue", 
113                     assignedto=Link("user"), priority=Link("priority"), 
114                     status=Link("status"), product=Link("product"), 
115                     platform=Multilink("platform"), version=String(),
116                     targetversion=String(), supportcall=Multilink("support"))
118     import detectors
119     detectors.init(db)
121     return db
122  
123 def init(adminpw): 
124     ''' as from the roundupdb method initDB 
125  
126     Open the new database, and set up a bunch of attributes.
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()
181 # $Log: not supported by cvs2svn $
182 # Revision 1.17  2001/12/02 05:06:16  richard
183 # . We now use weakrefs in the Classes to keep the database reference, so
184 #   the close() method on the database is no longer needed.
185 #   I bumped the minimum python requirement up to 2.1 accordingly.
186 # . #487480 ] roundup-server
187 # . #487476 ] INSTALL.txt
189 # I also cleaned up the change message / post-edit stuff in the cgi client.
190 # There's now a clearly marked "TODO: append the change note" where I believe
191 # the change note should be added there. The "changes" list will obviously
192 # have to be modified to be a dict of the changes, or somesuch.
194 # More testing needed.
196 # Revision 1.16  2001/12/01 07:17:50  richard
197 # . We now have basic transaction support! Information is only written to
198 #   the database when the commit() method is called. Only the anydbm
199 #   backend is modified in this way - neither of the bsddb backends have been.
200 #   The mail, admin and cgi interfaces all use commit (except the admin tool
201 #   doesn't have a commit command, so interactive users can't commit...)
202 # . Fixed login/registration forwarding the user to the right page (or not,
203 #   on a failure)
205 # Revision 1.15  2001/11/26 22:55:56  richard
206 # Feature:
207 #  . Added INSTANCE_NAME to configuration - used in web and email to identify
208 #    the instance.
209 #  . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
210 #    signature info in e-mails.
211 #  . Some more flexibility in the mail gateway and more error handling.
212 #  . Login now takes you to the page you back to the were denied access to.
214 # Fixed:
215 #  . Lots of bugs, thanks Roché and others on the devel mailing list!
217 # Revision 1.14  2001/11/21 02:34:18  richard
218 # Added a target version field to the extended issue schema
220 # Revision 1.13  2001/10/30 00:54:45  richard
221 # Features:
222 #  . #467129 ] Lossage when username=e-mail-address
223 #  . #473123 ] Change message generation for author
224 #  . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
226 # Revision 1.12  2001/10/09 07:25:59  richard
227 # Added the Password property type. See "pydoc roundup.password" for
228 # implementation details. Have updated some of the documentation too.
230 # Revision 1.11  2001/08/07 00:24:43  richard
231 # stupid typo
233 # Revision 1.10  2001/08/07 00:15:51  richard
234 # Added the copyright/license notice to (nearly) all files at request of
235 # Bizar Software.
237 # Revision 1.9  2001/08/02 06:38:17  richard
238 # Roundupdb now appends "mailing list" information to its messages which
239 # include the e-mail address and web interface address. Templates may
240 # override this in their db classes to include specific information (support
241 # instructions, etc).
243 # Revision 1.8  2001/07/30 01:26:59  richard
244 # Big changes:
245 #  . split off the support priority into its own class
246 #  . added "new support, new user" to the page head
247 #  . fixed the display options for the heading links
249 # Revision 1.7  2001/07/29 07:01:39  richard
250 # Added vim command to all source so that we don't get no steenkin' tabs :)
252 # Revision 1.6  2001/07/25 01:23:07  richard
253 # Added the Roundup spec to the new documentation directory.
255 # Revision 1.5  2001/07/23 23:20:35  richard
256 # forgot to remove the interfaces from the dbinit module ;)
258 # Revision 1.4  2001/07/23 08:45:28  richard
259 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
260 # workable instance_home set up :)
261 # _and_ anydbm has had its first test :)
263 # Revision 1.3  2001/07/23 07:14:41  richard
264 # Moved the database backends off into backends.
266 # Revision 1.2  2001/07/23 06:25:50  richard
267 # relfected the move to roundup/backends
269 # Revision 1.1  2001/07/23 04:33:21  anthonybaxter
270 # split __init__.py into 2. dbinit and instance_config.
272 # Revision 1.1  2001/07/23 03:50:46  anthonybaxter
273 # moved templates to proper location
275 # Revision 1.2  2001/07/22 12:09:32  richard
276 # Final commit of Grande Splite
279 # vim: set filetype=python ts=4 sw=4 et si