# TODO: Define default python3 interpreter. # # Description: # Trigger to block submission of changelists which contain any variation of # "do not submit" (case/spacing insensitive) on the first line of the changelist # description. # # Use: # "DoNotSubmit.py -p %serverAddress% -c %changelist%" # # Trigger use: # DoNotSubmit change-submit //DepotPathForTargetFiles/... # ".../TriggerDirectory/DoNotSubmit.py -p %masterServer% -c %changelist%" # # Author: Joe Robinson # Created: 2013/06/26 # Editor: $Author$ # Edited: $DateTime$ # File: $File$ import sys, re, marshal, subprocess # sys: exit() # re: Regular expression matching. # marshal: Python dictionary loading. # subprocess: Process creation and piping # of stdout. from optparse import OptionParser # Command-line argument parser # ADMIN OPTIONS: #---------- # String to check top comment for. regexString = '^DO[\W_]*NOT[\W_]*SUBMIT[\W_]*$' # Compile expression with optional params (ignore case, multiline, etc) # By default, does not reject description with the regexString on any line other # than the first. # # re.I - Ignore case # re.M - '^' and '$' will match the begging and end of each line in addition to # the beginning and end of the string. regex = re.compile(r"%s" % regexString, re.I | re.M) # LOCATION of p4 binary (server-side) p4binary = "/usr/local/bin/p4" # User to run 'p4 change' command as. Example: "someServiceUser" userArg = "someServiceUser" #---------- # Options parsing: #---------- usage = "%prog -p %serverAddress% -c %changelist%" parser = OptionParser(usage = usage) parser.add_option("-c", "--changeNum", action = "store", type = "string", dest = "changelistNum", help = "Changelist number to check.", metavar = "%changelist%") parser.add_option("-p", action = "store", type = "string", dest = "serverAddress", help = "Address of server (hostname:port).", metavar = "%serverAddress%") (options, args) = parser.parse_args() # Load a dictionary from 'p4 -G change' with command-line options. #---------- reader = subprocess.Popen( [p4binary, "-G", "-p", options.serverAddress, "-u", userArg, "change", "-o", options.changelistNum], stdout=subprocess.PIPE ) stdout, stderr = reader.communicate() dictionary = marshal.loads(stdout) # Assign desc field to string for regular expression comparison. #---------- descString = (dictionary[b'Description']).decode() # Exit with error message if string is matched. if (regex.match(descString)): sys.exit(" --- DoNotSubmit (py) REJECTED changelist %s." % options.changelistNum) # If match is not found, exit(0) to allow the submit to pass. sys.exit(0)
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 8328 | Joe Robinson |
Added completed bash script. License file. |
||
#4 | 8325 | Joe Robinson |
File housekeeping - cleaned up spacing and obsolete comments. Removed '-u' flag. 'userArg' now part of admin options. |
||
#3 | 8323 | Joe Robinson |
Fixed regex matching. Command-line options parsing and changelist dictionary retrieval implemented. Does not check for Python version. Works with Python3.3+. |
||
#2 | 8321 | Joe Robinson |
Almost fixed regex matcher. Detects built-in test string, does not detect dictionary test string. |
||
#1 | 8320 | Joe Robinson |
First test version of py version. Fixed file paths. |
||
//guest/joe_robinson/main/projects/DoNotSubmit/src/DoNotSubmit.py | |||||
#1 | 8316 | Joe Robinson | Added blank .rb and .py files. |