from wizard import command, deploy, shell, app, util import sys import os def main(argv, baton): options, args = parse_args(argv, baton) if not os.path.exists(".git"): raise Exception("Not in root directory of Git repository") files = shell.eval("git", "ls-files", "-o") if files: raise Exception("Unversioned files exist, aborting (please cleanup directory first)") rav = args[0].split('-') av = app.ApplicationVersion.make(rav[0], rav[1]) try: shell.call("git", "rev-parse", av.pristine_tag) raise Error("Pristine tag already exists") except shell.CallError: pass try: shell.call("git", "rev-parse", av.wizard_tag) raise Error("Wizard tag already exists") except shell.CallError: pass shell.call("git", "checkout", "pristine") shell.call("wizard", "prepare-pristine", av.pristine_tag) shell.call("git", "commit", "-s", "-m", "%s %s" % (av.application.fullname, av.version)) shell.call("git", "tag", av.pristine_tag) shell.call("git", "checkout", "master", stdout=sys.stdout, stderr=sys.stderr) try: shell.call("git", "merge", "pristine", "--no-commit", stdout=sys.stdout, stderr=sys.stderr) except shell.CallError: # XXX refactor this pattern while 1: print "Dropping in shell: resolve conflicts and then exit" shell.interactive() if shell.eval("git", "ls-files", "--unmerged").strip(): print print "WARNING: There are still unmerged files." out = raw_input("Continue editing? [y/N]: ") if out == "y" or out == "Y": continue else: print "Aborting." sys.exit(1) break shell.call("git", "commit", "-s", "-m", "%s %s-scripts" % (av.application.fullname, av.version)) if options.test_dir: with util.ChangeDirectory(options.test_dir): shell.call("./%s-install-test.sh" % av.application.name, addenv={'WIZARD_NO_COMMIT': '1'}, stdout=sys.stdout, stderr=sys.stderr) with util.ChangeDirectory("testdir_%s_install_head" % av.application.name): shell.call("git", "stash") shell.call("git", "stash", "apply") shell.call("wizard", "prepare-config") if shell.eval("git", "ls-files", "--modified").strip(): print print "ERROR: There were configuration changes, bailing" print "Don't forget to make the %s tag when you're done" % av.wizard_tag print "Check %s for more details" % os.getcwd() sys.exit(1) shell.call("git", "stash", "apply") # so that uninstalls work shell.call("git", "tag", av.wizard_tag) def parse_args(argv, baton): usage = """usage: %prog prepare-upgrade APP-VERSION Interactively walks through the process of preparing an upgrade.""" parser = command.WizardOptionParser(usage) parser.add_option("--test-dir", dest="test_dir", metavar="DIR", default=None, help="This folder contains test scripts for this update.") options, args = parser.parse_all(argv) if len(args) > 1: parser.error("too many arguments") elif len(args) == 0: parser.error("please provide APP-VERSION") return options, args class Error(command.Error): """Base exception for all exceptions raised by upgrade""" pass