#! /usr/local/bin/python ############################################################################## ## This script is now maintained as part of the PR system, and can be ## downloaded from the PR System web page. This script may be different ## from the one included with STCVS, but is not presently supported. ## Any bugs with this implementation of cm_pr_verify can be filed against ## the PRSystem. At some point this scirpt may convert back to bourne shell ## to remove the python and installation location dependancies, but works ## for now. Only this one script that was part of STCVS is supported with ## the PR System, and is the only piece that is required for integration with ## PR System builds. Tagging of individual releases of files is only ## required to correct comments where the PR number was valid for the ## repository, but was the incorrect PR. This re-tagging was always done ## by hand, so nothing has changed by not supporting the scirpt that tagged ## the individual versions of the files with PR numbers. ## ## cm_pr_verify script ## ## The cm_pr_verify script will always check that the commit log message ## contains a valid PR number. It will optionally check that the PR number is ## contained in the PR System database and that the PR was filed under a ## particular subsystem. The cm_pr_verify script will be called from the ## CVSROOT/verifymsg file. The verifymsg file is set up when the repository is ## created. The log message for each commit will be intercepted and parsed by ## the pr_verify script. If the PR number does not pass the tests, the commit ## will not be allowed. ## ## Syntax: ## ## cm_pr_verify [-v] [-s subsystem(s)] [-admin user] ## ## Arguments: ## ## None. The commit log message is written to a temporary file by the commit ## command. That file name is automatically passed to the script ## invoked by the verifymsg file. ## ## Options: ## ## -verify_pr Verify that the PR number in the message exists in the ## PR System database ## ## -subsys subsystem Verify that the PR specified with the verify_pr flag ## was filed under a particular subsystem This option ## supplies one or more comma-separated subsystem names. ## Any PR number used to commit a file must have been ## filed under one of the subsystems in the list. ## ## -admin user Do not require this user to provide a PR number. This ## is to provide for a CM account to make administrative ## changes without having to specifiy a PR number for ## a commit. ## ## Examples: ## ## An example of a valid cvs commit command that would be processed is: ## ## > cvs commit -m"PR 12345,24680 This is a test" x.java ## ## The examples below show the line that would appear in the verifymsg file. ## See CVS documentation for the verifymsg file format. ## ## ## 1. Check that the PR number is present in log message and that it has a ## valid format. ## ## DEFAULT $CVSROOT/CVSROOT/cm_pr_verify # ## 2. Check that the PR number is present in log message, has a valid format, ## is present in the PR System database and was filed under the SPSS or ## SCS subsystem. Allow the cm_mgr account to bypass this checking ## ## DEFAULT $CVSROOT/CVSROOT/cm_pr_verify -verify_pr -subsys SPSS,SCS -admin cm_mgr ## ############################################################################# import sys import os import re import string import urllib prNumber = "0" verify = 0 checkSubsys = 0 subsys = [] bypass = 0 admin = 0 PR_SYS_URL = "http://www.ess.stsci.edu/prsystem/servlet/" # # get command line options # i = 1 while i < len(sys.argv): if re.match("-su", sys.argv[i]): checkSubsys = 1 i += 1 subsys = sys.argv[i] subsysList = subsys.split(",") elif re.match("-ve", sys.argv[i]): verify = 1 elif re.match("-admin", sys.argv[i]): admin = 1 i += 1 adminUser = sys.argv[i] else: msgfile = sys.argv[i] i += 1 # # get the log message from temp file specified in last argument and check # the PR number format # f = open(msgfile) line = f.readline() f.close() prMatch = re.match('PR\s+[0-9,]+\s*', line.strip()) if not prMatch: user = os.environ['USER'] if admin and user == adminUser: # # Don't require PR for admin account # print "\nBypassing PR verify for admin user:", user, "\n" sys.exit(0) else: print "The string 'PR XXXXX ' must appear at the beginning of the log message." sys.exit(1) else: tokens = line.split() prNumberList = tokens[1].split(",") for prNumber in prNumberList: # # check PR number against PR system if option supplied # if checkSubsys != "" or verify: f = urllib.urlopen(PR_SYS_URL+"prsubsystems?active=1&prnum=" + prNumber) line = f.readline() if not line: print "PR", prNumber, "was not found in the PR System database" sys.exit(1) # # check against subsystem if supplied # found = 0 if checkSubsys : while line: try: i = subsysList.index(line.strip()) found = 1 break except(ValueError): line = f.readline() if not found: print "PR", prNumber, "must have been filed under one of the",\ "following subsystems:", subsys sys.exit(1) sys.exit(0)