#!/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: WorkflowTriggers.py DESCRIPTION: Base class with utility functions for interfacing with Swarm and parsing workflow yaml file. """ # Python 2.7/3.3 compatibility. from __future__ import print_function import sys import P4Triggers import P4 import requests import yaml from string import Template class WorkflowTrigger(P4Triggers.P4Trigger): """See module doc string for details""" def load_config(self, config_file=None): if not config_file: config_file = "/p4/common/config/Workflow.yaml" config = {} try: with open(config_file, 'r') as f: config = yaml.load(f) except Exception as e: self.logger.error(str(e)) return config def get_swarm_url(self): """Read from Perforce server propery value""" if self.options.test_mode: return "http://swarm.dev/" prop = self.p4.run('property', '-l' , '-n', 'P4.Swarm.URL') self.logger.debug("Property: %s" % str(prop)) url = prop[0]['value'] if url[-1] != '/': url += '/' return url def get_project(self, config, change): """Return first matching project for a file in the change""" if not 'projects' in config: return {} # Search all config projects and return as soon as we find one that we are in which # has specified key value set to 'y' for prj in config['projects']: if not 'name' in prj or not 'depot_paths' in prj: return False map = P4.Map() for p in prj['depot_paths']: map.insert(p) for df in change.files: if map.includes(df.depotFile): return prj return {} def project_flag_true(self, config, change, key): """Returns True if specified field (key) has a value of 'y' for a matching project""" if not 'projects' in config: return False # Search all config projects and return as soon as we find one that we are in which # has specified key value set to 'y' for prj in config['projects']: if not 'name' in prj or not 'depot_paths' in prj: return False if not key in prj or not prj[key] == 'y': continue map = P4.Map() for p in prj['depot_paths']: map.insert(p) for df in change.files: if map.includes(df.depotFile): return True return False def formatReviewDescription(self, review_description, **kwargs): """Format using specified format options - see call below Assumes review_description is an array of lines in config file""" desc = "\n".join(review_description) desc = desc.replace("\\n", "\n") t = Template(desc) result = t.safe_substitute(**kwargs) return result
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 26652 | Robert Cowham |
This is Tom's change: Introduced new 'Unsupported' directory to clarify that some files in the SDP are not officially supported. These files are samples for illustration, to provide examples, or are deprecated but not yet ready for removal from the package. The Maintenance and many SDP triggers have been moved under here, along with other SDP scripts and triggers. Added comments to p4_vars indicating that it should not be edited directly. Added reference to an optional site_global_vars file that, if it exists, will be sourced to provide global user settings without needing to edit p4_vars. As an exception to the refactoring, the totalusers.py Maintenance script will be moved to indicate that it is supported. Removed settings to support long-sunset P4Web from supported structure. Structure under new .../Unsupported folder is: Samples/bin Sample scripts. Samples/triggers Sample trigger scripts. Samples/triggers/tests Sample trigger script tests. Samples/broker Sample broker filter scripts. Deprecated/triggers Deprecated triggers. To Do in a subsequent change: Make corresponding doc changes. |
||
#7 | 26049 | Robert Cowham | Allow only certain people (or group members) to create streams | ||
#6 | 24624 | Robert Cowham |
Add new feature/test for CheckSubmitHasReview: - pre_submit_test_must_pass When set, the Swarm testStatus config must equal 'pass' |
||
#5 | 24249 | Robert Cowham | Load YAML in order | ||
#4 | 23830 | Robert Cowham |
Refactor and move detection of shelved change up to P4Triggers. Also WorkflowTriggers |
||
#3 | 23528 | Robert Cowham | Handled default change | ||
#2 | 23527 | Robert Cowham | Add a config option fix_allowed_paths per project for CheckFixes.py | ||
#1 | 23420 | Robert Cowham | Refactored to use common WorkflowTriggers class |