5 import logging.handlers
9 from wizard import deploy
10 from wizard import shell
11 from wizard import util
12 from wizard.command import _base
14 # XXX: WARNING EXPERIMENTAL DANGER DANGER WILL ROBINSON
16 # need errors for checking DAG integrity (if the user is on a completely
17 # different history tree, stuff is problems)
19 # we need an option that specifies the person making the update. Since n-b
20 # doesn't actually have a way to do this, username is probably what we want.
21 def main(argv, global_options):
22 options, args = parse_args(argv)
25 if not os.path.isdir(".git"):
26 raise NotAutoinstallError()
28 d = deploy.Deployment.fromDir(".")
30 if e.errno == errno.ENOENT:
31 raise NotAutoinstallError()
33 repo = d.getApplication().getRepository()
34 # begin the command line process
35 sh = shell.Shell(options.dry_run)
38 # commit their changes
39 message = "Pre-commit of %s locker before autoinstall upgrade.\n\n%s" % (util.get_dir_owner(), util.get_git_footer())
41 message += "\nPre-commit-by: " + util.get_operator_git()
42 except util.NoOperatorInfo:
45 sh.call("git", "commit", "-a", "-m", "Pre-upgrade commit.")
46 except shell.CallError:
47 logging.info("No changes detected")
49 # perform fetch to update repository state
50 sh.call("git", "fetch", repo)
51 # clone their website to a temporary directory
52 temp_dir = tempfile.mkdtemp()
53 temp_wc_dir = os.path.join(temp_dir, "repo")
54 logging.info("Using temporary directory: " + temp_wc_dir)
55 sh.call("git", "clone", "--shared", ".", temp_wc_dir)
56 with util.ChangeDirectory(temp_wc_dir):
57 # reconfigure the repository path
58 sh.call("git", "remote", "add", "scripts", repo)
59 sh.call("git", "fetch", "scripts")
61 version, _ = sh.call(["git", "--git-dir="+repo, "describe", "--tags", "master"])
63 message = "Upgraded autoinstall in %s to %s.\n\n%s" % (util.get_dir_owner(), version, util.get_git_footer())
65 message += "\nUpgraded-by: " + util.get_operator_git()
66 except util.NoOperatorInfo:
68 sh.call("git", "merge", "-m", message, "scripts/master")
69 except shell.CallError:
71 # XXX: frob .htaccess to make site inaccessible
72 # git merge (which performs a fast forward)
73 # - merge could fail (race)
74 sh.call("git", "pull", temp_wc_dir, "master")
76 sh.call(".scripts/update")
77 # XXX: frob .htaccess to make site accessible
78 # XXX: - check if .htaccess changed, first. Upgrade
79 # process might have frobbed it. Don't be
80 # particularly worried if the segment dissappeared
83 usage = """usage: %prog upgrade [ARGS] DIR
85 Upgrades an autoinstall ot the latest version. This involves
86 updating files and running .scripts/update.
88 WARNING: This is still experimental."""
89 parser = _base.WizardOptionParser(usage)
90 parser.add_option("--dry-run", dest="dry_run", action="store_true",
91 default=False, help="Prints would would be run without changing anything")
92 options, args = parser.parse_all(argv)
94 parser.error("too many arguments")
96 parser.error("must specify directory")
99 class Error(_base.Error):
100 """Base exception for all exceptions raised by upgrade"""
103 class NotAutoinstallError(Error):
107 ERROR: Could not find .git file. Are you sure
108 this is an autoinstalled application? Did you remember
112 class MergeFailed(Error):