Code

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