#! /usr/bin/env python # ______________________________________________________________________ # # Filename: cvs_latest_version # # Created: 20-JAN-2001, Harry Melanson # # ______________________________________________________________________ """Determine latest tag of a CVS package. USAGE: cvs_latest_version [-hv] package OPTIONS: -h, --help -- Print help text and exit. -p=pxx-br -- List latest version on specified production branch. Assumes packages are tagged with the following style: vxx-xx-xx. Ignores all other tags. Uses the command: cvs history -Ta """ # ______________________________________________________________________ import sys, os import glob import string # ______________________________________________________________________ __author__ = 'Harry Melanson, melanson@fnal.gov' __version__ = '00.00.00' __filename__ = 'memstats' __doc__ = __doc__ % vars() # ______________________________________________________________________ def process_command(): """Process the command.""" from scriptutil import getOptions optlist, args = getOptions('p:', [], __doc__) # Process command line arguments if len(args) == 0: print "\nERROR: No CVS package specified." print "\nNAME: ", (os.path.basename(sys.argv[0])) print __doc__ sys.exit(-1) FLAG = 'A' # Default flag - 'active tag' for opt in optlist: if opt.flag == '-p': FLAG = opt.value # Look for latest version on a production branch PACKAGE = args[0] command = 'cvs history -Ta | grep " ' + PACKAGE + ' "' # Issue cvs history command and get latest active version result = None for line in os.popen(command, 'r').readlines(): items = string.split(line) if len(items) != 7: print "WARNING: Format of cvs history has changed." print " Returned following line:" print "\n", string.join(items) sys.exit() else: version = items[6] if (string.find(version, ':' + FLAG) != -1): # Select latest version result = line # Report results if (result != None): items = string.split(result) package = items[5] version = string.split(string.split(result, FLAG)[0],'[')[-1][:-1] developer = items[4] date = items[1] time = items[2] if (package == PACKAGE): if FLAG == 'A': print "\nLatest tagged version of " + package + " on development branch: " + version + \ " (" + developer + ", " + date + ", " + time + ")\n" sys.exit() else: print "\nLatest tagged version of " + package + " on " + FLAG + ": " + version + \ " (" + developer + ", " + date + ", " + time + ")\n" sys.exit() else: print "WARNING: Different package encountered." print " Returned following line:" print "\n", string.join(items) sys.exit() else: print "WARNING: This package is either not in CVS or it has not yet been tagged." # ______________________________________________________________________ # # Execute command if __name__ == '__main__': process_command() sys.exit(0)