#!/usr/bin/env python """ _MakeRelease_ Release Tarball maker for D0Runjob. Checks out D0Runjob, MCPS, ShREEK, and Shahkar then creates a release tarball. Modify from MCPS version of MakeRelease """ import getopt import sys import popen2 import os import time usage="""MakeRelease.py Options: -h, --help : display this message --directory= : Check out modules and build tarfile in Otherwise, use /tmp/d0runjob-/ directory --d0runjob-tag= : Check out tagged version of D0Runjob with tag Uses the head version if not specified --shahkar-tag= : Check out tagged version of Shahkar with tag Uses the head version if not specified --mcps-tag= : Check out tagged version of MCPS with tag Uses the head version if not specified --agent-tag= : Check out tagged version of PRODAGENT with tag Uses the head version if not specified --tarfile= : Use the name provided as the name of the release tarfile. If not set an rtag will be used """ # cdcvs checkout # cvs -d cvsuser@cdcvs.fnal.gov:/cvs/cd checkout foobar # list of package to include in tarball, from various CVS # Most Shahkar/MCPS packages are now maintained in PRODAGENT shahkar_include = [ # 'Shahkar', # 'MB', 'Shampoo', 'XMLP', 'ShLogger', # 'ShREEK', ] d0rj_include = [ 'd0rjapps', 'd0rjaux', 'd0cards', 'd0rjcore', 'd0rjrcp', 'd0rjsam', 'd0rjsubmit', 'd0shreek', 'd0workflow', 'IMProv', 'jobscripts', 'MB', 'MgrFwk', 'name_algs', 'RunRes', 'scriptObjects', 'SeedGen', 'Shahkar', 'ShREEK', ] d0rj_aux = [ 'bin', 'etc', 'doc', 'macros', 'ups', 'xml' ] # replace these with PRODAGENT versions. mcps_include = ['DocMaker', 'MCPS', # remove 'MCPSPython', # remove 'MCPSShREEK', # remove 'PORC', # remove # 'RunRes', # need mods # 'SeedGen', ] agent_include = [ # 'MB', # 'ShLogger', # 'RunRes', # need mods # 'ShREEK', # need mods ] envD0Runjob = """ export CVSROOT=d0cvs@cdcvs.fnal.gov:/cvsroot/d0cvs export CVS_RSH=/usr/bin/ssh """ envShahkar = """ export CVSROOT=:pserver:anonymous@cdcvs.fnal.gov:/cvs/cd_read_only export CVS_RSH=/usr/bin/ssh """ envMCPS = """ export CVSROOT=:pserver:anonymous@cdcvs.fnal.gov:/cvs/uscms export CVS_RSH=/usr/bin/ssh """ # You may need to 'cvs login' with '98passwd' envAGENT = """ export CVSROOT=:pserver:anonymous@cmscvs.cern.ch:/cvs_server/repositories/CMSSW export CVS_RSH=/usr/bin/ssh """ #envShREEK = """ #export CVSROOT=:pserver:anonymous@cdcvs.fnal.gov:/cvs/uscms #export CVS_RSH=/usr/bin/ssh #""" def createWorkArea(dirName, release): """ create the basic directory structure """ os.makedirs(dirName) os.chdir(dirName) os.makedirs("%s/bin" % release) os.makedirs("%s/Python" % release) print "=> Release Area Created in :" print "=> %s" % dirName return def doCheckouts(cfg): """ check out the packages into the working area """ coD0Runjob = envD0Runjob coD0Runjob += "cd %s\n"%cfg['WorkingDir'] coD0Runjob += "cvs -Q" if cfg['D0RunjobTag'] != "HEAD": coD0Runjob += " export -r %s" % cfg['D0RunjobTag'] else: coD0Runjob += " co" coD0Runjob += " D0Runjob" coShahkar = envShahkar coShahkar += "cd %s\n"%cfg['WorkingDir'] coShahkar += "cvs -Q" if cfg["ShahkarTag"] != None: coShahkar += " export -r %s " % cfg["ShahkarTag"] else: coShahkar += " co" coShahkar += " Shahkar" coMCPS = envMCPS coMCPS += "cd %s\n"%cfg['WorkingDir'] coMCPS += "cvs -Q" if cfg["MCPSTag"] != None: coMCPS += " export -r %s " % cfg["MCPSTag"] else: coMCPS += " co" coMCPS += " MCPS" # coAGENT = envAGENT # coAGENT += "cd %s\n"%cfg['WorkingDir'] # coAGENT += "cvs -Q" # if cfg["AGENTTag"] != None: # coAGENT += " export -r %s " % cfg["AGENTTag"] # else: # coAGENT += " co" # coAGENT += " PRODAGENT" # coShREEK = envShREEK # coShREEK += "cd %s\n"%cfg['WorkingDir'] # coShREEK += "cvs -Q" # if cfg["ShREEKTag"] != None: # coShREEK += " export -r %s " % cfg["ShREEKTag"] # else: # coShREEK += " co" # coShREEK += " ShREEK" pop = popen2.Popen4(coD0Runjob) print "=> Doing: %s"%coD0Runjob while pop.poll() == -1: exitCode = pop.poll() exitCode = pop.poll() if exitCode != 0: print "Error Checking out D0Runjob:" print pop.fromchild.read() sys.exit(1) pop = popen2.Popen4(coShahkar) print "=> Doing: %s"%coShahkar while pop.poll() == -1: exitCode = pop.poll() exitCode = pop.poll() if exitCode != 0: print "Error Checking out Shahkar:" print pop.fromchild.read() sys.exit(1) pop = popen2.Popen4(coMCPS) print "=> Doing: %s"%coMCPS while pop.poll() == -1: exitCode = pop.poll() exitCode = pop.poll() if exitCode != 0: print "Error Checking out MCPS:" print pop.fromchild.read() sys.exit(1) # pop = popen2.Popen4(coAGENT) # print "=> Doing: %s"%coAGENT # while pop.poll() == -1: # exitCode = pop.poll() # exitCode = pop.poll() # if exitCode != 0: # print "Error Checking out PRODAGENT:" # print pop.fromchild.read() # sys.exit(1) # pop = popen2.Popen4(coShREEK) # print "=> Doing: %s"%coShREEK # while pop.poll() == -1: # exitCode = pop.poll() # exitCode = pop.poll() # if exitCode != 0: # print "Error Checking out ShREEK:" # print pop.fromchild.read() # sys.exit(1) for dir in d0rj_include: source = os.path.join(cfg["WorkingDir"], 'D0Runjob/d0runjob', dir) cmd = "/bin/cp -rf %s %s"%(source, cfg["PythonDir"]) os.system(cmd) for dir in d0rj_aux: source = os.path.join(cfg["WorkingDir"], 'D0Runjob', dir) cmd = "/bin/cp -rf %s %s"%(source, cfg["DistDir"]) os.system(cmd) for dir in shahkar_include: source = os.path.join(cfg["WorkingDir"], 'Shahkar/Python', dir) cmd = "/bin/cp -rf %s %s"%(source, cfg["PythonDir"]) os.system(cmd) for dir in mcps_include: source = os.path.join(cfg["WorkingDir"], 'MCPS/MCPSRunjob/Python', dir) cmd = "/bin/cp -rf %s %s"%(source, cfg["PythonDir"]) os.system(cmd) # for dir in agent_include: # source = os.path.join(cfg["WorkingDir"], 'PRODAGENT/src/python', dir) # cmd = "/bin/cp -rf %s %s"%(source, cfg["PythonDir"]) # os.system(cmd) # shreek_include = ['IMProv', # 'ShLogger', # 'ShREEK', # ] # for dir in shreek_include: # source = os.path.join(cfg["WorkingDir"], 'ShREEK/src/python', dir) # os.system("/bin/cp -rf %s %s"%(source, cfg["PythonDir"])) tarComm = "cd %s\n" % cfg["WorkingDir"] tarComm += "tar -zcf %s %s" % (cfg["Tarfile"], cfg["Version"]) print "Tarring:",tarComm os.system(tarComm) print "=> Tarfile Created:" print "=> %s" % cfg["Tarfile"] def processArgs(): """ _processArgs_ Process the command line args and return a dictionary containing the options and values """ shortopts = "h" longopts = [ "help", "directory=", "d0runjob-tag=", "shahkar-tag=", "mcps-tag=", # "agent-tag=", "tarfile=", ] try: opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts) except getopt.GetoptError: print usage sys.exit(1) result = {} result.setdefault("D0RunjobTag", "HEAD") result.setdefault("ShahkarTag", None) result.setdefault("MCPSTag", None) # result.setdefault("AGENTTag", None) timestamp = time.asctime(time.localtime(time.time())).replace(" ", "_") timestamp = timestamp.replace(":","-") result.setdefault("WorkingDir", os.path.join("/tmp", "d0runjob-%s" % timestamp)) for opt, arg in opts: if opt in ('-h', '--help'): print usage sys.exit(0) if opt == '--tarfile': result['Tarfile'] = arg if opt == '--directory': result["WorkingDir"] = arg if opt == '--d0runjob-tag': result["D0RunjobTag"] = arg if opt == '--shahkar-tag': result["ShahkarTag"] = arg if opt == '--mcps-tag': result["MCPSTag"] = arg # if opt == '--agent-tag': # result["AGENTTag"] = arg result.setdefault("Version", "d0runjob_%s" % result["D0RunjobTag"]) result.setdefault("DistDir", os.path.join(result["WorkingDir"], result["Version"])) result.setdefault("PythonDir", os.path.join(result["DistDir"], "Python")) result.setdefault("Tarfile", os.path.join(result["WorkingDir"], "%s.tar.gz" % result["Version"])) return result if __name__ == '__main__': cfg = processArgs() createWorkArea(cfg["WorkingDir"], cfg["Version"]) doCheckouts(cfg)