annotate roundup/instance.py @ 3237:ed97e2a85576 maint-0.8

clearer docs for find(); couple of other post-release fixes
author Richard Jones <richard@users.sourceforge.net>
date Thu, 03 Mar 2005 22:12:36 +0000
parents 9c8de04a76b1
children bf660e65ba45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
213
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
1 #
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
3 # This module is free software, and you may redistribute it and/or modify
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
4 # under the same terms as Python, so long as this copyright message and
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
5 # disclaimer are retained in their original form.
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
6 #
214
18134bffab37 stupid typo
Richard Jones <richard@users.sourceforge.net>
parents: 213
diff changeset
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
213
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
10 # POSSIBILITY OF SUCH DAMAGE.
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
11 #
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
d45384bc6420 Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents: 204
diff changeset
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2621
d344419d599d use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2584
diff changeset
17 #
2977
9c8de04a76b1 unit test fixes
Richard Jones <richard@users.sourceforge.net>
parents: 2933
diff changeset
18 # $Id: instance.py,v 1.33 2004-11-29 02:55:46 richard Exp $
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
19
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1953
diff changeset
20 '''Tracker handling (open tracker).
406
bdc2ea127ae9 Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents: 380
diff changeset
21
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
22 Backwards compatibility for the old-style "imported" trackers.
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23 '''
2005
fc52d57c6c3e documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents: 1953
diff changeset
24 __docformat__ = 'restructuredtext'
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
26 import os
2977
9c8de04a76b1 unit test fixes
Richard Jones <richard@users.sourceforge.net>
parents: 2933
diff changeset
27 from roundup import configuration, mailgw
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
28 from roundup import hyperdb, backends
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
29 from roundup.cgi import client, templating
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
30
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
31 class Vars:
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
32 def __init__(self, vars):
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
33 self.__dict__.update(vars)
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
34
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
35 class Tracker:
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
36 def __init__(self, tracker_home, optimize=0):
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
37 """New-style tracker instance constructor
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
38
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
39 Parameters:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
40 tracker_home:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
41 tracker home directory
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
42 optimize:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
43 if set, precompile html templates
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
44
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
45 """
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
46 self.tracker_home = tracker_home
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
47 self.optimize = optimize
2647
8c46091c36d0 Main Roundup configuration class renamed to CoreConfig.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2638
diff changeset
48 self.config = configuration.CoreConfig(tracker_home)
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
49 self.cgi_actions = {}
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
50 self.templating_utils = {}
2836
473d2323bc9d load interfaces in __init__():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2796
diff changeset
51 self.load_interfaces()
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
52 self.templates = templating.Templates(self.config["TEMPLATES"])
2890
938915fbcb49 get_backend_name() is a lengthy thing (file I/O).
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2856
diff changeset
53 self.backend = backends.get_backend(self.get_backend_name())
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
54 if self.optimize:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
55 self.templates.precompileTemplates()
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
56 # initialize tracker extensions
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
57 for extension in self.get_extensions('extensions'):
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
58 extension(self)
2902
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
59 # load database schema
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
60 schemafilename = os.path.join(self.tracker_home, 'schema.py')
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
61 # Note: can't use built-in open()
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
62 # because of the global function with the same name
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
63 schemafile = file(schemafilename, 'rt')
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
64 self.schema = compile(schemafile.read(), schemafilename, 'exec')
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
65 schemafile.close()
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
66 # load database detectors
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
67 self.detectors = self.get_extensions('detectors')
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
68 # db_open is set to True after first open()
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
69 self.db_open = 0
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
70
2736
402d6d556558 postgres backend open doesn't hide corruption in schema [SF#956375]
Richard Jones <richard@users.sourceforge.net>
parents: 2701
diff changeset
71 def get_backend_name(self):
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
72 o = __builtins__['open']
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
73 f = o(os.path.join(self.tracker_home, 'db', 'backend_name'))
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
74 name = f.readline().strip()
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
75 f.close()
2736
402d6d556558 postgres backend open doesn't hide corruption in schema [SF#956375]
Richard Jones <richard@users.sourceforge.net>
parents: 2701
diff changeset
76 return name
402d6d556558 postgres backend open doesn't hide corruption in schema [SF#956375]
Richard Jones <richard@users.sourceforge.net>
parents: 2701
diff changeset
77
2796
7f1e17aeca1b journaltag is optional
Richard Jones <richard@users.sourceforge.net>
parents: 2736
diff changeset
78 def open(self, name=None):
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
79 # load the database schema
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
80 # we cannot skip this part even if self.optimize is set
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
81 # because the schema has security settings that must be
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
82 # applied to each database instance
2890
938915fbcb49 get_backend_name() is a lengthy thing (file I/O).
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2856
diff changeset
83 backend = self.backend
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
84 vars = {
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
85 'Class': backend.Class,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
86 'FileClass': backend.FileClass,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
87 'IssueClass': backend.IssueClass,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
88 'String': hyperdb.String,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
89 'Password': hyperdb.Password,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
90 'Date': hyperdb.Date,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
91 'Link': hyperdb.Link,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
92 'Multilink': hyperdb.Multilink,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
93 'Interval': hyperdb.Interval,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
94 'Boolean': hyperdb.Boolean,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
95 'Number': hyperdb.Number,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
96 'db': backend.Database(self.config, name)
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
97 }
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
98
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
99 if self.optimize:
2902
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
100 # execute preloaded schema object
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
101 exec(self.schema, vars)
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
102 # use preloaded detectors
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
103 detectors = self.detectors
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
104 else:
2902
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
105 # execute the schema file
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
106 self._load_python('schema.py', vars)
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
107 # reload extensions and detectors
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
108 for extension in self.get_extensions('extensions'):
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
109 extension(self)
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
110 detectors = self.get_extensions('detectors')
2902
f50b867747c9 if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2891
diff changeset
111 db = vars['db']
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
112 # apply the detectors
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
113 for detector in detectors:
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
114 detector(db)
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
115 # if we are running in debug mode
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
116 # or this is the first time the database is opened,
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
117 # do database upgrade checks
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
118 if not (self.optimize and self.db_open):
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
119 db.post_init()
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
120 self.db_open = 1
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
121 return db
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
122
2697
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
123 def load_interfaces(self):
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
124 """load interfaces.py (if any), initialize Client and MailGW attrs"""
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
125 vars = {}
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
126 if os.path.isfile(os.path.join(self.tracker_home, 'interfaces.py')):
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
127 self._load_python('interfaces.py', vars)
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
128 self.Client = vars.get('Client', client.Client)
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
129 self.MailGW = vars.get('MailGW', mailgw.MailGW)
d138df58b0c3 load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2688
diff changeset
130
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
131 def get_extensions(self, dirname):
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
132 """Load python extensions
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
133
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
134 Parameters:
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
135 dirname:
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
136 extension directory name relative to tracker home
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
137
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
138 Return value:
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
139 list of init() functions for each extension
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
140
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
141 """
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
142 extensions = []
2688
eb14c12813a0 fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2677
diff changeset
143 dirpath = os.path.join(self.tracker_home, dirname)
eb14c12813a0 fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2677
diff changeset
144 if os.path.isdir(dirpath):
eb14c12813a0 fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2677
diff changeset
145 for name in os.listdir(dirpath):
2677
1f0143b53bee fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2647
diff changeset
146 if not name.endswith('.py'):
1f0143b53bee fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2647
diff changeset
147 continue
1f0143b53bee fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2647
diff changeset
148 vars = {}
1f0143b53bee fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2647
diff changeset
149 self._load_python(os.path.join(dirname, name), vars)
2891
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
150 extensions.append(vars['init'])
bc72b1c7319b if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2890
diff changeset
151 return extensions
2638
18e86941c950 Load up extensions in the tracker "extensions" directory.
Richard Jones <richard@users.sourceforge.net>
parents: 2633
diff changeset
152
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
153 def init(self, adminpw):
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
154 db = self.open('admin')
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
155 self._load_python('initial_data.py', {'db': db, 'adminpw': adminpw,
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
156 'admin_email': self.config['ADMIN_EMAIL']})
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
157 db.commit()
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
158 db.close()
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
159
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
160 def exists(self):
2890
938915fbcb49 get_backend_name() is a lengthy thing (file I/O).
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2856
diff changeset
161 return self.backend.db_exists(self.config)
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
162
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
163 def nuke(self):
2890
938915fbcb49 get_backend_name() is a lengthy thing (file I/O).
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2856
diff changeset
164 self.backend.db_nuke(self.config)
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
165
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
166 def _load_python(self, file, vars):
2273
c77483d2cda4 merge from maint-0-7
Richard Jones <richard@users.sourceforge.net>
parents: 2005
diff changeset
167 file = os.path.join(self.tracker_home, file)
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
168 execfile(file, vars)
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
169 return vars
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
170
2633
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
171 def registerAction(self, name, action):
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
172 self.cgi_actions[name] = action
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
173
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
174 def registerUtil(self, name, function):
a9e1fff1e793 I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents: 2621
diff changeset
175 self.templating_utils[name] = function
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
176
1162
86d41c31f9be old habits...
Richard Jones <richard@users.sourceforge.net>
parents: 1158
diff changeset
177 class TrackerError(Exception):
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
178 pass
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
179
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
180
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
181 class OldStyleTrackers:
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
182 def __init__(self):
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
183 self.number = 0
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
184 self.trackers = {}
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
185
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
186 def open(self, tracker_home, optimize=0):
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
187 """Open the tracker.
380
a1331423eb93 Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents: 214
diff changeset
188
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
189 Parameters:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
190 tracker_home:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
191 tracker home directory
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
192 optimize:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
193 if set, precompile html templates
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
194
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
195 Raise ValueError if the tracker home doesn't exist.
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
196
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
197 """
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
198 import imp
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
199 # sanity check existence of tracker home
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
200 if not os.path.exists(tracker_home):
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
201 raise ValueError, 'no such directory: "%s"'%tracker_home
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
202
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
203 # sanity check tracker home contents
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
204 for reqd in 'config dbinit select_db interfaces'.split():
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
205 if not os.path.exists(os.path.join(tracker_home, '%s.py'%reqd)):
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
206 raise TrackerError, 'File "%s.py" missing from tracker '\
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
207 'home "%s"'%(reqd, tracker_home)
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
208
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
209 if self.trackers.has_key(tracker_home):
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
210 return imp.load_package(self.trackers[tracker_home],
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
211 tracker_home)
2933
6574d6736b57 register all backend modules for old-style trackers
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2902
diff changeset
212 # register all available backend modules
6574d6736b57 register all backend modules for old-style trackers
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2902
diff changeset
213 backends.list_backends()
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
214 self.number = self.number + 1
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
215 modname = '_roundup_tracker_%s'%self.number
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
216 self.trackers[tracker_home] = modname
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
217
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
218 # load the tracker
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
219 tracker = imp.load_package(modname, tracker_home)
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
220
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
221 # ensure the tracker has all the required bits
2621
d344419d599d use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2584
diff changeset
222 for required in 'open init Client MailGW'.split():
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
223 if not hasattr(tracker, required):
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
224 raise TrackerError, \
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1162
diff changeset
225 'Required tracker attribute "%s" missing'%required
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
226
2621
d344419d599d use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2584
diff changeset
227 # load and apply the config
2647
8c46091c36d0 Main Roundup configuration class renamed to CoreConfig.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2638
diff changeset
228 tracker.config = configuration.CoreConfig(tracker_home)
2621
d344419d599d use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2584
diff changeset
229 tracker.dbinit.config = tracker.config
2397
fa50e1347397 added basic logging support
Richard Jones <richard@users.sourceforge.net>
parents: 2273
diff changeset
230
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
231 tracker.optimize = optimize
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
232 tracker.templates = templating.Templates(tracker.config["TEMPLATES"])
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
233 if optimize:
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
234 tracker.templates.precompileTemplates()
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
235
1158
30db4a11d700 sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents: 1090
diff changeset
236 return tracker
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
237
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
238 OldStyleTrackers = OldStyleTrackers()
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
239 def open(tracker_home, optimize=0):
1780
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
240 if os.path.exists(os.path.join(tracker_home, 'dbinit.py')):
d2801a2b0a77 Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
241 # user should upgrade...
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
242 return OldStyleTrackers.open(tracker_home, optimize=optimize)
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
243
2851
96626831def1 trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2836
diff changeset
244 return Tracker(tracker_home, optimize=optimize)
204
c1461733cbf9 Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
245
2621
d344419d599d use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2584
diff changeset
246 # vim: set filetype=python sts=4 sw=4 et si :

Roundup Issue Tracker: http://roundup-tracker.org/