Code

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