Mercurial > p > roundup > code
annotate roundup/instance.py @ 4943:7920d700e580 routing
Add support for extensions to provide custom pages to Roundup
and update CHANGES.txt
1. Added registerHandler() extension point to instance.Tracker
to register URL handlers for specific routes
2. Added processing of extension routes to client.cgi
3. Added example plugins/extensions/custompage.py
| author | anatoly techtonik <techtonik@gmail.com> |
|---|---|
| date | Tue, 25 Nov 2014 17:29:38 +0300 |
| parents | 6e9b9743de89 |
| children | 082ee3ded101 |
| 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 | 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 # |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 |
| 4388 | 19 """Top-level tracker interface. |
| 20 | |
| 21 Open a tracker with: | |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
22 |
| 4388 | 23 >>> from roundup import instance |
| 24 >>> db = instance.open('path to tracker home') | |
| 25 | |
| 26 The "db" handle you get back is the tracker's hyperdb which has the interface | |
| 4395 | 27 described in `roundup.hyperdb.Database`. |
| 4083 | 28 """ |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1953
diff
changeset
|
29 __docformat__ = 'restructuredtext' |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
31 import os |
|
3771
bf660e65ba45
Directory structure changes.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
2977
diff
changeset
|
32 import sys |
|
2977
9c8de04a76b1
unit test fixes
Richard Jones <richard@users.sourceforge.net>
parents:
2933
diff
changeset
|
33 from roundup import configuration, mailgw |
| 4083 | 34 from roundup import hyperdb, backends, actions |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
35 from roundup.cgi import client, templating |
| 4083 | 36 from roundup.cgi import actions as cgi_actions |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
37 |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
38 class Tracker: |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
39 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
|
40 """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
|
41 |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
42 Parameters: |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
43 tracker_home: |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
44 tracker home directory |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
45 optimize: |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
46 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
|
47 |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
48 """ |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
49 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
|
50 self.optimize = optimize |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4083
diff
changeset
|
51 # if set, call schema_hook after executing schema.py will get |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4083
diff
changeset
|
52 # same variables (in particular db) as schema.py main purpose is |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4083
diff
changeset
|
53 # for regression tests |
|
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4083
diff
changeset
|
54 self.schema_hook = None |
|
2647
8c46091c36d0
Main Roundup configuration class renamed to CoreConfig.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2638
diff
changeset
|
55 self.config = configuration.CoreConfig(tracker_home) |
|
4943
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
56 |
| 4083 | 57 self.actions = {} |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
58 self.cgi_actions = {} |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
59 self.templating_utils = {} |
|
4943
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
60 self.web_handlers = {} |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
61 |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
62 libdir = os.path.join(self.tracker_home, 'lib') |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
63 self.libdir = os.path.isdir(libdir) and libdir or '' |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
64 |
|
4592
7b7cfb4b00eb
Fix improvements on instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4588
diff
changeset
|
65 self.load_interfaces() |
|
4721
ec359e7c6c95
Rename templating.get_templates to get_loader
anatoly techtonik <techtonik@gmail.com>
parents:
4720
diff
changeset
|
66 self.templates = templating.get_loader(self.config["TEMPLATES"], |
|
4592
7b7cfb4b00eb
Fix improvements on instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4588
diff
changeset
|
67 self.config["TEMPLATE_ENGINE"]) |
|
7b7cfb4b00eb
Fix improvements on instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4588
diff
changeset
|
68 self.backend = backends.get_backend(self.get_backend_name()) |
|
7b7cfb4b00eb
Fix improvements on instance.py.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4588
diff
changeset
|
69 |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
70 if self.optimize: |
|
4748
e339583eae8e
templating: rename precompileTemplates to precompile
anatoly techtonik <techtonik@gmail.com>
parents:
4722
diff
changeset
|
71 self.templates.precompile() |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
72 # initialize tracker extensions |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
73 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
|
74 extension(self) |
|
2902
f50b867747c9
if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2891
diff
changeset
|
75 # load database schema |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
76 self.schema = self._compile('schema.py') |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
77 # load database detectors |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
78 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
|
79 # 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
|
80 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
|
81 |
|
2736
402d6d556558
postgres backend open doesn't hide corruption in schema [SF#956375]
Richard Jones <richard@users.sourceforge.net>
parents:
2701
diff
changeset
|
82 def get_backend_name(self): |
|
4508
996cc758f704
the "file" alias was introduced some time after this code was written
Richard Jones <richard@users.sourceforge.net>
parents:
4506
diff
changeset
|
83 f = file(os.path.join(self.config.DATABASE, 'backend_name')) |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
84 name = f.readline().strip() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
85 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
|
86 return name |
|
402d6d556558
postgres backend open doesn't hide corruption in schema [SF#956375]
Richard Jones <richard@users.sourceforge.net>
parents:
2701
diff
changeset
|
87 |
|
2796
7f1e17aeca1b
journaltag is optional
Richard Jones <richard@users.sourceforge.net>
parents:
2736
diff
changeset
|
88 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
|
89 # 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
|
90 # 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
|
91 # 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
|
92 # 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
|
93 backend = self.backend |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
94 env = { |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
95 'Class': backend.Class, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
96 'FileClass': backend.FileClass, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
97 'IssueClass': backend.IssueClass, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
98 'String': hyperdb.String, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
99 'Password': hyperdb.Password, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
100 'Date': hyperdb.Date, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
101 'Link': hyperdb.Link, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
102 'Multilink': hyperdb.Multilink, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
103 'Interval': hyperdb.Interval, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
104 'Boolean': hyperdb.Boolean, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
105 'Number': hyperdb.Number, |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
106 '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
|
107 } |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
108 |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
109 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
|
110 # execute preloaded schema object |
|
4606
48b73776601c
More fix for improvements on instance.py.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
4592
diff
changeset
|
111 self._exec(self.schema, env) |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4083
diff
changeset
|
112 if callable (self.schema_hook): |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
113 self.schema_hook(**env) |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
114 # use preloaded detectors |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
115 detectors = self.detectors |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
116 else: |
|
2902
f50b867747c9
if optimize is set, load the schema file in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2891
diff
changeset
|
117 # execute the schema file |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
118 self._execfile('schema.py', env) |
|
4211
61cf00ca920a
Process each message through the mail gateway as a separate transaction.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
4083
diff
changeset
|
119 if callable (self.schema_hook): |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
120 self.schema_hook(**env) |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
121 # 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
|
122 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
|
123 extension(self) |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
124 detectors = self.get_extensions('detectors') |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
125 db = env['db'] |
| 4781 | 126 db.tx_Source = None |
| 127 | |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
128 # apply the detectors |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
129 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
|
130 detector(db) |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
131 # 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
|
132 # 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
|
133 # 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
|
134 if not (self.optimize and self.db_open): |
|
4266
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
135 # As a consistency check, ensure that every link property is |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
136 # pointing at a defined class. Otherwise, the schema is |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
137 # internally inconsistent. This is an important safety |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
138 # measure as it protects against an accidental schema change |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
139 # dropping a table while there are still links to the table; |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
140 # once the table has been dropped, there is no way to get it |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
141 # back, so it is important to drop it only if we are as sure |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
142 # as possible that it is no longer needed. |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
143 classes = db.getclasses() |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
144 for classname in classes: |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
145 cl = db.getclass(classname) |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
146 for propname, prop in cl.getprops().iteritems(): |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
147 if not isinstance(prop, (hyperdb.Link, |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
148 hyperdb.Multilink)): |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
149 continue |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
150 linkto = prop.classname |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
151 if linkto not in classes: |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
152 raise ValueError, \ |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
153 ("property %s.%s links to non-existent class %s" |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
154 % (classname, propname, linkto)) |
|
2b75274936bc
Add schema consistency checks.
Stefan Seefeld <stefan@seefeld.name>
parents:
4211
diff
changeset
|
155 |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
156 db.post_init() |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
157 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
|
158 return db |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
159 |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
160 def load_interfaces(self): |
|
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
161 """load interfaces.py (if any), initialize Client and MailGW attrs""" |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
162 env = {} |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
163 if os.path.isfile(os.path.join(self.tracker_home, 'interfaces.py')): |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
164 self._execfile('interfaces.py', env) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
165 self.Client = env.get('Client', client.Client) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
166 self.MailGW = env.get('MailGW', mailgw.MailGW) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
167 self.TemplatingUtils = env.get('TemplatingUtils', templating.TemplatingUtils) |
|
2697
d138df58b0c3
load user interfaces
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2688
diff
changeset
|
168 |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
169 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
|
170 """Load python extensions |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
171 |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
172 Parameters: |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
173 dirname: |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
174 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
|
175 |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
176 Return value: |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
177 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
|
178 |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
179 """ |
|
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
180 extensions = [] |
|
2688
eb14c12813a0
fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2677
diff
changeset
|
181 dirpath = os.path.join(self.tracker_home, dirname) |
|
eb14c12813a0
fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2677
diff
changeset
|
182 if os.path.isdir(dirpath): |
|
3771
bf660e65ba45
Directory structure changes.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
2977
diff
changeset
|
183 sys.path.insert(1, dirpath) |
|
2688
eb14c12813a0
fix load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2677
diff
changeset
|
184 for name in os.listdir(dirpath): |
|
2677
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
185 if not name.endswith('.py'): |
|
1f0143b53bee
fix .load_extensions():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2647
diff
changeset
|
186 continue |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
187 env = {} |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
188 self._execfile(os.path.join(dirname, name), env) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
189 extensions.append(env['init']) |
|
3773
21ff756e4549
Fixes for directory handling.
Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
parents:
3771
diff
changeset
|
190 sys.path.remove(dirpath) |
|
2891
bc72b1c7319b
if optimize is set, load all extension modules in __init__()...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2890
diff
changeset
|
191 return extensions |
|
2638
18e86941c950
Load up extensions in the tracker "extensions" directory.
Richard Jones <richard@users.sourceforge.net>
parents:
2633
diff
changeset
|
192 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
193 def init(self, adminpw): |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
194 db = self.open('admin') |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
195 self._execfile('initial_data.py', {'db': db, 'adminpw': adminpw, |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
196 '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
|
197 db.commit() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
198 db.close() |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
199 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
200 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
|
201 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
|
202 |
|
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
203 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
|
204 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
|
205 |
|
4588
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
206 def _compile(self, fname): |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
207 fname = os.path.join(self.tracker_home, fname) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
208 return compile(file(fname).read(), fname, 'exec') |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
209 |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
210 def _exec(self, obj, env): |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
211 if self.libdir: |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
212 sys.path.insert(1, self.libdir) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
213 exec(obj, env) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
214 if self.libdir: |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
215 sys.path.remove(self.libdir) |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
216 return env |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
217 |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
218 def _execfile(self, fname, env): |
|
7017c8dd704c
Small improvements on instance.py by Cheer Xiao.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
4587
diff
changeset
|
219 self._exec(self._compile(fname), env) |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
220 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
221 def registerAction(self, name, action): |
| 4083 | 222 |
| 223 # The logic here is this: | |
| 224 # * if `action` derives from actions.Action, | |
| 225 # it is executable as a generic action. | |
| 226 # * if, moreover, it also derives from cgi.actions.Bridge, | |
| 227 # it may in addition be called via CGI | |
| 228 # * in all other cases we register it as a CGI action, without | |
| 229 # any check (for backward compatibility). | |
| 230 if issubclass(action, actions.Action): | |
| 231 self.actions[name] = action | |
| 232 if issubclass(action, cgi_actions.Bridge): | |
| 233 self.cgi_actions[name] = action | |
| 234 else: | |
| 235 self.cgi_actions[name] = action | |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
236 |
|
4943
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
237 def registerHandler(self, urlpath, function): |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
238 """Add handler for urlpath. `urlpath` is a simple rule for |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
239 roundup.web.router that is matched before Roundup makes DB |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
240 lookups for classes that are available to render. |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
241 |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
242 New in version 1.6.x""" |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
243 self.web_handlers[urlpath] = function |
|
7920d700e580
Add support for extensions to provide custom pages to Roundup
anatoly techtonik <techtonik@gmail.com>
parents:
4781
diff
changeset
|
244 |
|
2633
a9e1fff1e793
I thought I committed this last night. Ho hum.
Richard Jones <richard@users.sourceforge.net>
parents:
2621
diff
changeset
|
245 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
|
246 self.templating_utils[name] = function |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
247 |
|
1162
86d41c31f9be
old habits...
Richard Jones <richard@users.sourceforge.net>
parents:
1158
diff
changeset
|
248 class TrackerError(Exception): |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
249 pass |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
250 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
251 |
|
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
252 class OldStyleTrackers: |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
253 def __init__(self): |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
254 self.number = 0 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
255 self.trackers = {} |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
256 |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
257 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
|
258 """Open the tracker. |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
259 |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
260 Parameters: |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
261 tracker_home: |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
262 tracker home directory |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
263 optimize: |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
264 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
|
265 |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
266 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
|
267 |
|
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
268 """ |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
269 import imp |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
270 # sanity check existence of tracker home |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
271 if not os.path.exists(tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
272 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
|
273 |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
274 # 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
|
275 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
|
276 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
|
277 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
|
278 '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
|
279 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
280 if self.trackers.has_key(tracker_home): |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
281 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
|
282 tracker_home) |
|
2933
6574d6736b57
register all backend modules for old-style trackers
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2902
diff
changeset
|
283 # register all available backend modules |
|
6574d6736b57
register all backend modules for old-style trackers
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2902
diff
changeset
|
284 backends.list_backends() |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
285 self.number = self.number + 1 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
286 modname = '_roundup_tracker_%s'%self.number |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
287 self.trackers[tracker_home] = modname |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
288 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
289 # load the tracker |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
290 tracker = imp.load_package(modname, tracker_home) |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
291 |
|
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
292 # ensure the tracker has all the required bits |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
293 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
|
294 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
|
295 raise TrackerError, \ |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1162
diff
changeset
|
296 'Required tracker attribute "%s" missing'%required |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
297 |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
298 # load and apply the config |
|
2647
8c46091c36d0
Main Roundup configuration class renamed to CoreConfig.
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2638
diff
changeset
|
299 tracker.config = configuration.CoreConfig(tracker_home) |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
300 tracker.dbinit.config = tracker.config |
|
2397
fa50e1347397
added basic logging support
Richard Jones <richard@users.sourceforge.net>
parents:
2273
diff
changeset
|
301 |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
302 tracker.optimize = optimize |
|
4722
f7e68ae4926c
Restore compatibility with an old style trackers (not sure if
anatoly techtonik <techtonik@gmail.com>
parents:
4721
diff
changeset
|
303 tracker.templates = templating.get_loader(tracker.config["TEMPLATES"]) |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
304 if optimize: |
|
4748
e339583eae8e
templating: rename precompileTemplates to precompile
anatoly techtonik <techtonik@gmail.com>
parents:
4722
diff
changeset
|
305 tracker.templates.precompile() |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
306 |
|
1158
30db4a11d700
sanity check instance attributes on open
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
307 return tracker |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
308 |
|
1780
d2801a2b0a77
Initial implementation (half-baked) at new Tracker instance.
Richard Jones <richard@users.sourceforge.net>
parents:
1174
diff
changeset
|
309 OldStyleTrackers = OldStyleTrackers() |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
310 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
|
311 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
|
312 # user should upgrade... |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
313 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
|
314 |
|
2851
96626831def1
trackers got a 'templates' attribute, containing html templates collection...
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2836
diff
changeset
|
315 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
|
316 |
|
2621
d344419d599d
use new style config;
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2584
diff
changeset
|
317 # vim: set filetype=python sts=4 sw=4 et si : |
