#!/usr/bin/env python3 # -*- coding: utf-8 -*- # ============================================================================== # Copyright and license info is available in the LICENSE file included with # the Server Deployment Package (SDP), and also available online: # https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE # ------------------------------------------------------------------------------ """ NAME: CreateSwarmReview.py DESCRIPTION: This trigger is intended for use with Swarm installations It will search for any jobs associated with the changelist and find any reviews associated with that job. If found it will update the review with this changelist Otherwise it will create a new Swarm review with a template description and with configurable reviewers as requested. To install, add a line to your Perforce triggers table like the following: create_swarm_review change-commit //... "python /p4/common/bin/triggers/CreateSwarmReview.py -p %serverport% -u perforce %change% " or (if server is standard SDP and has appropriate environment defaults for P4PORT and P4USER): create_swarm_review change-commit //... "python /p4/common/bin/triggers/CreateSwarmReview.py %change% " You may need to provide the full path to python executable, or edit the path to the trigger. Also, don't forget to make the file executable. """ # Python 2.7/3.3 compatibility. from __future__ import print_function import sys import re import argparse import textwrap import P4Triggers import shutil import os ###################################################################### # CONFIGURATION BLOCK # END OF CONFIGURATION BLOCK ###################################################################### class CreateSwarmReview(P4Triggers.P4Trigger): """See module doc string for details""" def __init__(self, *args, **kwargs): P4Triggers.P4Trigger.__init__(self, **kwargs) desc = textwrap.dedent(__doc__) parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=desc, epilog="Copyright (c) 2008-2017 Perforce Software, Inc." ) self.add_parse_args(parser) self.options = parser.parse_args(args=args) self.init_logger() self.logger.debug("Command Line Options: %s\n" % self.options) def add_parse_args(self, parser): """Specific args for this trigger - also calls super class to add common trigger args""" parser.add_argument('-c', '--config-file', help="Configuration file for trigger. Default: CreateSwarmReview.yaml") parser.add_argument('change', help="Change to process - %%change%% argument from triggers entry.") super(CreateSwarmReview, self).add_parse_args(parser) def run(self): """Runs trigger""" try: self.logger.debug("CreateSwarmReview trigger firing") self.setupP4() self.p4.connect() change = self.getChange(self.options.change) except Exception: return self.reportException() return 0 if __name__ == '__main__': """ Main Program""" trigger = CreateSwarmReview(*sys.argv[1:]) sys.exit(trigger.run())