| | 198 | |
|---|
| | 199 | |
|---|
| | 200 | class TicketWorkflowOpRunExternal(Component): |
|---|
| | 201 | """Action to allow running an external command as a side-effect. |
|---|
| | 202 | |
|---|
| | 203 | If it is a lengthy task, it should daemonize so the webserver can get back |
|---|
| | 204 | to doing its thing. If the script exits with a non-zero return code, an |
|---|
| | 205 | error will be logged to the Trac log. |
|---|
| | 206 | |
|---|
| | 207 | <someaction>.operations = run_external |
|---|
| | 208 | <someaction>.run_external = echo "blah blah blah" >> /var/log/blah |
|---|
| | 209 | <someaction>.run_external_hint = Clue the user in. |
|---|
| | 210 | |
|---|
| | 211 | Don't forget to add the `TicketWorkflowOpRunExternal` to the workflow |
|---|
| | 212 | option in [ticket]. |
|---|
| | 213 | If there is no workflow option, the line will look like this: |
|---|
| | 214 | |
|---|
| | 215 | workflow = ConfigurableTicketWorkflow,TicketWorkflowOpRunExternal |
|---|
| | 216 | """ |
|---|
| | 217 | |
|---|
| | 218 | implements(ITicketActionController) |
|---|
| | 219 | |
|---|
| | 220 | # ITicketActionController methods |
|---|
| | 221 | |
|---|
| | 222 | def get_ticket_actions(self, req, ticket): |
|---|
| | 223 | """Finds the actions that use this operation""" |
|---|
| | 224 | controller = ConfigurableTicketWorkflow(self.env) |
|---|
| | 225 | return controller.get_actions_by_operation_for_req(req, ticket, |
|---|
| | 226 | 'run_external') |
|---|
| | 227 | |
|---|
| | 228 | def get_all_status(self): |
|---|
| | 229 | """Provide any additional status values""" |
|---|
| | 230 | # We don't have anything special here; the statuses will be recognized |
|---|
| | 231 | # by the default controller. |
|---|
| | 232 | return [] |
|---|
| | 233 | |
|---|
| | 234 | def render_ticket_action_control(self, req, ticket, action): |
|---|
| | 235 | """Returns the action control""" |
|---|
| | 236 | actions = ConfigurableTicketWorkflow(self.env).actions |
|---|
| | 237 | label = actions[action]['name'] |
|---|
| | 238 | hint = self.config.get('ticket-workflow', |
|---|
| | 239 | action + '.run_external_hint').strip() |
|---|
| | 240 | if hint is None: |
|---|
| | 241 | hint = "Will run external script." |
|---|
| | 242 | return (label, tag(''), hint) |
|---|
| | 243 | |
|---|
| | 244 | def get_ticket_changes(self, req, ticket, action): |
|---|
| | 245 | """No changes to the ticket""" |
|---|
| | 246 | return {} |
|---|
| | 247 | |
|---|
| | 248 | def apply_action_side_effects(self, req, ticket, action): |
|---|
| | 249 | """Run the external script""" |
|---|
| | 250 | script = self.config.get('ticket-workflow', |
|---|
| | 251 | action + '.run_external').strip() |
|---|
| | 252 | retval = call(script, shell=True) |
|---|
| | 253 | if retval: |
|---|
| | 254 | self.env.log.error("External script %r exited with %s." % (script, |
|---|
| | 255 | retval)) |
|---|