+def main(argv, baton):
+ options, args = parse_args(argv, baton)
+ if args:
+ dir = args[0]
+ else:
+ dir = "."
+ shell.drop_priviledges(dir, options.log_file)
+ util.chdir(dir)
+ if os.path.exists(".scripts/blacklisted"):
+ raise BlacklistedError()
+ sh = shell.Shell()
+ util.set_git_env()
+ if options.continue_:
+ temp_wc_dir = os.getcwd()
+ user_commit, next_commit = open(".git/WIZARD_PARENTS", "r").read().split()
+ repo = open(".git/WIZARD_REPO", "r").read()
+ version = open(".git/WIZARD_UPGRADE_VERSION", "r").read()
+ util.chdir(sh.eval("git", "config", "remote.origin.url"))
+ d = deploy.Deployment(".")
+ try:
+ sh.call("git", "status")
+ raise LocalChangesError()
+ except shell.CallError:
+ pass
+ else:
+ d = deploy.Deployment(".")
+ d.verify()
+ d.verifyTag(options.srv_path)
+ d.verifyGit(options.srv_path)
+ d.verifyConfigured()
+ d.verifyVersion()
+ if not options.dry_run:
+ d.verifyWeb()
+ repo = d.application.repository(options.srv_path)
+ version = calculate_newest_version(sh, repo)
+ if version == d.app_version.scripts_tag and not options.force:
+ raise AlreadyUpgraded
+ if not options.dry_run:
+ perform_pre_commit(sh)
+ temp_wc_dir = perform_tmp_clone(sh)
+ with util.ChangeDirectory(temp_wc_dir):
+ sh.call("git", "remote", "add", "scripts", repo)
+ sh.call("git", "fetch", "-q", "scripts")
+ user_commit, next_commit = calculate_parents(sh, version)
+ # save variables so that --continue will work
+ # yeah yeah no trailing newline whatever
+ open(".git/WIZARD_REPO", "w").write(repo)
+ open(".git/WIZARD_UPGRADE_VERSION", "w").write(version)
+ open(".git/WIZARD_PARENTS", "w").write("%s\n%s" % (user_commit, next_commit))
+ perform_merge(sh, repo, d, version)
+ # variables: version, user_commit, next_commit, temp_wc_dir
+ with util.ChangeDirectory(temp_wc_dir):
+ try:
+ sh.call("git", "status")
+ sh.call("git", "commit", "-m", "throw-away commit")
+ except shell.CallError:
+ pass
+ message = make_commit_message(version)
+ new_tree = sh.eval("git", "rev-parse", "HEAD^{tree}")
+ final_commit = sh.eval("git", "commit-tree", new_tree,
+ "-p", user_commit, "-p", next_commit, input=message, log=True)
+ # a master branch may not necessarily exist if the user
+ # was manually installed to an earlier version
+ try:
+ sh.call("git", "checkout", "-q", "-b", "master", "--")
+ except shell.CallError:
+ sh.call("git", "checkout", "-q", "master", "--")
+ sh.call("git", "reset", "-q", "--hard", final_commit)
+ d.verifyVersion()
+ # Till now, all of our operations were in a tmp sandbox.
+ if options.dry_run:
+ logging.info("Dry run, bailing. See results at %s" % temp_wc_dir)
+ return
+ # perform database backup
+ backup = d.backup(options)
+ # XXX: frob .htaccess to make site inaccessible
+ with util.IgnoreKeyboardInterrupts():
+ with util.LockDirectory(".scripts-upgrade-lock"):
+ # git merge (which performs a fast forward)
+ sh.call("git", "pull", "-q", temp_wc_dir, "master")
+ version_obj = distutils.version.LooseVersion(version.partition('-')[2])
+ try:
+ # run update script
+ d.upgrade(version_obj, options)
+ d.verifyWeb()
+ except app.UpgradeFailure:
+ logging.warning("Upgrade failed: rolling back")
+ perform_restore(d, backup)
+ raise
+ except deploy.WebVerificationError as e:
+ logging.warning("Web verification failed: rolling back")
+ logging.info("Web page that was output was:\n\n%s" % e.contents)
+ perform_restore(d, backup)
+ raise app.UpgradeVerificationFailure("Upgrade caused website to become inaccessible; site was rolled back")
+ # XXX: frob .htaccess to make site accessible
+ # to do this, check if .htaccess changed, first. Upgrade
+ # process might have frobbed it. Don't be
+ # particularly worried if the segment disappeared