From b840cd4f247094ffe1233e213a4323ff7237f441 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Fri, 1 Jul 2011 17:08:50 -0400 Subject: Refactor export.py to use main() clause. Minimal testing has been done to compare export.py and export2.py. --- tools/export2.py | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 tools/export2.py diff --git a/tools/export2.py b/tools/export2.py new file mode 100755 index 000000000..9fa920d18 --- /dev/null +++ b/tools/export2.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +Second attempt to make our export script more portable than export.sh +""" + +import fileinput +from subprocess import Popen, PIPE +import sys + +# py3k compatibility +try: + from email.Utils import formatdate +except ImportError: + from email.utils import formatdate + +def run(command): + return Popen(command, shell=True, stdout=PIPE).communicate() + +def find_and_replace(f, iftest, rline, startswith=False): + for line in fileinput.input(f, inplace=1): + if startswith: + if line.startswith(iftest): + line = line.replace(line, rline) + sys.stdout.write(line) + else: + if iftest in line and line != "Version: %{version}\n": + line = line.replace(line, rline) + sys.stdout.write(line) + + +if __name__ == '__main__': + pkgname = 'bcfg2' + ftphost = 'terra.mcs.anl.gov' + ftpdir = '/mcs/ftp/pub/bcfg' + + # py3k compatibility + try: + version = raw_input("Please enter the version you are tagging (e.g. 1.0.0): ") + name = raw_input("Your name: ") + email = raw_input("Your email: ") + except NameError: + version = input("Please enter the version you are tagging (e.g. 1.0.0): ") + name = input("Your name: ") + email = input("Your email: ") + + tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) + + # update the version + majorver = version[:5] + minorver = version[5:] + + newchangelog = \ + """bcfg2 (%s%s-0.0) unstable; urgency=low + + * New upstream release + + -- %s <%s> %s + + """ % (majorver, minorver, name, email, formatdate(localtime=True)) + + + # write out the new debian changelog + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + quit() + # Update redhat directory versions + with open('redhat/VERSION', 'w') as f: + f.write("%s\n" % majorver) + f.close() + with open('redhat/RELEASE', 'w') as f: + f.write("0.0%s\n" % minorver) + f.close() + # update solaris version + find_and_replace('solaris/Makefile', 'VERS=', + 'VERS=%s-1\n' % version, startswith=True) + find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', + 'VERSION="%s"\n' % version, startswith=True) + find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', + 'VERSION="%s"\n' % version, startswith=True) + # set new version in setup.py + find_and_replace('setup.py', 'version=', ' version="%s",\n' % version) + # replace version in misc/bcfg2.spec + find_and_replace('misc/bcfg2.spec', 'Version:', + 'Version: %s\n' % version) + # update the version in reports + find_and_replace('src/lib/Server/Reports/reports/templates/base.html', + 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version) + # update the version in the docs + find_and_replace('doc/conf.py', 'version =', + 'version = \'%s\'\n' % majorver[0:3], startswith=True) + find_and_replace('doc/conf.py', 'release =', + 'release = \'%s\'\n' % (majorver), startswith=True) + + # tag the release + #FIXME: do this using python-dulwich + cmd = "git commit -asm 'Version bump to %s'" % version + output = run(cmd)[0].strip() + # NOTE: This will use the default email address key. If you want to sign the tag + # using a different key, you will need to set 'signingkey' to the proper + # value in the [user] section of your git configuration. + cmd = "git tag -s v%s -m 'tagged %s release'" % (version, version) + output = run(cmd)[0].strip() + cmd = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + (pkgname, version, version, tarname) + output = run(cmd)[0].strip() + cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) + output = run(cmd)[0].strip() + + # upload release to ftp + cmd = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname + output = run(cmd)[0].strip() + + + + + + + + + -- cgit v1.2.3-1-g7c22 From 4ff124d7c9179c5286cf41256883a94ba2e07f7e Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Fri, 1 Jul 2011 17:13:09 -0400 Subject: Add new version variables to export script --- tools/export2.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 9fa920d18..bb7ad23ca 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -45,6 +45,17 @@ if __name__ == '__main__': name = input("Your name: ") email = input("Your email: ") + # parse version into Major.Minor.Build and validate + try: + [version_major, version_minor, version_build] = version.split(".") + if not version_major.isdigit() or not version_minor.isdigit(): + raise VersionError('isdigit() test failed') + except: + print "Version must be of the form Major.Minor.Build, where Major and Minor are integers and Build is a single digit optionally followed by pre##" + quit() + + version_macbuild = version_build[0:1] + tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) # update the version @@ -98,14 +109,14 @@ if __name__ == '__main__': # tag the release #FIXME: do this using python-dulwich - cmd = "git commit -asm 'Version bump to %s'" % version + cmd = "ggit commit -asm 'Version bump to %s'" % version output = run(cmd)[0].strip() # NOTE: This will use the default email address key. If you want to sign the tag # using a different key, you will need to set 'signingkey' to the proper # value in the [user] section of your git configuration. - cmd = "git tag -s v%s -m 'tagged %s release'" % (version, version) + cmd = "ggit tag -s v%s -m 'tagged %s release'" % (version, version) output = run(cmd)[0].strip() - cmd = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + cmd = "ggit archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ (pkgname, version, version, tarname) output = run(cmd)[0].strip() cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) -- cgit v1.2.3-1-g7c22 From 09cbf47c9a42a8ce588e9a6bfb5c45b228fcbaca Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 11:05:15 -0400 Subject: Add Environment.py file for building classes to gather env data. Includes Pyversion() class which simplifies getting the Python version that Bcfg2 is running under. It is mostly useful for Python 2 and under, since Python 3 has the handy sys.version_info.{major,minor,...} object. --- src/lib/Environment.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/lib/Environment.py diff --git a/src/lib/Environment.py b/src/lib/Environment.py new file mode 100644 index 000000000..782407ee2 --- /dev/null +++ b/src/lib/Environment.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +Environment.py + +Classes for easy access to python environment information (e.g. python version). +""" + +import sys +import os + +class Pyversion(): + + def __init__(self): + # This is only helpful for Python 2 and older. Python 3 has sys.version_info.major. + [self.major, self.minor, self.micro, self.releaselevel, self.serial] = sys.version_info + self.version = sys.version + self.hex = sys.hexversion + + +def main(): + # test class Pyversion + pyversion = Pyversion() + print "%s : %s" % ("major", pyversion.major) + print "%s : %s" % ("minor", pyversion.minor) + print "%s : %s" % ("micro", pyversion.micro) + print "%s : %s" % ("releaselevel", pyversion.releaselevel) + print "%s : %s" % ("serial", pyversion.serial) + print "%s : %s" % ("version", pyversion.version) + print "%s : %s" % ("hex", pyversion.hex) + + pass + + +if __name__ == '__main__': + main() + -- cgit v1.2.3-1-g7c22 From 0f16c41f46df8448b127d4e8b2274a9ffdcddb84 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 11:18:22 -0400 Subject: Exclude compiled python files from the git repository. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d449d8bb4..80cc98761 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ src/Bcfg2 +*.pyc -- cgit v1.2.3-1-g7c22 From b6560930b190fa05970b594e8029c0b17e9e4f8f Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 15:51:02 -0400 Subject: Add command line options to export tool. Run with -h to see all the options. --- tools/export2.py | 105 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 31 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index bb7ad23ca..886db0cf0 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -3,11 +3,14 @@ """ Second attempt to make our export script more portable than export.sh + """ import fileinput from subprocess import Popen, PIPE import sys +# This will need to be replaced with argsparse when we make a 2.7+/3.2+ version +import optparse # py3k compatibility try: @@ -15,6 +18,18 @@ try: except ImportError: from email.utils import formatdate +# In lieu of a config file +help_message = '''This script creates a tag in the Bcfg2 git repo and exports a tar file of the code +at that tag. + +This script must be run at the top of your git repository. +''' + + +pkgname = 'bcfg2' +ftphost = 'terra.mcs.anl.gov' +ftpdir = '/mcs/ftp/pub/bcfg' + def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() @@ -29,19 +44,39 @@ def find_and_replace(f, iftest, rline, startswith=False): line = line.replace(line, rline) sys.stdout.write(line) - -if __name__ == '__main__': - pkgname = 'bcfg2' - ftphost = 'terra.mcs.anl.gov' - ftpdir = '/mcs/ftp/pub/bcfg' +def main(argv=None): + # This is where the options are set up + p = optparse.OptionParser(description = help_message, + prog = 'export2.py', + version = '0.1', + usage = '%prog [-h|--help] [-v|--version] [-n|--dry-run] [-d|--debug]') + p.add_option('--verbose', '-v', + action = 'store_true', + help = 'turns on verbose mode', + default = False, + dest = 'verbose') + p.add_option('--dry-run', '-n', + action = 'store_true', + help = 'run in dry-run mode; no changes will be made to the system', + default = False, + dest = 'dryrun') + p.add_option('--debug', '-d', + action = 'store_true', + help = 'run in debun mode', + default = False, + dest = 'debug') + options, arguments = p.parse_args() + + if options.debug: + print options # py3k compatibility try: - version = raw_input("Please enter the version you are tagging (e.g. 1.0.0): ") + version = raw_input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") name = raw_input("Your name: ") email = raw_input("Your email: ") except NameError: - version = input("Please enter the version you are tagging (e.g. 1.0.0): ") + version = input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") name = input("Your name: ") email = input("Your email: ") @@ -73,12 +108,17 @@ if __name__ == '__main__': # write out the new debian changelog - with open('debian/changelog', 'r+') as f: - old = f.read() - f.seek(0) - f.write(newchangelog + old) - f.close() - quit() + try: + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + except: + print "Problem opening debian/changelog" + print help_message + quit() + # Update redhat directory versions with open('redhat/VERSION', 'w') as f: f.write("%s\n" % majorver) @@ -109,28 +149,31 @@ if __name__ == '__main__': # tag the release #FIXME: do this using python-dulwich - cmd = "ggit commit -asm 'Version bump to %s'" % version - output = run(cmd)[0].strip() + commando = {} + + commando["vcs_commit"] = "git commit -asm 'Version bump to %s'" % version + # NOTE: This will use the default email address key. If you want to sign the tag # using a different key, you will need to set 'signingkey' to the proper # value in the [user] section of your git configuration. - cmd = "ggit tag -s v%s -m 'tagged %s release'" % (version, version) - output = run(cmd)[0].strip() - cmd = "ggit archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ - (pkgname, version, version, tarname) - output = run(cmd)[0].strip() - cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) - output = run(cmd)[0].strip() - - # upload release to ftp - cmd = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname - output = run(cmd)[0].strip() - - - - - + commando["vcs_tag"] = "git tag -s v%s -m 'tagged %s release'" % (version, version) + commando["create_archive"] = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + (pkgname, version, version, tarname) + commando["gpg_encrypt"] = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) + # upload release to ftp + commando["scp_archive"] = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname + + # Execute the commands + commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] + if options.dryrun: + for cmd in commando_orders: + print "dry-run: %s" % commando[cmd] + else: + for cmd in commando_orders: + output = run(commando[cmd])[0].strip() +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3-1-g7c22 From cba35827f740d070b3493200a67632955c0e4c4a Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 16:31:36 -0400 Subject: Extend dry-run mode to file replacement --- tools/export2.py | 54 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 886db0cf0..25ac8335e 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -33,8 +33,13 @@ ftpdir = '/mcs/ftp/pub/bcfg' def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() -def find_and_replace(f, iftest, rline, startswith=False): - for line in fileinput.input(f, inplace=1): +def find_and_replace(f, iftest, rline, startswith=False, dryrun=True): + if dryrun: + inplace=0 + print "*** dry-run: New '%s' will look like this:" % f + else: + inplace=1 + for line in fileinput.input(f, inplace): if startswith: if line.startswith(iftest): line = line.replace(line, rline) @@ -43,6 +48,8 @@ def find_and_replace(f, iftest, rline, startswith=False): if iftest in line and line != "Version: %{version}\n": line = line.replace(line, rline) sys.stdout.write(line) + if dryrun: + print "*** End '%s'" % f def main(argv=None): # This is where the options are set up @@ -108,24 +115,33 @@ def main(argv=None): # write out the new debian changelog - try: - with open('debian/changelog', 'r+') as f: - old = f.read() - f.seek(0) - f.write(newchangelog + old) - f.close() - except: - print "Problem opening debian/changelog" - print help_message - quit() + if options.dryrun: + print "*** Add the following to the top of debian/changelog:\n%s" % newchangelog + print "\n" + else: + try: + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + except: + print "Problem opening debian/changelog" + print help_message + quit() # Update redhat directory versions - with open('redhat/VERSION', 'w') as f: - f.write("%s\n" % majorver) - f.close() - with open('redhat/RELEASE', 'w') as f: - f.write("0.0%s\n" % minorver) - f.close() + if options.dryrun: + print "*** Replace redhat/VERIONS content with '%s'." % majorver + print "*** Replace redhat/RELEASE content with '%s'." % minorver + else: + with open('redhat/VERSION', 'w') as f: + f.write("%s\n" % majorver) + f.close() + with open('redhat/RELEASE', 'w') as f: + f.write("0.0%s\n" % minorver) + f.close() + # update solaris version find_and_replace('solaris/Makefile', 'VERS=', 'VERS=%s-1\n' % version, startswith=True) @@ -170,7 +186,7 @@ def main(argv=None): commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] if options.dryrun: for cmd in commando_orders: - print "dry-run: %s" % commando[cmd] + print "*** dry-run: %s" % commando[cmd] else: for cmd in commando_orders: output = run(commando[cmd])[0].strip() -- cgit v1.2.3-1-g7c22 From 2503fdd13aeec12294ede0cfa16b1e3ead6e2a88 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 23:55:47 -0400 Subject: Finish converting find_and_replace calls to use dryrun argument. Set default value to false. Made the find_and_replace calls multilined. --- tools/export2.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 25ac8335e..0b8cc159d 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -33,7 +33,7 @@ ftpdir = '/mcs/ftp/pub/bcfg' def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() -def find_and_replace(f, iftest, rline, startswith=False, dryrun=True): +def find_and_replace(f, iftest, rline, startswith=False, dryrun=False): if dryrun: inplace=0 print "*** dry-run: New '%s' will look like this:" % f @@ -144,24 +144,37 @@ def main(argv=None): # update solaris version find_and_replace('solaris/Makefile', 'VERS=', - 'VERS=%s-1\n' % version, startswith=True) + 'VERS=%s-1\n' % version, + startswith=True, + dryrun=options.dryrun) find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', - 'VERSION="%s"\n' % version, startswith=True) + 'VERSION="%s"\n' % version, + startswith=True, + dryrun=options.dryrun) find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', - 'VERSION="%s"\n' % version, startswith=True) + 'VERSION="%s"\n' % version, + startswith=True, + dryrun=options.dryrun) # set new version in setup.py - find_and_replace('setup.py', 'version=', ' version="%s",\n' % version) + find_and_replace('setup.py', 'version=', ' version="%s",\n' % version, + dryrun=options.dryrun) # replace version in misc/bcfg2.spec find_and_replace('misc/bcfg2.spec', 'Version:', - 'Version: %s\n' % version) + 'Version: %s\n' % version, + dryrun=options.dryrun) # update the version in reports find_and_replace('src/lib/Server/Reports/reports/templates/base.html', - 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version) + 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version, + dryrun=options.dryrun) # update the version in the docs find_and_replace('doc/conf.py', 'version =', - 'version = \'%s\'\n' % majorver[0:3], startswith=True) + 'version = \'%s\'\n' % majorver[0:3], + startswith=True, + dryrun=options.dryrun) find_and_replace('doc/conf.py', 'release =', - 'release = \'%s\'\n' % (majorver), startswith=True) + 'release = \'%s\'\n' % (majorver), + startswith=True, + dryrun=options.dryrun) # tag the release #FIXME: do this using python-dulwich -- cgit v1.2.3-1-g7c22 From 0b24ff7603b4f8d2b00de8438559b131fa6d1ca4 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Fri, 1 Jul 2011 17:08:50 -0400 Subject: Refactor export.py to use main() clause. Minimal testing has been done to compare export.py and export2.py. --- tools/export2.py | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100755 tools/export2.py diff --git a/tools/export2.py b/tools/export2.py new file mode 100755 index 000000000..9fa920d18 --- /dev/null +++ b/tools/export2.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +Second attempt to make our export script more portable than export.sh +""" + +import fileinput +from subprocess import Popen, PIPE +import sys + +# py3k compatibility +try: + from email.Utils import formatdate +except ImportError: + from email.utils import formatdate + +def run(command): + return Popen(command, shell=True, stdout=PIPE).communicate() + +def find_and_replace(f, iftest, rline, startswith=False): + for line in fileinput.input(f, inplace=1): + if startswith: + if line.startswith(iftest): + line = line.replace(line, rline) + sys.stdout.write(line) + else: + if iftest in line and line != "Version: %{version}\n": + line = line.replace(line, rline) + sys.stdout.write(line) + + +if __name__ == '__main__': + pkgname = 'bcfg2' + ftphost = 'terra.mcs.anl.gov' + ftpdir = '/mcs/ftp/pub/bcfg' + + # py3k compatibility + try: + version = raw_input("Please enter the version you are tagging (e.g. 1.0.0): ") + name = raw_input("Your name: ") + email = raw_input("Your email: ") + except NameError: + version = input("Please enter the version you are tagging (e.g. 1.0.0): ") + name = input("Your name: ") + email = input("Your email: ") + + tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) + + # update the version + majorver = version[:5] + minorver = version[5:] + + newchangelog = \ + """bcfg2 (%s%s-0.0) unstable; urgency=low + + * New upstream release + + -- %s <%s> %s + + """ % (majorver, minorver, name, email, formatdate(localtime=True)) + + + # write out the new debian changelog + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + quit() + # Update redhat directory versions + with open('redhat/VERSION', 'w') as f: + f.write("%s\n" % majorver) + f.close() + with open('redhat/RELEASE', 'w') as f: + f.write("0.0%s\n" % minorver) + f.close() + # update solaris version + find_and_replace('solaris/Makefile', 'VERS=', + 'VERS=%s-1\n' % version, startswith=True) + find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', + 'VERSION="%s"\n' % version, startswith=True) + find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', + 'VERSION="%s"\n' % version, startswith=True) + # set new version in setup.py + find_and_replace('setup.py', 'version=', ' version="%s",\n' % version) + # replace version in misc/bcfg2.spec + find_and_replace('misc/bcfg2.spec', 'Version:', + 'Version: %s\n' % version) + # update the version in reports + find_and_replace('src/lib/Server/Reports/reports/templates/base.html', + 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version) + # update the version in the docs + find_and_replace('doc/conf.py', 'version =', + 'version = \'%s\'\n' % majorver[0:3], startswith=True) + find_and_replace('doc/conf.py', 'release =', + 'release = \'%s\'\n' % (majorver), startswith=True) + + # tag the release + #FIXME: do this using python-dulwich + cmd = "git commit -asm 'Version bump to %s'" % version + output = run(cmd)[0].strip() + # NOTE: This will use the default email address key. If you want to sign the tag + # using a different key, you will need to set 'signingkey' to the proper + # value in the [user] section of your git configuration. + cmd = "git tag -s v%s -m 'tagged %s release'" % (version, version) + output = run(cmd)[0].strip() + cmd = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + (pkgname, version, version, tarname) + output = run(cmd)[0].strip() + cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) + output = run(cmd)[0].strip() + + # upload release to ftp + cmd = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname + output = run(cmd)[0].strip() + + + + + + + + + -- cgit v1.2.3-1-g7c22 From 5aa97a1b01f0a4508d4e5adbe0db5022029bead8 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Fri, 1 Jul 2011 17:13:09 -0400 Subject: Add new version variables to export script --- tools/export2.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 9fa920d18..bb7ad23ca 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -45,6 +45,17 @@ if __name__ == '__main__': name = input("Your name: ") email = input("Your email: ") + # parse version into Major.Minor.Build and validate + try: + [version_major, version_minor, version_build] = version.split(".") + if not version_major.isdigit() or not version_minor.isdigit(): + raise VersionError('isdigit() test failed') + except: + print "Version must be of the form Major.Minor.Build, where Major and Minor are integers and Build is a single digit optionally followed by pre##" + quit() + + version_macbuild = version_build[0:1] + tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) # update the version @@ -98,14 +109,14 @@ if __name__ == '__main__': # tag the release #FIXME: do this using python-dulwich - cmd = "git commit -asm 'Version bump to %s'" % version + cmd = "ggit commit -asm 'Version bump to %s'" % version output = run(cmd)[0].strip() # NOTE: This will use the default email address key. If you want to sign the tag # using a different key, you will need to set 'signingkey' to the proper # value in the [user] section of your git configuration. - cmd = "git tag -s v%s -m 'tagged %s release'" % (version, version) + cmd = "ggit tag -s v%s -m 'tagged %s release'" % (version, version) output = run(cmd)[0].strip() - cmd = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + cmd = "ggit archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ (pkgname, version, version, tarname) output = run(cmd)[0].strip() cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) -- cgit v1.2.3-1-g7c22 From 146a7a633bc3a36de21f589af0eec10755b0cae5 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 11:05:15 -0400 Subject: Add Environment.py file for building classes to gather env data. Includes Pyversion() class which simplifies getting the Python version that Bcfg2 is running under. It is mostly useful for Python 2 and under, since Python 3 has the handy sys.version_info.{major,minor,...} object. --- src/lib/Environment.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/lib/Environment.py diff --git a/src/lib/Environment.py b/src/lib/Environment.py new file mode 100644 index 000000000..782407ee2 --- /dev/null +++ b/src/lib/Environment.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +Environment.py + +Classes for easy access to python environment information (e.g. python version). +""" + +import sys +import os + +class Pyversion(): + + def __init__(self): + # This is only helpful for Python 2 and older. Python 3 has sys.version_info.major. + [self.major, self.minor, self.micro, self.releaselevel, self.serial] = sys.version_info + self.version = sys.version + self.hex = sys.hexversion + + +def main(): + # test class Pyversion + pyversion = Pyversion() + print "%s : %s" % ("major", pyversion.major) + print "%s : %s" % ("minor", pyversion.minor) + print "%s : %s" % ("micro", pyversion.micro) + print "%s : %s" % ("releaselevel", pyversion.releaselevel) + print "%s : %s" % ("serial", pyversion.serial) + print "%s : %s" % ("version", pyversion.version) + print "%s : %s" % ("hex", pyversion.hex) + + pass + + +if __name__ == '__main__': + main() + -- cgit v1.2.3-1-g7c22 From 620cfe3e55265fc819994dab1e14b38966fa3eba Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 11:18:22 -0400 Subject: Exclude compiled python files from the git repository. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d449d8bb4..80cc98761 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ src/Bcfg2 +*.pyc -- cgit v1.2.3-1-g7c22 From 6a6032322a823eb7bcd4cdd8a08b177d99e74709 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 15:51:02 -0400 Subject: Add command line options to export tool. Run with -h to see all the options. --- tools/export2.py | 105 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 31 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index bb7ad23ca..886db0cf0 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -3,11 +3,14 @@ """ Second attempt to make our export script more portable than export.sh + """ import fileinput from subprocess import Popen, PIPE import sys +# This will need to be replaced with argsparse when we make a 2.7+/3.2+ version +import optparse # py3k compatibility try: @@ -15,6 +18,18 @@ try: except ImportError: from email.utils import formatdate +# In lieu of a config file +help_message = '''This script creates a tag in the Bcfg2 git repo and exports a tar file of the code +at that tag. + +This script must be run at the top of your git repository. +''' + + +pkgname = 'bcfg2' +ftphost = 'terra.mcs.anl.gov' +ftpdir = '/mcs/ftp/pub/bcfg' + def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() @@ -29,19 +44,39 @@ def find_and_replace(f, iftest, rline, startswith=False): line = line.replace(line, rline) sys.stdout.write(line) - -if __name__ == '__main__': - pkgname = 'bcfg2' - ftphost = 'terra.mcs.anl.gov' - ftpdir = '/mcs/ftp/pub/bcfg' +def main(argv=None): + # This is where the options are set up + p = optparse.OptionParser(description = help_message, + prog = 'export2.py', + version = '0.1', + usage = '%prog [-h|--help] [-v|--version] [-n|--dry-run] [-d|--debug]') + p.add_option('--verbose', '-v', + action = 'store_true', + help = 'turns on verbose mode', + default = False, + dest = 'verbose') + p.add_option('--dry-run', '-n', + action = 'store_true', + help = 'run in dry-run mode; no changes will be made to the system', + default = False, + dest = 'dryrun') + p.add_option('--debug', '-d', + action = 'store_true', + help = 'run in debun mode', + default = False, + dest = 'debug') + options, arguments = p.parse_args() + + if options.debug: + print options # py3k compatibility try: - version = raw_input("Please enter the version you are tagging (e.g. 1.0.0): ") + version = raw_input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") name = raw_input("Your name: ") email = raw_input("Your email: ") except NameError: - version = input("Please enter the version you are tagging (e.g. 1.0.0): ") + version = input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") name = input("Your name: ") email = input("Your email: ") @@ -73,12 +108,17 @@ if __name__ == '__main__': # write out the new debian changelog - with open('debian/changelog', 'r+') as f: - old = f.read() - f.seek(0) - f.write(newchangelog + old) - f.close() - quit() + try: + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + except: + print "Problem opening debian/changelog" + print help_message + quit() + # Update redhat directory versions with open('redhat/VERSION', 'w') as f: f.write("%s\n" % majorver) @@ -109,28 +149,31 @@ if __name__ == '__main__': # tag the release #FIXME: do this using python-dulwich - cmd = "ggit commit -asm 'Version bump to %s'" % version - output = run(cmd)[0].strip() + commando = {} + + commando["vcs_commit"] = "git commit -asm 'Version bump to %s'" % version + # NOTE: This will use the default email address key. If you want to sign the tag # using a different key, you will need to set 'signingkey' to the proper # value in the [user] section of your git configuration. - cmd = "ggit tag -s v%s -m 'tagged %s release'" % (version, version) - output = run(cmd)[0].strip() - cmd = "ggit archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ - (pkgname, version, version, tarname) - output = run(cmd)[0].strip() - cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) - output = run(cmd)[0].strip() - - # upload release to ftp - cmd = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname - output = run(cmd)[0].strip() - - - - - + commando["vcs_tag"] = "git tag -s v%s -m 'tagged %s release'" % (version, version) + commando["create_archive"] = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + (pkgname, version, version, tarname) + commando["gpg_encrypt"] = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) + # upload release to ftp + commando["scp_archive"] = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname + + # Execute the commands + commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] + if options.dryrun: + for cmd in commando_orders: + print "dry-run: %s" % commando[cmd] + else: + for cmd in commando_orders: + output = run(commando[cmd])[0].strip() +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3-1-g7c22 From d2dfb778793bcf635de64f388b96da595f55740a Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 16:31:36 -0400 Subject: Extend dry-run mode to file replacement --- tools/export2.py | 54 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 886db0cf0..25ac8335e 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -33,8 +33,13 @@ ftpdir = '/mcs/ftp/pub/bcfg' def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() -def find_and_replace(f, iftest, rline, startswith=False): - for line in fileinput.input(f, inplace=1): +def find_and_replace(f, iftest, rline, startswith=False, dryrun=True): + if dryrun: + inplace=0 + print "*** dry-run: New '%s' will look like this:" % f + else: + inplace=1 + for line in fileinput.input(f, inplace): if startswith: if line.startswith(iftest): line = line.replace(line, rline) @@ -43,6 +48,8 @@ def find_and_replace(f, iftest, rline, startswith=False): if iftest in line and line != "Version: %{version}\n": line = line.replace(line, rline) sys.stdout.write(line) + if dryrun: + print "*** End '%s'" % f def main(argv=None): # This is where the options are set up @@ -108,24 +115,33 @@ def main(argv=None): # write out the new debian changelog - try: - with open('debian/changelog', 'r+') as f: - old = f.read() - f.seek(0) - f.write(newchangelog + old) - f.close() - except: - print "Problem opening debian/changelog" - print help_message - quit() + if options.dryrun: + print "*** Add the following to the top of debian/changelog:\n%s" % newchangelog + print "\n" + else: + try: + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + except: + print "Problem opening debian/changelog" + print help_message + quit() # Update redhat directory versions - with open('redhat/VERSION', 'w') as f: - f.write("%s\n" % majorver) - f.close() - with open('redhat/RELEASE', 'w') as f: - f.write("0.0%s\n" % minorver) - f.close() + if options.dryrun: + print "*** Replace redhat/VERIONS content with '%s'." % majorver + print "*** Replace redhat/RELEASE content with '%s'." % minorver + else: + with open('redhat/VERSION', 'w') as f: + f.write("%s\n" % majorver) + f.close() + with open('redhat/RELEASE', 'w') as f: + f.write("0.0%s\n" % minorver) + f.close() + # update solaris version find_and_replace('solaris/Makefile', 'VERS=', 'VERS=%s-1\n' % version, startswith=True) @@ -170,7 +186,7 @@ def main(argv=None): commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] if options.dryrun: for cmd in commando_orders: - print "dry-run: %s" % commando[cmd] + print "*** dry-run: %s" % commando[cmd] else: for cmd in commando_orders: output = run(commando[cmd])[0].strip() -- cgit v1.2.3-1-g7c22 From 6c4f30ab28d8200239350242b545c1021cb084d5 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Tue, 5 Jul 2011 23:55:47 -0400 Subject: Finish converting find_and_replace calls to use dryrun argument. Set default value to false. Made the find_and_replace calls multilined. --- tools/export2.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 25ac8335e..0b8cc159d 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -33,7 +33,7 @@ ftpdir = '/mcs/ftp/pub/bcfg' def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() -def find_and_replace(f, iftest, rline, startswith=False, dryrun=True): +def find_and_replace(f, iftest, rline, startswith=False, dryrun=False): if dryrun: inplace=0 print "*** dry-run: New '%s' will look like this:" % f @@ -144,24 +144,37 @@ def main(argv=None): # update solaris version find_and_replace('solaris/Makefile', 'VERS=', - 'VERS=%s-1\n' % version, startswith=True) + 'VERS=%s-1\n' % version, + startswith=True, + dryrun=options.dryrun) find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', - 'VERSION="%s"\n' % version, startswith=True) + 'VERSION="%s"\n' % version, + startswith=True, + dryrun=options.dryrun) find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', - 'VERSION="%s"\n' % version, startswith=True) + 'VERSION="%s"\n' % version, + startswith=True, + dryrun=options.dryrun) # set new version in setup.py - find_and_replace('setup.py', 'version=', ' version="%s",\n' % version) + find_and_replace('setup.py', 'version=', ' version="%s",\n' % version, + dryrun=options.dryrun) # replace version in misc/bcfg2.spec find_and_replace('misc/bcfg2.spec', 'Version:', - 'Version: %s\n' % version) + 'Version: %s\n' % version, + dryrun=options.dryrun) # update the version in reports find_and_replace('src/lib/Server/Reports/reports/templates/base.html', - 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version) + 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version, + dryrun=options.dryrun) # update the version in the docs find_and_replace('doc/conf.py', 'version =', - 'version = \'%s\'\n' % majorver[0:3], startswith=True) + 'version = \'%s\'\n' % majorver[0:3], + startswith=True, + dryrun=options.dryrun) find_and_replace('doc/conf.py', 'release =', - 'release = \'%s\'\n' % (majorver), startswith=True) + 'release = \'%s\'\n' % (majorver), + startswith=True, + dryrun=options.dryrun) # tag the release #FIXME: do this using python-dulwich -- cgit v1.2.3-1-g7c22 From c8f4173ac79691c6a2eb9fe59f755b4990227edf Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 12:01:23 -0400 Subject: Create paranoid mode for export script. Paranoid mode does not modify the git repository, but does modify the files. This allows git-diff to be used to see what will change when run in regular mode. --- tools/export2.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/export2.py b/tools/export2.py index 0b8cc159d..17e732bf6 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -72,10 +72,17 @@ def main(argv=None): help = 'run in debun mode', default = False, dest = 'debug') + p.add_option('--paranoid', '-P', + action = 'store_true', + help = 'run in paranoid mode, make changes but do not commit to repository', + default = False, + dest = 'paranoid') options, arguments = p.parse_args() if options.debug: print options + print "What should debug mode do?" + quit() # py3k compatibility try: @@ -180,6 +187,8 @@ def main(argv=None): #FIXME: do this using python-dulwich commando = {} + commando["vcs_diff"] = "git diff" + commando["vcs_commit"] = "git commit -asm 'Version bump to %s'" % version # NOTE: This will use the default email address key. If you want to sign the tag @@ -196,7 +205,11 @@ def main(argv=None): commando["scp_archive"] = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname # Execute the commands - commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] + if options.paranoid: + commando_orders = ["vcs_diff"] + else: + commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] + if options.dryrun: for cmd in commando_orders: print "*** dry-run: %s" % commando[cmd] -- cgit v1.2.3-1-g7c22 From 8276b715e11c445f8aae0b62ee3da5847bf3ab21 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 12:09:32 -0400 Subject: Create verbose option for running commands. If export2.py -P -v is run, then the diff will be shown. --- tools/export2.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/export2.py b/tools/export2.py index 17e732bf6..6e0e2787e 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -216,6 +216,8 @@ def main(argv=None): else: for cmd in commando_orders: output = run(commando[cmd])[0].strip() + if options.verbose: + print output if __name__ == '__main__': sys.exit(main()) -- cgit v1.2.3-1-g7c22 From 127322030d16857a5e4aec4d8a3910c9c70709df Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 12:16:49 -0400 Subject: Made verbose mode for commands a little more verbose. --- tools/export2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/export2.py b/tools/export2.py index 6e0e2787e..a6a06da14 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -217,6 +217,7 @@ def main(argv=None): for cmd in commando_orders: output = run(commando[cmd])[0].strip() if options.verbose: + print "Ran '%s' with output:" % cmd print output if __name__ == '__main__': -- cgit v1.2.3-1-g7c22 From c30660980db658ebfbffe83174cec0150e1aa3ba Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 13:29:44 -0400 Subject: Group verpose output in a more logical way. --- tools/export2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export2.py b/tools/export2.py index a6a06da14..567d4b227 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -217,8 +217,8 @@ def main(argv=None): for cmd in commando_orders: output = run(commando[cmd])[0].strip() if options.verbose: - print "Ran '%s' with output:" % cmd print output + print "Ran '%s' with above output." % cmd if __name__ == '__main__': sys.exit(main()) -- cgit v1.2.3-1-g7c22 From 1294f5b1a25791eeb906ecdd75d5a7f21de8a7fe Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 15:45:16 -0400 Subject: Derive majorver and minorver from dictionary; Add debug check. --- tools/export2.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 567d4b227..770df5350 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -82,7 +82,6 @@ def main(argv=None): if options.debug: print options print "What should debug mode do?" - quit() # py3k compatibility try: @@ -94,22 +93,34 @@ def main(argv=None): name = input("Your name: ") email = input("Your email: ") - # parse version into Major.Minor.Build and validate + # parse version into Major.Minor.MicroBuild and validate + vkeys = ["major", "minor", "microbuild"] try: - [version_major, version_minor, version_build] = version.split(".") - if not version_major.isdigit() or not version_minor.isdigit(): + version_info = dict(zip(vkeys,version.split("."))) + if not version_info["major"].isdigit() or not version_info["minor"].isdigit(): raise VersionError('isdigit() test failed') except: - print "Version must be of the form Major.Minor.Build, where Major and Minor are integers and Build is a single digit optionally followed by pre##" + print """Version must be of the form Major.Minor.MicroBuild, +where Major and Minor are integers and +Micro is a single digit optionally followed by Build (i.e. pre##) +E.G. 1.2.0pre1 is a valid version. + """ quit() - version_macbuild = version_build[0:1] + version_info["micro"] = version_info["microbuild"][0:1] + version_info["build"] = version_info["microbuild"][1:] + version_release = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) + if options.debug: + print "version is %s" % version + print "version_info is %s" % version_info + print "version_version is %s" % version_release + tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) # update the version - majorver = version[:5] - minorver = version[5:] + majorver = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) + minorver = version_info['build'] newchangelog = \ """bcfg2 (%s%s-0.0) unstable; urgency=low @@ -182,6 +193,11 @@ def main(argv=None): 'release = \'%s\'\n' % (majorver), startswith=True, dryrun=options.dryrun) + # update osx Makefile + find_and_replace('osx/Makefile', 'BCFGVER =', + 'BCFGVER = \'%s\'\n' % (version), + startswith=True, + dryrun=options.dryrun) # tag the release #FIXME: do this using python-dulwich -- cgit v1.2.3-1-g7c22 From 7251e6f829b3a81ce281318d930c19429de71e81 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 15:52:15 -0400 Subject: Replace majorver with version_release. --- tools/export2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 770df5350..1beb9e628 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -129,7 +129,7 @@ E.G. 1.2.0pre1 is a valid version. -- %s <%s> %s - """ % (majorver, minorver, name, email, formatdate(localtime=True)) + """ % (version_release, minorver, name, email, formatdate(localtime=True)) # write out the new debian changelog @@ -150,11 +150,11 @@ E.G. 1.2.0pre1 is a valid version. # Update redhat directory versions if options.dryrun: - print "*** Replace redhat/VERIONS content with '%s'." % majorver + print "*** Replace redhat/VERIONS content with '%s'." % version_release print "*** Replace redhat/RELEASE content with '%s'." % minorver else: with open('redhat/VERSION', 'w') as f: - f.write("%s\n" % majorver) + f.write("%s\n" % version_release) f.close() with open('redhat/RELEASE', 'w') as f: f.write("0.0%s\n" % minorver) @@ -190,7 +190,7 @@ E.G. 1.2.0pre1 is a valid version. startswith=True, dryrun=options.dryrun) find_and_replace('doc/conf.py', 'release =', - 'release = \'%s\'\n' % (majorver), + 'release = \'%s\'\n' % (version_release), startswith=True, dryrun=options.dryrun) # update osx Makefile -- cgit v1.2.3-1-g7c22 From 65c6238da8bb7cfc5e9af6e04e5a97d845b577c8 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 16:04:47 -0400 Subject: Replace majorver[0:3] with dictionary call. --- tools/export2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index 1beb9e628..e487b52e3 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -114,7 +114,7 @@ E.G. 1.2.0pre1 is a valid version. if options.debug: print "version is %s" % version print "version_info is %s" % version_info - print "version_version is %s" % version_release + print "version_release is %s" % version_release tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) @@ -186,7 +186,7 @@ E.G. 1.2.0pre1 is a valid version. dryrun=options.dryrun) # update the version in the docs find_and_replace('doc/conf.py', 'version =', - 'version = \'%s\'\n' % majorver[0:3], + 'version = \'%s.%s\'\n' % (version_info['major'], version_info['minor']), startswith=True, dryrun=options.dryrun) find_and_replace('doc/conf.py', 'release =', -- cgit v1.2.3-1-g7c22 From 8d1baecf2123cc5f100e5b819d94badbefc1df08 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 16:08:50 -0400 Subject: Replace minorver with dictionary call. --- tools/export2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index e487b52e3..be78ff6e6 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -129,7 +129,7 @@ E.G. 1.2.0pre1 is a valid version. -- %s <%s> %s - """ % (version_release, minorver, name, email, formatdate(localtime=True)) + """ % (version_release, version_info['build'], name, email, formatdate(localtime=True)) # write out the new debian changelog @@ -151,13 +151,13 @@ E.G. 1.2.0pre1 is a valid version. # Update redhat directory versions if options.dryrun: print "*** Replace redhat/VERIONS content with '%s'." % version_release - print "*** Replace redhat/RELEASE content with '%s'." % minorver + print "*** Replace redhat/RELEASE content with '%s'." % version_info['build'] else: with open('redhat/VERSION', 'w') as f: f.write("%s\n" % version_release) f.close() with open('redhat/RELEASE', 'w') as f: - f.write("0.0%s\n" % minorver) + f.write("0.0%s\n" % version_info['build']) f.close() # update solaris version -- cgit v1.2.3-1-g7c22 From ac985571ecf932f59b080a4e9dc580e6db694107 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 16:10:35 -0400 Subject: Remove unused veriables. --- tools/export2.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index be78ff6e6..780462523 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -117,10 +117,6 @@ E.G. 1.2.0pre1 is a valid version. print "version_release is %s" % version_release tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) - - # update the version - majorver = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) - minorver = version_info['build'] newchangelog = \ """bcfg2 (%s%s-0.0) unstable; urgency=low -- cgit v1.2.3-1-g7c22 From 1021d458baa61a581e29d99eadb4bf17cd057cb9 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 16:17:49 -0400 Subject: Prepare osx/Makefile to be changed by export2.py --- osx/Makefile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/osx/Makefile b/osx/Makefile index 8d16b42ae..e2223e0aa 100644 --- a/osx/Makefile +++ b/osx/Makefile @@ -29,13 +29,9 @@ SITELIBDIR = /Library/Python/${PYVERSION}/site-packages # an Info.plist file for packagemaker to look at for package creation # and substitute the version strings. Major/Minor versions can only be # integers (e.g. "1" and "00" for bcfg2 version 1.0.0. -BCFGVER = $(shell /usr/bin/grep version ../setup.py | cut -d\" -f2) -BCFGVER1 = $(shell /bin/echo ${BCFGVER} | /usr/bin/cut -d"." -f1) -BCFGVER2 = $(shell /bin/echo ${BCFGVER} | /usr/bin/cut -d"." -f2) -BCFGVER3 = $(shell /bin/echo ${BCFGVER} | /usr/bin/cut -d"." -f3) -BCFGVER3I = $(shell /usr/bin/python -c "import sys; print sys.argv[1][0:1]" ${BCFGVER3}) -MAJOR = ${BCFGVER1} -MINOR = ${BCFGVER2}${BCFGVER3I} +BCFGVER = v1.2.0pre3 +MAJOR = 1 +MINOR = 2.0 default: clean client -- cgit v1.2.3-1-g7c22 From 254fbd906be0d927f1a456e80a8add41d7aa9068 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Wed, 6 Jul 2011 16:22:37 -0400 Subject: Add code to modify osx/Makefile directly so version is no longer discovered. osx/Makefile will now have the version variables set when the repo is tagged like other package directories. --- tools/export2.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/export2.py b/tools/export2.py index 780462523..dd5816cab 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -191,7 +191,15 @@ E.G. 1.2.0pre1 is a valid version. dryrun=options.dryrun) # update osx Makefile find_and_replace('osx/Makefile', 'BCFGVER =', - 'BCFGVER = \'%s\'\n' % (version), + 'BCFGVER = %s\n' % (version), + startswith=True, + dryrun=options.dryrun) + find_and_replace('osx/Makefile', 'MAJOR =', + 'MAJOR = %s\n' % (version_info['major']), + startswith=True, + dryrun=options.dryrun) + find_and_replace('osx/Makefile', 'MINOR =', + 'MINOR = %s.%s\n' % (version_info['minor'], version_info['micro']), startswith=True, dryrun=options.dryrun) -- cgit v1.2.3-1-g7c22 From 32711630044db111893b1dd6a75e80e6a86504bc Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 09:22:14 -0400 Subject: Remove extra whitespace from the debian/changelog entry. --- tools/export2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/export2.py b/tools/export2.py index dd5816cab..fa75686b6 100755 --- a/tools/export2.py +++ b/tools/export2.py @@ -119,13 +119,13 @@ E.G. 1.2.0pre1 is a valid version. tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) newchangelog = \ - """bcfg2 (%s%s-0.0) unstable; urgency=low +"""bcfg2 (%s%s-0.0) unstable; urgency=low - * New upstream release + * New upstream release - -- %s <%s> %s + -- %s <%s> %s - """ % (version_release, version_info['build'], name, email, formatdate(localtime=True)) +""" % (version_release, version_info['build'], name, email, formatdate(localtime=True)) # write out the new debian changelog -- cgit v1.2.3-1-g7c22 From aa4665fcd46033aa44997fd36f5d974e9b48df91 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 09:40:34 -0400 Subject: Correct typo in version variable. --- osx/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osx/Makefile b/osx/Makefile index e2223e0aa..4bca85582 100644 --- a/osx/Makefile +++ b/osx/Makefile @@ -29,7 +29,7 @@ SITELIBDIR = /Library/Python/${PYVERSION}/site-packages # an Info.plist file for packagemaker to look at for package creation # and substitute the version strings. Major/Minor versions can only be # integers (e.g. "1" and "00" for bcfg2 version 1.0.0. -BCFGVER = v1.2.0pre3 +BCFGVER = 1.2.0pre3 MAJOR = 1 MINOR = 2.0 -- cgit v1.2.3-1-g7c22 From 44ef51ff7d1581f918e49d780c44b15c4ee2ed6b Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 09:44:33 -0400 Subject: Move export2.py ontop of export.py. One export script to rule them all. --- tools/export.py | 281 ++++++++++++++++++++++++++++++++++++++++--------------- tools/export2.py | 244 ----------------------------------------------- 2 files changed, 207 insertions(+), 318 deletions(-) delete mode 100755 tools/export2.py diff --git a/tools/export.py b/tools/export.py index 2885625d5..fa75686b6 100755 --- a/tools/export.py +++ b/tools/export.py @@ -1,12 +1,16 @@ #!/usr/bin/env python +# encoding: utf-8 """ -First attempt to make our export script more portable than export.sh +Second attempt to make our export script more portable than export.sh + """ import fileinput from subprocess import Popen, PIPE import sys +# This will need to be replaced with argsparse when we make a 2.7+/3.2+ version +import optparse # py3k compatibility try: @@ -14,22 +18,28 @@ try: except ImportError: from email.utils import formatdate +# In lieu of a config file +help_message = '''This script creates a tag in the Bcfg2 git repo and exports a tar file of the code +at that tag. + +This script must be run at the top of your git repository. +''' + + pkgname = 'bcfg2' ftphost = 'terra.mcs.anl.gov' ftpdir = '/mcs/ftp/pub/bcfg' -# py3k compatibility -try: - version = raw_input("Please enter the version you are tagging (e.g. 1.0.0): ") -except NameError: - version = input("Please enter the version you are tagging (e.g. 1.0.0): ") -tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) - def run(command): return Popen(command, shell=True, stdout=PIPE).communicate() -def find_and_replace(f, iftest, rline, startswith=False): - for line in fileinput.input(f, inplace=1): +def find_and_replace(f, iftest, rline, startswith=False, dryrun=False): + if dryrun: + inplace=0 + print "*** dry-run: New '%s' will look like this:" % f + else: + inplace=1 + for line in fileinput.input(f, inplace): if startswith: if line.startswith(iftest): line = line.replace(line, rline) @@ -38,74 +48,197 @@ def find_and_replace(f, iftest, rline, startswith=False): if iftest in line and line != "Version: %{version}\n": line = line.replace(line, rline) sys.stdout.write(line) + if dryrun: + print "*** End '%s'" % f -# update the version -majorver = version[:5] -minorver = version[5:] -# py3k compatibility -try: - name = raw_input("Your name: ") - email = raw_input("Your email: ") -except NameError: - name = input("Your name: ") - email = input("Your email: ") -newchangelog = \ +def main(argv=None): + # This is where the options are set up + p = optparse.OptionParser(description = help_message, + prog = 'export2.py', + version = '0.1', + usage = '%prog [-h|--help] [-v|--version] [-n|--dry-run] [-d|--debug]') + p.add_option('--verbose', '-v', + action = 'store_true', + help = 'turns on verbose mode', + default = False, + dest = 'verbose') + p.add_option('--dry-run', '-n', + action = 'store_true', + help = 'run in dry-run mode; no changes will be made to the system', + default = False, + dest = 'dryrun') + p.add_option('--debug', '-d', + action = 'store_true', + help = 'run in debun mode', + default = False, + dest = 'debug') + p.add_option('--paranoid', '-P', + action = 'store_true', + help = 'run in paranoid mode, make changes but do not commit to repository', + default = False, + dest = 'paranoid') + options, arguments = p.parse_args() + + if options.debug: + print options + print "What should debug mode do?" + + # py3k compatibility + try: + version = raw_input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") + name = raw_input("Your name: ") + email = raw_input("Your email: ") + except NameError: + version = input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") + name = input("Your name: ") + email = input("Your email: ") + + # parse version into Major.Minor.MicroBuild and validate + vkeys = ["major", "minor", "microbuild"] + try: + version_info = dict(zip(vkeys,version.split("."))) + if not version_info["major"].isdigit() or not version_info["minor"].isdigit(): + raise VersionError('isdigit() test failed') + except: + print """Version must be of the form Major.Minor.MicroBuild, +where Major and Minor are integers and +Micro is a single digit optionally followed by Build (i.e. pre##) +E.G. 1.2.0pre1 is a valid version. + """ + quit() + + version_info["micro"] = version_info["microbuild"][0:1] + version_info["build"] = version_info["microbuild"][1:] + version_release = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) + + if options.debug: + print "version is %s" % version + print "version_info is %s" % version_info + print "version_release is %s" % version_release + + tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) + + newchangelog = \ """bcfg2 (%s%s-0.0) unstable; urgency=low * New upstream release -- %s <%s> %s -""" % (majorver, minorver, name, email, formatdate(localtime=True)) -# write out the new debian changelog -with open('debian/changelog', 'r+') as f: - old = f.read() - f.seek(0) - f.write(newchangelog + old) -f.close() -# Update redhat directory versions -with open('redhat/VERSION', 'w') as f: - f.write("%s\n" % majorver) -f.close() -with open('redhat/RELEASE', 'w') as f: - f.write("0.0%s\n" % minorver) -f.close() -# update solaris version -find_and_replace('solaris/Makefile', 'VERS=', - 'VERS=%s-1\n' % version, startswith=True) -find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', - 'VERSION="%s"\n' % version, startswith=True) -find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', - 'VERSION="%s"\n' % version, startswith=True) -# set new version in setup.py -find_and_replace('setup.py', 'version=', ' version="%s",\n' % version) -# replace version in misc/bcfg2.spec -find_and_replace('misc/bcfg2.spec', 'Version:', - 'Version: %s\n' % version) -# update the version in reports -find_and_replace('src/lib/Server/Reports/reports/templates/base.html', - 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version) -# update the version in the docs -find_and_replace('doc/conf.py', 'version =', - 'version = \'%s\'\n' % majorver[0:3], startswith=True) -find_and_replace('doc/conf.py', 'release =', - 'release = \'%s\'\n' % (majorver), startswith=True) - -# tag the release -#FIXME: do this using python-dulwich -cmd = "git commit -asm 'Version bump to %s'" % version -output = run(cmd)[0].strip() -# NOTE: This will use the default email address key. If you want to sign the tag -# using a different key, you will need to set 'signingkey' to the proper -# value in the [user] section of your git configuration. -cmd = "git tag -s v%s -m 'tagged %s release'" % (version, version) -output = run(cmd)[0].strip() -cmd = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ - (pkgname, version, version, tarname) -output = run(cmd)[0].strip() -cmd = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) -output = run(cmd)[0].strip() - -# upload release to ftp -cmd = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname -output = run(cmd)[0].strip() +""" % (version_release, version_info['build'], name, email, formatdate(localtime=True)) + + + # write out the new debian changelog + if options.dryrun: + print "*** Add the following to the top of debian/changelog:\n%s" % newchangelog + print "\n" + else: + try: + with open('debian/changelog', 'r+') as f: + old = f.read() + f.seek(0) + f.write(newchangelog + old) + f.close() + except: + print "Problem opening debian/changelog" + print help_message + quit() + + # Update redhat directory versions + if options.dryrun: + print "*** Replace redhat/VERIONS content with '%s'." % version_release + print "*** Replace redhat/RELEASE content with '%s'." % version_info['build'] + else: + with open('redhat/VERSION', 'w') as f: + f.write("%s\n" % version_release) + f.close() + with open('redhat/RELEASE', 'w') as f: + f.write("0.0%s\n" % version_info['build']) + f.close() + + # update solaris version + find_and_replace('solaris/Makefile', 'VERS=', + 'VERS=%s-1\n' % version, + startswith=True, + dryrun=options.dryrun) + find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', + 'VERSION="%s"\n' % version, + startswith=True, + dryrun=options.dryrun) + find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', + 'VERSION="%s"\n' % version, + startswith=True, + dryrun=options.dryrun) + # set new version in setup.py + find_and_replace('setup.py', 'version=', ' version="%s",\n' % version, + dryrun=options.dryrun) + # replace version in misc/bcfg2.spec + find_and_replace('misc/bcfg2.spec', 'Version:', + 'Version: %s\n' % version, + dryrun=options.dryrun) + # update the version in reports + find_and_replace('src/lib/Server/Reports/reports/templates/base.html', + 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version, + dryrun=options.dryrun) + # update the version in the docs + find_and_replace('doc/conf.py', 'version =', + 'version = \'%s.%s\'\n' % (version_info['major'], version_info['minor']), + startswith=True, + dryrun=options.dryrun) + find_and_replace('doc/conf.py', 'release =', + 'release = \'%s\'\n' % (version_release), + startswith=True, + dryrun=options.dryrun) + # update osx Makefile + find_and_replace('osx/Makefile', 'BCFGVER =', + 'BCFGVER = %s\n' % (version), + startswith=True, + dryrun=options.dryrun) + find_and_replace('osx/Makefile', 'MAJOR =', + 'MAJOR = %s\n' % (version_info['major']), + startswith=True, + dryrun=options.dryrun) + find_and_replace('osx/Makefile', 'MINOR =', + 'MINOR = %s.%s\n' % (version_info['minor'], version_info['micro']), + startswith=True, + dryrun=options.dryrun) + + # tag the release + #FIXME: do this using python-dulwich + commando = {} + + commando["vcs_diff"] = "git diff" + + commando["vcs_commit"] = "git commit -asm 'Version bump to %s'" % version + + # NOTE: This will use the default email address key. If you want to sign the tag + # using a different key, you will need to set 'signingkey' to the proper + # value in the [user] section of your git configuration. + commando["vcs_tag"] = "git tag -s v%s -m 'tagged %s release'" % (version, version) + + commando["create_archive"] = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ + (pkgname, version, version, tarname) + + commando["gpg_encrypt"] = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) + + # upload release to ftp + commando["scp_archive"] = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname + + # Execute the commands + if options.paranoid: + commando_orders = ["vcs_diff"] + else: + commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] + + if options.dryrun: + for cmd in commando_orders: + print "*** dry-run: %s" % commando[cmd] + else: + for cmd in commando_orders: + output = run(commando[cmd])[0].strip() + if options.verbose: + print output + print "Ran '%s' with above output." % cmd + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/export2.py b/tools/export2.py deleted file mode 100755 index fa75686b6..000000000 --- a/tools/export2.py +++ /dev/null @@ -1,244 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -""" -Second attempt to make our export script more portable than export.sh - -""" - -import fileinput -from subprocess import Popen, PIPE -import sys -# This will need to be replaced with argsparse when we make a 2.7+/3.2+ version -import optparse - -# py3k compatibility -try: - from email.Utils import formatdate -except ImportError: - from email.utils import formatdate - -# In lieu of a config file -help_message = '''This script creates a tag in the Bcfg2 git repo and exports a tar file of the code -at that tag. - -This script must be run at the top of your git repository. -''' - - -pkgname = 'bcfg2' -ftphost = 'terra.mcs.anl.gov' -ftpdir = '/mcs/ftp/pub/bcfg' - -def run(command): - return Popen(command, shell=True, stdout=PIPE).communicate() - -def find_and_replace(f, iftest, rline, startswith=False, dryrun=False): - if dryrun: - inplace=0 - print "*** dry-run: New '%s' will look like this:" % f - else: - inplace=1 - for line in fileinput.input(f, inplace): - if startswith: - if line.startswith(iftest): - line = line.replace(line, rline) - sys.stdout.write(line) - else: - if iftest in line and line != "Version: %{version}\n": - line = line.replace(line, rline) - sys.stdout.write(line) - if dryrun: - print "*** End '%s'" % f - -def main(argv=None): - # This is where the options are set up - p = optparse.OptionParser(description = help_message, - prog = 'export2.py', - version = '0.1', - usage = '%prog [-h|--help] [-v|--version] [-n|--dry-run] [-d|--debug]') - p.add_option('--verbose', '-v', - action = 'store_true', - help = 'turns on verbose mode', - default = False, - dest = 'verbose') - p.add_option('--dry-run', '-n', - action = 'store_true', - help = 'run in dry-run mode; no changes will be made to the system', - default = False, - dest = 'dryrun') - p.add_option('--debug', '-d', - action = 'store_true', - help = 'run in debun mode', - default = False, - dest = 'debug') - p.add_option('--paranoid', '-P', - action = 'store_true', - help = 'run in paranoid mode, make changes but do not commit to repository', - default = False, - dest = 'paranoid') - options, arguments = p.parse_args() - - if options.debug: - print options - print "What should debug mode do?" - - # py3k compatibility - try: - version = raw_input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") - name = raw_input("Your name: ") - email = raw_input("Your email: ") - except NameError: - version = input("Please enter the Bcfg2 version you are tagging (e.g. 1.0.0): ") - name = input("Your name: ") - email = input("Your email: ") - - # parse version into Major.Minor.MicroBuild and validate - vkeys = ["major", "minor", "microbuild"] - try: - version_info = dict(zip(vkeys,version.split("."))) - if not version_info["major"].isdigit() or not version_info["minor"].isdigit(): - raise VersionError('isdigit() test failed') - except: - print """Version must be of the form Major.Minor.MicroBuild, -where Major and Minor are integers and -Micro is a single digit optionally followed by Build (i.e. pre##) -E.G. 1.2.0pre1 is a valid version. - """ - quit() - - version_info["micro"] = version_info["microbuild"][0:1] - version_info["build"] = version_info["microbuild"][1:] - version_release = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) - - if options.debug: - print "version is %s" % version - print "version_info is %s" % version_info - print "version_release is %s" % version_release - - tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) - - newchangelog = \ -"""bcfg2 (%s%s-0.0) unstable; urgency=low - - * New upstream release - - -- %s <%s> %s - -""" % (version_release, version_info['build'], name, email, formatdate(localtime=True)) - - - # write out the new debian changelog - if options.dryrun: - print "*** Add the following to the top of debian/changelog:\n%s" % newchangelog - print "\n" - else: - try: - with open('debian/changelog', 'r+') as f: - old = f.read() - f.seek(0) - f.write(newchangelog + old) - f.close() - except: - print "Problem opening debian/changelog" - print help_message - quit() - - # Update redhat directory versions - if options.dryrun: - print "*** Replace redhat/VERIONS content with '%s'." % version_release - print "*** Replace redhat/RELEASE content with '%s'." % version_info['build'] - else: - with open('redhat/VERSION', 'w') as f: - f.write("%s\n" % version_release) - f.close() - with open('redhat/RELEASE', 'w') as f: - f.write("0.0%s\n" % version_info['build']) - f.close() - - # update solaris version - find_and_replace('solaris/Makefile', 'VERS=', - 'VERS=%s-1\n' % version, - startswith=True, - dryrun=options.dryrun) - find_and_replace('solaris/pkginfo.bcfg2', 'VERSION=', - 'VERSION="%s"\n' % version, - startswith=True, - dryrun=options.dryrun) - find_and_replace('solaris/pkginfo.bcfg2-server', 'VERSION=', - 'VERSION="%s"\n' % version, - startswith=True, - dryrun=options.dryrun) - # set new version in setup.py - find_and_replace('setup.py', 'version=', ' version="%s",\n' % version, - dryrun=options.dryrun) - # replace version in misc/bcfg2.spec - find_and_replace('misc/bcfg2.spec', 'Version:', - 'Version: %s\n' % version, - dryrun=options.dryrun) - # update the version in reports - find_and_replace('src/lib/Server/Reports/reports/templates/base.html', - 'Bcfg2 Version', ' Bcfg2 Version %s\n' % version, - dryrun=options.dryrun) - # update the version in the docs - find_and_replace('doc/conf.py', 'version =', - 'version = \'%s.%s\'\n' % (version_info['major'], version_info['minor']), - startswith=True, - dryrun=options.dryrun) - find_and_replace('doc/conf.py', 'release =', - 'release = \'%s\'\n' % (version_release), - startswith=True, - dryrun=options.dryrun) - # update osx Makefile - find_and_replace('osx/Makefile', 'BCFGVER =', - 'BCFGVER = %s\n' % (version), - startswith=True, - dryrun=options.dryrun) - find_and_replace('osx/Makefile', 'MAJOR =', - 'MAJOR = %s\n' % (version_info['major']), - startswith=True, - dryrun=options.dryrun) - find_and_replace('osx/Makefile', 'MINOR =', - 'MINOR = %s.%s\n' % (version_info['minor'], version_info['micro']), - startswith=True, - dryrun=options.dryrun) - - # tag the release - #FIXME: do this using python-dulwich - commando = {} - - commando["vcs_diff"] = "git diff" - - commando["vcs_commit"] = "git commit -asm 'Version bump to %s'" % version - - # NOTE: This will use the default email address key. If you want to sign the tag - # using a different key, you will need to set 'signingkey' to the proper - # value in the [user] section of your git configuration. - commando["vcs_tag"] = "git tag -s v%s -m 'tagged %s release'" % (version, version) - - commando["create_archive"] = "git archive --format=tar --prefix=%s-%s/ v%s | gzip > %s" % \ - (pkgname, version, version, tarname) - - commando["gpg_encrypt"] = "gpg --armor --output %s.gpg --detach-sig %s" % (tarname, tarname) - - # upload release to ftp - commando["scp_archive"] = "scp %s* terra.mcs.anl.gov:/mcs/ftp/pub/bcfg/" % tarname - - # Execute the commands - if options.paranoid: - commando_orders = ["vcs_diff"] - else: - commando_orders = ["vcs_commit","vcs_tag","create_archive","gpg_encrypt","scp_archive"] - - if options.dryrun: - for cmd in commando_orders: - print "*** dry-run: %s" % commando[cmd] - else: - for cmd in commando_orders: - output = run(commando[cmd])[0].strip() - if options.verbose: - print output - print "Ran '%s' with above output." % cmd - -if __name__ == '__main__': - sys.exit(main()) -- cgit v1.2.3-1-g7c22 From 8552a8344283949808805137ef182fdc75a5072e Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 09:47:32 -0400 Subject: Correct typo in version variable. --- osx/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osx/Makefile b/osx/Makefile index e2223e0aa..4bca85582 100644 --- a/osx/Makefile +++ b/osx/Makefile @@ -29,7 +29,7 @@ SITELIBDIR = /Library/Python/${PYVERSION}/site-packages # an Info.plist file for packagemaker to look at for package creation # and substitute the version strings. Major/Minor versions can only be # integers (e.g. "1" and "00" for bcfg2 version 1.0.0. -BCFGVER = v1.2.0pre3 +BCFGVER = 1.2.0pre3 MAJOR = 1 MINOR = 2.0 -- cgit v1.2.3-1-g7c22 From ddbaad0ea618ce3bfd92db2cedc25ccc75a10f13 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 10:24:09 -0400 Subject: Add verification that version_info['micro'] is a single digit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because of restrictions in Mac OS X packaging, Bcfg2's Micro and Minor version numbers must be combined into an integer in the OS X package (IFMinorVersion attribute). In order for this to work, the micro version must be an integer, otherwise we'll run into cases where theĀ· IFMinorVersion will not be in sequence with the Bcfg2 Micro and Minor versions. --- osx/Makefile | 2 +- tools/export.py | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/osx/Makefile b/osx/Makefile index 4bca85582..de2d75402 100644 --- a/osx/Makefile +++ b/osx/Makefile @@ -31,7 +31,7 @@ SITELIBDIR = /Library/Python/${PYVERSION}/site-packages # integers (e.g. "1" and "00" for bcfg2 version 1.0.0. BCFGVER = 1.2.0pre3 MAJOR = 1 -MINOR = 2.0 +MINOR = 20 default: clean client diff --git a/tools/export.py b/tools/export.py index fa75686b6..b1c4d0ecb 100755 --- a/tools/export.py +++ b/tools/export.py @@ -97,24 +97,27 @@ def main(argv=None): vkeys = ["major", "minor", "microbuild"] try: version_info = dict(zip(vkeys,version.split("."))) - if not version_info["major"].isdigit() or not version_info["minor"].isdigit(): + version_info["micro"] = version_info["microbuild"][0:1] + version_info["build"] = version_info["microbuild"][1:] + version_release = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) + + if options.debug: + print "version is %s" % version + print "version_info is %s" % version_info + print "version_release is %s" % version_release + + if not version_info["major"].isdigit() or not version_info["minor"].isdigit() or not version_info["micro"]: raise VersionError('isdigit() test failed') + if version_info["micro"] > 1: + raise VersionError('micro must be single digit because IFMinorVersion restrictions in Mac OS X Packaging') except: print """Version must be of the form Major.Minor.MicroBuild, where Major and Minor are integers and Micro is a single digit optionally followed by Build (i.e. pre##) E.G. 1.2.0pre1 is a valid version. - """ +""" quit() - version_info["micro"] = version_info["microbuild"][0:1] - version_info["build"] = version_info["microbuild"][1:] - version_release = "%s.%s.%s" % (version_info['major'], version_info['minor'], version_info['micro']) - - if options.debug: - print "version is %s" % version - print "version_info is %s" % version_info - print "version_release is %s" % version_release tarname = '/tmp/%s-%s.tar.gz' % (pkgname, version) @@ -199,7 +202,7 @@ E.G. 1.2.0pre1 is a valid version. startswith=True, dryrun=options.dryrun) find_and_replace('osx/Makefile', 'MINOR =', - 'MINOR = %s.%s\n' % (version_info['minor'], version_info['micro']), + 'MINOR = %s%s\n' % (version_info['minor'], version_info['micro']), startswith=True, dryrun=options.dryrun) -- cgit v1.2.3-1-g7c22 From 5c9f5c5052acf4107ecbf13d5ab63c1a7996c87e Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 10:35:21 -0400 Subject: Check length of version['micro'] instead of value. --- tools/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export.py b/tools/export.py index b1c4d0ecb..c690ecd73 100755 --- a/tools/export.py +++ b/tools/export.py @@ -108,7 +108,7 @@ def main(argv=None): if not version_info["major"].isdigit() or not version_info["minor"].isdigit() or not version_info["micro"]: raise VersionError('isdigit() test failed') - if version_info["micro"] > 1: + if len(version_info["micro"]) > 1: raise VersionError('micro must be single digit because IFMinorVersion restrictions in Mac OS X Packaging') except: print """Version must be of the form Major.Minor.MicroBuild, -- cgit v1.2.3-1-g7c22 From 3c90ebcb31dc5f0f49e5c0ee9f00de78fc237af2 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 13:54:01 -0400 Subject: Document versioning conventions used by Bcfg2. --- doc/development/versioning.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 doc/development/versioning.txt diff --git a/doc/development/versioning.txt b/doc/development/versioning.txt new file mode 100644 index 000000000..e32a361a0 --- /dev/null +++ b/doc/development/versioning.txt @@ -0,0 +1,18 @@ +.. -*- mode: rst -*- + +.. _development-tips: + +Versioning Bcfg2 +---------------- + +#. These are the conventions Bcfg2 has adopted for `versioning`_: + + * The version number will be broken down into Major.Minor.MicroBuild. + * Major and Minor are ever increasing integers. + * Micro is a single digit integer. This is because of limits in some +of the package systems (specifically Mac OS X). + * Build is either missing or refers to release candidates: e.g. +"pre3". + + +.. _versioning: https://secure.wikimedia.org/wikipedia/en/wiki/Software_versioning -- cgit v1.2.3-1-g7c22 From 67b6e93187f8643283c98387dee5d4bcf28164f0 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 15:43:11 -0400 Subject: Correct typo in PYVERSION to fix Ticket 1023. --- osx/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osx/Makefile b/osx/Makefile index de2d75402..660c790cd 100644 --- a/osx/Makefile +++ b/osx/Makefile @@ -1,4 +1,4 @@ -PYVERSION := $(shell /usr/bin/python -c "import sys; print '%s.%s' % (sys.version_info[0], sys.version_info[1])"python -c "import sys; print sys.version[0:3]") +PYVERSION := $(shell /usr/bin/python -c "import sys; print '%s.%s' % (sys.version_info[0], sys.version_info[1])" PYMAJORVERSION := $(shell /usr/bin/python -c "import sys; print sys.version_info[0]") PYMINORVERSION := $(shell /usr/bin/python -c "import sys; print sys.version_info[1]") PREFLIGHT = preflight -- cgit v1.2.3-1-g7c22 From e788eb6afaf00516425e48ae27c72c20c5e4636a Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 15:59:09 -0400 Subject: Add missing ). --- osx/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osx/Makefile b/osx/Makefile index 660c790cd..a5920a5eb 100644 --- a/osx/Makefile +++ b/osx/Makefile @@ -1,4 +1,4 @@ -PYVERSION := $(shell /usr/bin/python -c "import sys; print '%s.%s' % (sys.version_info[0], sys.version_info[1])" +PYVERSION := $(shell /usr/bin/python -c "import sys; print '%s.%s' % (sys.version_info[0], sys.version_info[1])") PYMAJORVERSION := $(shell /usr/bin/python -c "import sys; print sys.version_info[0]") PYMINORVERSION := $(shell /usr/bin/python -c "import sys; print sys.version_info[1]") PREFLIGHT = preflight -- cgit v1.2.3-1-g7c22 From 2659263b9a6660e0dbcb3cac1967714b8cfb3639 Mon Sep 17 00:00:00 2001 From: Raul Cuza Date: Thu, 7 Jul 2011 16:26:20 -0400 Subject: Add documentation on how to get started with Bcfg2 on Mac OS X (10.6). --- doc/getting_started/macosx/notes.txt | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 doc/getting_started/macosx/notes.txt diff --git a/doc/getting_started/macosx/notes.txt b/doc/getting_started/macosx/notes.txt new file mode 100644 index 000000000..88178fee9 --- /dev/null +++ b/doc/getting_started/macosx/notes.txt @@ -0,0 +1,77 @@ += Setting up Bcfg2 From Scratch = + +Ala [[http://blog.conpocococo.org/post/6079832974/managing-etc-motd-with-bcfg2-starting-from-an-empty-vm|Managing /etc/motd with Bcfg2 Starting From an Empty VM]], I'll be setting up a fresh OS X 10.6 machine to be managed by [[http://bcfg2.org|Bcfg2]]. + +== Get OS X 10.6 Running == + +Use your favorite provisioning method (e.g. open-box-then-push-power-button, DVD, [[http://www.deploystudio.com/Home.html|DeplyStudio]], etc) to get your operating system running and fully patched. + +For this hands on, I'm running OS X 10.6.8 (Build 10K540) with the +supplied python 2.6.1. I've also turned on Remote Login (i.e. ssh) so I +can use my client to write this document going through the steps; having +ssh on is not a requirement for this howto. + +== Get bcfg2-server Working == + +=== Get bcfg2 package === + +You might be able to get a package already built for you, but it is not hard to build it from the source. You'll need git (via [[https://code.google.com/p/git-osx-installer/|git-osx-installer]] or [[https://github.com/mxcl/homebrew|homebrew]] the former is easier, the later more developer friendly) and Apple's [[http://developer.apple.com/xcode/|xcode]]. + +The first step is to clone the bcfg2 repository into a working directory: + +{{{#!highlight bash +cd ~/Devloper +git clone git://git.mcs.anl.gov/bcfg2.git +cd bcfg2 +}}} + +At this point you will probably want to checkout a release tag (`git tag -l` to +see a list of them). This test is using v1.2.0pre4. Once you've done +that you can build the server. + +{{{#!highlight bash +git checkout v1.2.0pre4 +cd osx +make server +}}} + +The server package contains both the client and the server. The package +is located at ./osx/bcfg2-VERSION.pkg. Copy it to the machine you want +to set up from scratch and install it. + +THIS NEEDS TO VERIFIED +Some of the differences between bcfg2 on Mac OS X and Debian is that the +libraries are stored at +`/Library/Frameworks/Python.framework/Versions/Current/share/bcfg2/` +`/Library/Python/site-packages/Bcfg2/` +instead of `/usr/lib/pymodules/` and `/usr/share/pyshare/Bcfg2. Also, +instead of cron and init.d, +`/Library/LaunchDaemons/gov.anl.mcs.bcfg2-daily.plist` controls peridic +runs and starts and stops. The runtime files are stored in +`/usr/local/bin` under Mac OS X instead of /usr/sbin/ for Debian. +VERIFY + +Error: bcfg2-admin init +""" +10.6_client :~ user$ sudo /usr/local/bin/bcfg2-admin init +Failed to import lxml dependency. Shutting down server. +""" + +Try: sudo easy_install lxml. If you don't have gcc-4.2 installed, you'll +need to install it on a machine that does. Then move +`/Library/Python/2.6/sites-packages/lxml-2.3-py2.6-macosx-10.6-universal.egg` +to the client and add the line +"./lxml-2.3-py2.6-macosx-10.6-universal.egg" to +`/Library/Python/2.6/site-packages/easy-install.pth`. + +getting a new error: + +$ sudo /usr/local/bin/bcfg2-admin init +Interactively initialize a new repository. + +bcfg2-admin init +$ + +So what is lxml easy_install fully installing? Need to make a package +(Lettuce to the rescue!) + -- cgit v1.2.3-1-g7c22