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.
16 NOTICE: Currently doesn't do anything."""
17 parser = optparse.OptionParser(usage)
18 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
19 default=False, help="Print all commands and outputs")
20 parser.add_option("--dry-run", dest="dry_run", action="store_true",
21 default=False, help="Prints would would be run without changing anything")
22 options, args = parser.parse_args(argv)
24 parser.error("too many arguments")
26 parser.error("must specify directory")
28 print "Changing working directory to autoinstall directory"
34 print "ERROR: You don't have permissions to access this directory."
35 print "Do you have tickets for AFS with your root instance, and"
36 print "is your root instance on scripts-security-upd?"
38 print "You can check by running the commands 'klist' and"
39 print "'blanche scripts-security-upd'. We recommend getting"
40 print "root tickets using Nelson Elhage's krbroot script"
41 print "at /mit/nelhage/Public/krbroot (for which you run"
42 print "'krbroot shell' and then 'aklog')."
46 print "ERROR: No such directory... check your typing"
50 deploy = wd.Deployment.fromDir(".")
51 version = deploy.getAppVersion()
55 print "ERROR: Could not find .scripts-version file. Are you sure"
56 print "this is an autoinstalled application?"
59 # calculate the repository we'll be pulling out of
60 application = version.application
61 app = application.name
62 repo = os.path.join("/afs/athena.mit.edu/contrib/scripts/wizard/srv", app + ".git")
63 if not os.path.isdir(repo):
65 print "ERROR: Could not find repository for this application. Have"
66 print "you converted the repository over? Is the name %s" % app
67 print "the same as the the name of the foo.git folder?"
69 # begin the command line process
70 shell = sh.Shell(options.verbose, options.dry_run)
71 # check if the version we're trying to convert exists. We assume
72 # a convention here, namely, v1.2.3-scripts is what we want. If
73 # you broke the convention... shame on you.
75 tag = "v%s-scripts" % version.version
76 shell.call("git", "--git-dir", repo, "rev-parse", tag)
77 except sh.CalledProcessError:
79 print "ERROR: Could not find tag v%s-scripts for" % version.version
80 print "this application's version. Double check and make sure"
81 print "the repository was prepared with all necessary tags!"
84 did_git_checkout_scripts = False
87 shell.call("git", "init")
89 # configure our remote
90 shell.call("git", "remote", "add", "origin", repo)
91 # configure what would normally be set up on a 'git clone' for consistency
92 shell.call("git", "config", "branch.master.remote", "origin")
93 shell.call("git", "config", "branch.master.merge", "refs/heads/master")
94 # perform the initial fetch
95 shell.call("git", "fetch", "origin")
96 # soft reset to our tag
97 shell.call("git", "reset", tag)
98 # checkout the .scripts directory
99 shell.call("git", "checkout", ".scripts")
100 did_git_checkout_scripts = True
101 # XXX: setup .scripts/version???
102 # for verbose purposes, give us a git status and git diff
103 shell.call("git", "status")
104 shell.call("git", "diff")
107 print "ERROR: Exception detected! Rolling back..."
109 print "Deleting .git directory"
110 shell.call("rm", "-Rf", ".git")
111 if did_git_checkout_scripts:
112 print "Deleting .scripts directory"
113 shell.call("rm", "-Rf", ".scripts")