|
8 | 8 | from roundup.cgi.exceptions import * |
9 | 9 | from roundup.exceptions import UsageError |
10 | 10 | from roundup.date import Date, Range, Interval |
| 11 | +from roundup import actions |
11 | 12 | from SimpleXMLRPCServer import * |
12 | 13 |
|
13 | 14 | def translate(value): |
@@ -52,10 +53,10 @@ class RoundupInstance: |
52 | 53 | """The RoundupInstance provides the interface accessible through |
53 | 54 | the Python XMLRPC mapping.""" |
54 | 55 |
|
55 | | - def __init__(self, db, translator): |
| 56 | + def __init__(self, db, actions, translator): |
56 | 57 |
|
57 | 58 | self.db = db |
58 | | - self.userid = db.getuid() |
| 59 | + self.actions = actions |
59 | 60 | self.translator = translator |
60 | 61 |
|
61 | 62 | def list(self, classname, propname=None): |
@@ -125,15 +126,30 @@ def set(self, designator, *args): |
125 | 126 | raise UsageError, message |
126 | 127 |
|
127 | 128 |
|
| 129 | + builtin_actions = {'retire': actions.Retire} |
| 130 | + |
| 131 | + def action(self, name, *args): |
| 132 | + """""" |
| 133 | + |
| 134 | + if name in self.actions: |
| 135 | + action_type = self.actions[name] |
| 136 | + elif name in self.builtin_actions: |
| 137 | + action_type = self.builtin_actions[name] |
| 138 | + else: |
| 139 | + raise Exception('action "%s" is not supported %s' % (name, ','.join(self.actions.keys()))) |
| 140 | + action = action_type(self.db, self.translator) |
| 141 | + return action.execute(*args) |
| 142 | + |
| 143 | + |
128 | 144 | class RoundupDispatcher(SimpleXMLRPCDispatcher): |
129 | 145 | """RoundupDispatcher bridges from cgi.client to RoundupInstance. |
130 | 146 | It expects user authentication to be done.""" |
131 | 147 |
|
132 | | - def __init__(self, db, userid, translator, |
| 148 | + def __init__(self, db, actions, translator, |
133 | 149 | allow_none=False, encoding=None): |
134 | 150 |
|
135 | 151 | SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding) |
136 | | - self.register_instance(RoundupInstance(db, userid, translator)) |
| 152 | + self.register_instance(RoundupInstance(db, actions, translator)) |
137 | 153 |
|
138 | 154 |
|
139 | 155 | def dispatch(self, input): |
|
0 commit comments