+ util.set_git_env()
+ use_shm = False # if you are running --continue, this is guaranteed to be False
+ temp_dir = None
+ try: # global try-finally for cleaning up /dev/shm if it's being used
+ if options.continue_:
+ temp_wc_dir = os.getcwd()
+ wc = deploy.WorkingCopy(".")
+ 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()
+ if not options.log_file and os.path.exists(".git/WIZARD_LOG_FILE"):
+ options.log_file = open(".git/WIZARD_LOG_FILE", "r").read()
+ # reload logging
+ command.setup_file_logger(options.log_file, options.debug)
+ logging.info("Continuing upgrade...")
+ util.chdir(sh.eval("git", "config", "remote.origin.url"))
+ d = deploy.ProductionCopy(".")
+ try:
+ sh.call("git", "status")
+ raise LocalChangesError()
+ except shell.CallError:
+ pass
+ else:
+ d = deploy.ProductionCopy(".")
+ if os.path.exists(".scripts/blacklisted"):
+ reason = open(".scripts/blacklisted").read()
+ # ignore blank blacklisted files
+ if reason:
+ print reason
+ raise BlacklistedError(reason)
+ else:
+ logging.warning("Application was blacklisted, but no reason was found");
+ 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:
+ # don't log this error
+ # XXX: maybe we should build this in as a flag to add
+ # to exceptions w/ our exception handler
+ sys.stderr.write("Traceback:\n (n/a)\nAlreadyUpgraded\n")
+ sys.exit(1)
+ logging.info("Upgrading %s" % os.getcwd())
+ kib_usage, kib_limit = scripts.get_quota_usage_and_limit()
+ if kib_limit is not None and (kib_limit - kib_usage) < kib_buffer:
+ raise QuotaTooLow
+ if not options.dry_run:
+ perform_pre_commit(sh)
+ # If /dev/shm exists, it's a tmpfs and we can use it
+ # to do a fast git merge. Don't forget to move it to
+ # /tmp if it fails.
+ if not options.dry_run:
+ use_shm = os.path.exists("/dev/shm")
+ temp_dir, temp_wc_dir = perform_tmp_clone(sh, use_shm)
+ with util.ChangeDirectory(temp_wc_dir):
+ wc = deploy.WorkingCopy(".")
+ 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))
+ open(".git/WIZARD_SIZE", "w").write(str(scripts.get_disk_usage()))
+ if options.log_file:
+ open(".git/WIZARD_LOG_FILE", "w").write(options.log_file)
+ perform_merge(sh, repo, d, wc, version, use_shm, kib_limit and kib_limit - kib_usage or None)
+ # 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)
+ # This is a quick sanity check to make sure we didn't completely
+ # mess up the merge
+ wc.invalidateCache()
+ wc.verifyVersion()
+ # Till now, all of our operations were in a tmp sandbox.