Changeset 3631

Show
Ignore:
Timestamp:
05/07/08 21:05:24 (8 months ago)
Author:
retracile
Message:

AdvancedTicketWorkflowPlugin: Add a 'run_external' workflow operation. Bump the version number.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • advancedticketworkflowplugin/0.11/advancedworkflow/controller.py

    r3628 r3631  
    33""" 
    44 
     5from subprocess import call 
    56from genshi.builder import tag 
    67 
     
    910from trac.ticket.api import ITicketActionController 
    1011from trac.ticket.default_workflow import ConfigurableTicketWorkflow 
    11  
    12 # TODO: 
    13 #    set_owner_to_previous 
    14 #    run_external 
    1512 
    1613 
     
    199196            owner = '' 
    200197        return owner 
     198 
     199 
     200class 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)) 
  • advancedticketworkflowplugin/0.11/setup.py

    r3628 r3631  
    55setup(   
    66        name='AdvancedTicketWorkflowPlugin', 
    7         version='0.2', 
     7        version='0.3', 
    88        author = 'Eli Carter', 
    99        author_email = 'elicarter@retracile.net',