Mercurial > p > roundup > code
annotate roundup/instance.py @ 604:13719594278b config-0-4-0-branch
I've re-worked the config structure a little so it's simpler
(one less file) and added a unit test so we can be sure it's working.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 06 Feb 2002 07:11:13 +0000 |
| parents | bdc2ea127ae9 |
| children |
| 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. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
17 # |
|
604
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
18 # $Id: instance.py,v 1.5.2.1 2002-02-06 07:11:12 richard Exp $ |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
20 __doc__ = ''' |
|
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
21 Instance handling (open instance). |
|
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
22 |
|
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
23 Currently this module provides one function: open. This function opens |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 an instance. |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 ''' |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
27 import imp, os |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 class Opener: |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 def __init__(self): |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 self.number = 0 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 self.instances = {} |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 def open(self, instance_home): |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
35 '''Open the instance. |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
36 |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
37 Raise ValueError if the instance home doesn't exist. |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
38 ''' |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
39 if not os.path.exists(instance_home): |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
40 raise ValueError, 'no such directory: "%s"'%instance_home |
|
604
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
41 |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 if self.instances.has_key(instance_home): |
|
604
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
43 # already loaded |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
44 instance = imp.load_package(self.instances[instance_home], |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 instance_home) |
|
604
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
46 return instance |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
47 |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
48 # not loaded - make a module name for the instance |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 self.number = self.number + 1 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 modname = '_roundup_instance_%s'%self.number |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 self.instances[instance_home] = modname |
|
604
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
52 |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
53 # import the instance |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
54 instance = imp.load_package(modname, instance_home) |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
55 |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
56 # load the config |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
57 instance.instance_config = config.loadInstanceConfig(instance_home) |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
58 |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
59 # all done |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
60 return instance |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 opener = Opener() |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 open = opener.open |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
64 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 del Opener |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
66 del opener |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
67 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
68 |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 # |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 # $Log: not supported by cvs2svn $ |
|
604
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
71 # Revision 1.5 2001/11/22 15:46:42 jhermann |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
72 # Added module docstrings to all modules. |
|
13719594278b
I've re-worked the config structure a little so it's simpler
Richard Jones <richard@users.sourceforge.net>
parents:
406
diff
changeset
|
73 # |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
74 # Revision 1.4 2001/11/12 22:01:06 richard |
|
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
75 # Fixed issues with nosy reaction and author copies. |
|
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
380
diff
changeset
|
76 # |
|
380
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
77 # Revision 1.3 2001/08/07 00:24:42 richard |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
78 # stupid typo |
|
a1331423eb93
Fixed issues with nosy reaction and author copies.
Richard Jones <richard@users.sourceforge.net>
parents:
214
diff
changeset
|
79 # |
| 214 | 80 # Revision 1.2 2001/08/07 00:15:51 richard |
| 81 # Added the copyright/license notice to (nearly) all files at request of | |
| 82 # Bizar Software. | |
| 83 # | |
|
213
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
84 # Revision 1.1 2001/08/05 07:43:52 richard |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
85 # Instances are now opened by a special function that generates a unique |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
86 # module name for the instances on import time. |
|
d45384bc6420
Added the copyright/license notice to (nearly) all files...
Richard Jones <richard@users.sourceforge.net>
parents:
204
diff
changeset
|
87 # |
|
204
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
88 # |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
89 # |
|
c1461733cbf9
Instances are now opened by a special function...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
90 # vim: set filetype=python ts=4 sw=4 et si |
