6 import wizard.deploy as wd
7 import wizard.shell as sh
9 def main(argv, global_options):
10 usage = """usage: %prog migrate [ARGS] DIR
12 Migrates a directory to our Git-based autoinstall format.
13 Performs basic sanity checking and intelligently determines
14 what repository and tag to use."""
15 parser = optparse.OptionParser(usage)
16 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
17 default=False, help="Print all commands and outputs")
18 parser.add_option("--dry-run", dest="dry_run", action="store_true",
19 default=False, help="Prints would would be run without changing anything")
20 options, args = parser.parse_args(argv)
22 parser.error("too many arguments")
24 parser.error("must specify directory")
26 print "Changing working directory to autoinstall directory"
32 print "ERROR: You don't have permissions to access this directory."
33 print "Do you have tickets for AFS with your root instance, and"
34 print "is your root instance on scripts-security-upd?"
36 print "You can check by running the commands 'klist' and"
37 print "'blanche scripts-security-upd'. We recommend getting"
38 print "root tickets using Nelson Elhage's krbroot script"
39 print "at /mit/nelhage/Public/krbroot (for which you run"
40 print "'krbroot shell' and then 'aklog')."
44 print "ERROR: No such directory... check your typing"
48 deploy = wd.Deployment.fromDir(".")
49 version = deploy.getAppVersion()
53 print "ERROR: Could not find .scripts-version file. Are you sure"
54 print "this is an autoinstalled application?"
57 # calculate the repository we'll be pulling out of
58 application = version.application
59 app = application.name
60 repo = os.path.join("/afs/athena.mit.edu/contrib/scripts/wizard/srv", app + ".git")
61 if not os.path.isdir(repo):
63 print "ERROR: Could not find repository for this application. Have"
64 print "you converted the repository over? Is the name %s" % app
65 print "the same as the the name of the foo.git folder?"
67 # begin the command line process
68 shell = sh.Shell(options.verbose, options.dry_run)
69 # check if the version we're trying to convert exists. We assume
70 # a convention here, namely, v1.2.3-scripts is what we want. If
71 # you broke the convention... shame on you.
73 tag = "v%s-scripts" % version.version
74 shell.call("git", "--git-dir", repo, "rev-parse", tag)
75 except sh.CalledProcessError:
77 print "ERROR: Could not find tag v%s-scripts for" % version.version
78 print "this application's version. Double check and make sure"
79 print "the repository was prepared with all necessary tags!"
82 did_git_checkout_scripts = False
85 shell.call("git", "init")
87 # configure our remote
88 shell.call("git", "remote", "add", "origin", repo)
89 # configure what would normally be set up on a 'git clone' for consistency
90 shell.call("git", "config", "branch.master.remote", "origin")
91 shell.call("git", "config", "branch.master.merge", "refs/heads/master")
92 # perform the initial fetch
93 shell.call("git", "fetch", "origin")
94 # soft reset to our tag
95 shell.call("git", "reset", tag)
96 # checkout the .scripts directory
97 shell.call("git", "checkout", ".scripts")
98 did_git_checkout_scripts = True
99 # XXX: setup .scripts/version???
100 # for verbose purposes, give us a git status and git diff
102 shell.call("git", "status")
103 shell.call("git", "diff")
106 print "ERROR: Exception detected! Rolling back..."
108 print "Deleting .git directory"
109 shell.call("rm", "-Rf", ".git")
110 if did_git_checkout_scripts:
111 print "Deleting .scripts directory"
112 shell.call("rm", "-Rf", ".scripts")