[Openfirst-cvscommit] www/htdocs/nightly Makefile,1.1,1.2 package.py,1.1,1.2
Brought to you by:
xtimg
From: Jamie <ast...@us...> - 2005-11-21 18:37:44
|
Update of /cvsroot/openfirst/www/htdocs/nightly In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4573/www/htdocs/nightly Modified Files: Makefile package.py Log Message: - More advanced options in package.py (using the optparse module) - Can handle more than one module - Makefile correctly states that all is inefficient, not main and sdk A few bugs in package.py left: - Always produces an error (line 101) - Failed module list not nice - Probably only compatible with Python v2.3 and higher (definately v2.0 and higher) See `./package.py --help` for details on usage. Index: Makefile =================================================================== RCS file: /cvsroot/openfirst/www/htdocs/nightly/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 19 Nov 2005 19:16:46 -0000 1.1 --- Makefile 21 Nov 2005 18:37:32 -0000 1.2 *************** *** 6,10 **** ./package.py $@-nightly $(subst $(mprefix),,$@) ! # This is always enabled openfirst.base : ./package.py openfirst.base-nightly base --- 6,10 ---- ./package.py $@-nightly $(subst $(mprefix),,$@) ! # This module is always available openfirst.base : ./package.py openfirst.base-nightly base *************** *** 23,27 **** echo " help - Displays this message" echo "In addition, you may use the modules $(modtext) and 'openfirst.base' as targets." ! echo "WARNING: Using main or sdk is EXTREMELY inefficient." # Modules part of the standard distribution should go here --- 23,27 ---- echo " help - Displays this message" echo "In addition, you may use the modules $(modtext) and 'openfirst.base' as targets." ! echo "WARNING: Using all is EXTREMELY inefficient." # Modules part of the standard distribution should go here *************** *** 37,41 **** clean : rm -f pkg/*.tar.gz ! rm -f pkg/*.tar.bz rm -f pkg/*.zip --- 37,41 ---- clean : rm -f pkg/*.tar.gz ! rm -f pkg/*.tar.bz2 rm -f pkg/*.zip Index: package.py =================================================================== RCS file: /cvsroot/openfirst/www/htdocs/nightly/package.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.py 19 Nov 2005 17:26:38 -0000 1.1 --- package.py 21 Nov 2005 18:37:32 -0000 1.2 *************** *** 1,20 **** #!python ! """A script to package an openFIRST module""" ! ! from sys import argv, stdout, exit ! from os import * ## Use one of the following lines for the CVSROOT. ! ## The former is for external, the other for internal. CVSROOT = ":pserver:ano...@cv...:/cvsroot/openfirst" #CVSROOT = ":pserver:anonymous@cvs1:/cvsroot/openfirst" ! if len(argv) < 3 or "--help" in argv: ! stdout.write("""Packages openFIRST modules. ! Syntax: ! %s <package> <module> [<module> ...] ! Note that if you specify more than one module, then only the zip file will be ! correct.""" % argv[0]) ! exit(1) def getCVSModuleName(id): --- 1,46 ---- #!python ! """Packages openFIRST modules. Takes the package name and a series of CVS modules. ! Fails gracefully if the CVS export fails (by skiping that module).""" ## Use one of the following lines for the CVSROOT. ! ## The former is for external, the latter for internal. CVSROOT = ":pserver:ano...@cv...:/cvsroot/openfirst" #CVSROOT = ":pserver:anonymous@cvs1:/cvsroot/openfirst" ! ## Begin script proper ! from sys import argv, stderr, exit ! from os import * ! import shutil ! from optparse import OptionParser ! from subprocess import * ! ! ## Declare CLI options ! parser = OptionParser(usage="%prog <package> <module> ...", ! version="openFIRST 2.0", ! description=__doc__) ! ! parser.add_option("-r", "--cvsroot", ! action="store", type="string", dest="root", ! help="use ROOT as the CVSROOT during checkout", metavar="ROOT") ! parser.add_option("-q", "--quiet", ! action="store_false", dest="verbose", ! help="Hide the output from called programs") ! parser.add_option("-v", "--verbose", ! action="store_true", dest="verbose", ! help="Show the output from called programs [default]") ! parser.add_option("-d", "--debug", ! action="store_true", dest="debug", ! help="Show the commands used to call programs (on STDERR)") ! parser.add_option("-c", "--cvs-opt", ! action="append", type="string", dest="cvs", ! help="Add an additional CVS option (NOT IMPLEMENTED)", metavar="OPTION") ! parser.add_option("-t", "--cvs-tag", ! action="store", type="string", dest="tag", ! help="Use the CVS tag TAG during export", metavar="TAG") ! parser.set_defaults(root=CVSROOT, verbose=True, debug=False, cvs=['-R'], tag='HEAD') ! ! showProcessOutput = True ! debugProcessCalls = False ! CVSTag = 'HEAD' def getCVSModuleName(id): *************** *** 27,88 **** def checkOutCVS(module, target=None): ! command = "cvs -d%s export -rHEAD -R " % CVSROOT if target is not None: command += "-d %s " % (target) command += "%s" % (module) print "Exporting CVS module %s..." % module ! retval = system(command) return retval == 0 - # cvs = popen(command, 'r') - # print cvs - # print cvs.readlines() def system2(command): ! print "> "+command ! return system(command) def packageDirectory(directory, target): ! print "Creating gzip..." ! if path.exists(target+".tar.gz"): action = 'r' ! else: action = 'c' ! system2("tar -%szf %r %r" % (action, target+".tar.gz", directory)) ! ! print "Creating bzip..." ! if path.exists(target+".tar.bz"): action = 'r' else: action = 'c' ! system("tar -%sjf %r %r" % (action, target+".tar.bz", directory)) ! print "Creating zip..." ! system("zip -r %r %r" % (target+".zip", directory)) def packageBaseDirectory(directory, target): rtar = path.join(pardir, target) rtar2 = rtar ## Hack: Change \ to / ! #rtar2 = rtar.replace('\\', '/') chdir(directory) ! print "Creating gzip %s.tar.gz" % target ! if path.exists(target+".tar.gz"): action = 'r' ! else: action = 'c' ! system2("tar -%szf %s *" % (action, rtar2+".tar.gz")) ! ! print "Creating bzip %s.tar.bz" % target ! if path.exists(target+".tar.bz"): action = 'r' else: action = 'c' ! system("tar -%sjf %s *" % (action, rtar2+".tar.bz")) ! print "Creating zip %s.zip" % target ! system("zip -r %s %s" % (rtar+".zip", '*')) chdir(pardir) def cleanPackage(target): ! if path.exists(target+".tar.gz"): remove(target+".tar.gz") ! if path.exists(target+".tar.bz"): remove(target+".tar.bz") ! if path.exists(target+".zip"): remove(target+".zip") def cleanCVSExport(directory): if not path.exists(directory): return for f in listdir(directory): pf = path.join(directory, f) --- 53,124 ---- def checkOutCVS(module, target=None): ! command = "cvs -d%s export -r%s -R " % (CVSROOT, CVSTag) if target is not None: command += "-d %s " % (target) command += "%s" % (module) print "Exporting CVS module %s..." % module ! retval = system2(command) return retval == 0 def system2(command): ! if debugProcessCalls: print >> stderr, command ! if showProcessOutput: ! return system(command) ! else: ! proc = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE) ! proc.wait() ! return proc.returncode ! ! def initPackage(target): ! pass def packageDirectory(directory, target): ! print "Packaging %s into %s" % (directory, target) ! if path.exists(target+".tar"): action = 'r' else: action = 'c' ! system2("tar -%sf %r %r" % (action, target+".tar", directory)) ! system2("zip -r %r %r" % (target+".zip", directory)) def packageBaseDirectory(directory, target): + print "Packaging %s into %s" % (directory, target) rtar = path.join(pardir, target) rtar2 = rtar ## Hack: Change \ to / ! rtar2 = rtar.replace('\\', '/') chdir(directory) ! if path.exists(rtar+".tar"): action = 'r' else: action = 'c' ! system2("tar -%sf %s *" % (action, rtar2+".tar")) ! system2("zip -r %s *" % (rtar+".zip")) chdir(pardir) + def finalizePackage(target): + ## Always generates a warning. I'm too lazy to fix it. + tmp = tmpnam() + ## gzip takes the liberty of deleting the source file for us. + ## Unfortunately, it doesn't have an option to disable it. + ## So we just copy it off to a temporary location ... + shutil.copyfile(target+".tar", tmp) + ## ... run gzip ... + system2( "gzip -S .gz %s" % target+".tar" ) + ## ... and restore it. + shutil.move(tmp, target+".tar") + ## How nice! bzip2 _does_ have an option to keep the source file. + system2( "bzip2 -zk %s" % target+".tar" ) + # remove(target+".tar") + def cleanPackage(target): ! if path.exists(target+".tar"): remove(target+".tar") ! if path.exists(target+".tar.gz"): remove(target+".tar.gz") ! if path.exists(target+".tar.bz2"): remove(target+".tar.bz2") ! if path.exists(target+".zip"): remove(target+".zip") def cleanCVSExport(directory): if not path.exists(directory): return + # shutil.rmtree(directory) for f in listdir(directory): pf = path.join(directory, f) *************** *** 96,106 **** pass ! package = "pkg/openfirst-" + argv[1] cleanPackage(package) ! modules = argv[2:] for mod in modules: directory = mod cleanCVSExport(directory) ! checkOutCVS(mod) if mod == "base": packageBaseDirectory(directory, package) --- 132,161 ---- pass ! (options, args) = parser.parse_args() ! ! showProcessOutput = options.verbose ! debugProcessCalls = options.debug ! CVSROOT = options.root ! CVSTag = options.tag ! ## CVS options not implemented ! ! package = "pkg/" + args[1] cleanPackage(package) ! modules = args[2:] ! modules.sort() ! failed = [] ! ## Checkout CVS first for mod in modules: directory = mod cleanCVSExport(directory) ! if not checkOutCVS(mod): ! print "CVS Export failed!" ! failed += [mod] ! ! ## Package it ! initPackage(package) ! for mod in modules: ! directory = mod ! if not path.exists(directory): continue if mod == "base": packageBaseDirectory(directory, package) *************** *** 109,111 **** --- 164,173 ---- ## Don't allow web access to CVS cleanCVSExport(directory) + finalizePackage(package) + if len(failed) > 0: + mods = "" + for m in failed: mods += m+", " + print """%u module(s) failed to be exported, and were not included in + the package. They are: + %s""" % (len(failed), failed) |