Code

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