# 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. # # Author: Joe Robinson # Created: 2013/06/26 # Edited: %% # File: DoNotSubmit.py from sys import argv import sys, re, marshal #filename, changelistNum, serverDirectory, dictionaryFile = argv # TEST PARAMS #----- changelistNum = 0 dictionaryFile = open('text.txt', 'rb') dictionary = marshal.load(dictionaryFile) testString = "b'do-not-submit\n'" # Assign desc field to string #----- #TEST CASE = "b'DO_NOT_SUBMIT\n'" -> how to match to regex? descString = str(dictionary[b'desc']) print("Top comment line is: %s" % descString) # Exit with error message if string is found. # if desc field matches regular expression: ^b'do.not.submit'$ if (re.match(r"^b\'(DO).(NOT).(SUBMIT)\s*\n*\'$", descString, re.IGNORECASE)): print(" --- REJECTED submitted changelist.") sys.exit("PY script rejecting \'DO NOT SUBMIT\' changelist %i." % changelistNum) # Else if string is not found: print(" --- ACCEPTED submitted changelist %i." % changelistNum) sys.exit(0)