]> scripts.mit.edu Git - wizard.git/blobdiff - lib/wizard/command/migrate.py
Remove misleading docs.
[wizard.git] / lib / wizard / command / migrate.py
index f626322e21db7971346ea2ae468c98ad4e5326e4..e7ced10ec998176a6117ad6eada6635b99ce5b88 100644 (file)
@@ -1,16 +1,17 @@
 import optparse
 import sys
+import os
+import shutil
 
 import wizard.deploy as wd
+import wizard.shell as sh
 
 def main(argv, global_options):
     usage = """usage: %prog migrate [ARGS] DIR
 
 Migrates a directory to our Git-based autoinstall format.
 Performs basic sanity checking and intelligently determines
-what repository and tag to use.
-
-NOTICE: Currently doesn't do anything."""
+what repository and tag to use."""
     parser = optparse.OptionParser(usage)
     parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
             default=False, help="Print all commands and outputs")
@@ -22,5 +23,90 @@ NOTICE: Currently doesn't do anything."""
     elif not args:
         parser.error("must specify directory")
     dir = args[0]
-    print dir
-    print options
+    print "Changing working directory to autoinstall directory"
+    try:
+        os.chdir(dir)
+    except OSError as e:
+        if e.errno == 13:
+            print
+            print "ERROR: You don't have permissions to access this directory."
+            print "Do you have tickets for AFS with your root instance, and"
+            print "is your root instance on scripts-security-upd?"
+            print
+            print "You can check by running the commands 'klist' and"
+            print "'blanche scripts-security-upd'.  We recommend getting"
+            print "root tickets using Nelson Elhage's krbroot script"
+            print "at /mit/nelhage/Public/krbroot (for which you run"
+            print "'krbroot shell' and then 'aklog')."
+            raise SystemExit(-1)
+        elif e.errno == 2:
+            print
+            print "ERROR: No such directory... check your typing"
+            raise SystemExit(-1)
+        else: raise e
+    try:
+        deploy = wd.Deployment.fromDir(".")
+        version = deploy.getAppVersion()
+    except IOError as e:
+        if e.errno == 2:
+            print
+            print "ERROR: Could not find .scripts-version file.  Are you sure"
+            print "this is an autoinstalled application?"
+            raise SystemExit(-1)
+        else: raise e
+    # calculate the repository we'll be pulling out of
+    application = version.application
+    app = application.name
+    repo = os.path.join("/afs/athena.mit.edu/contrib/scripts/wizard/srv", app + ".git")
+    if not os.path.isdir(repo):
+        print
+        print "ERROR: Could not find repository for this application. Have"
+        print "you converted the repository over? Is the name %s" % app
+        print "the same as the the name of the foo.git folder?"
+        raise SystemExit(-1)
+    # begin the command line process
+    shell = sh.Shell(options.verbose, options.dry_run)
+    # check if the version we're trying to convert exists. We assume
+    # a convention here, namely, v1.2.3-scripts is what we want. If
+    # you broke the convention... shame on you.
+    try:
+        tag = "v%s-scripts" % version.version
+        shell.call("git", "--git-dir", repo, "rev-parse", tag)
+    except sh.CalledProcessError:
+        print
+        print "ERROR: Could not find tag v%s-scripts for" % version.version
+        print "this application's version.  Double check and make sure"
+        print "the repository was prepared with all necessary tags!"
+        raise SystemExit(-1)
+    did_git_init = False
+    did_git_checkout_scripts = False
+    try:
+        # create repository
+        shell.call("git", "init")
+        did_git_init = True
+        # configure our remote
+        shell.call("git", "remote", "add", "origin", repo)
+        # configure what would normally be set up on a 'git clone' for consistency
+        shell.call("git", "config", "branch.master.remote", "origin")
+        shell.call("git", "config", "branch.master.merge", "refs/heads/master")
+        # perform the initial fetch
+        shell.call("git", "fetch", "origin")
+        # soft reset to our tag
+        shell.call("git", "reset", tag)
+        # checkout the .scripts directory
+        shell.call("git", "checkout", ".scripts")
+        did_git_checkout_scripts = True
+        # XXX: setup .scripts/version???
+        # for verbose purposes, give us a git status and git diff
+        shell.call("git", "status")
+        shell.call("git", "diff")
+    except:
+        print
+        print "ERROR: Exception detected! Rolling back..."
+        if did_git_init:
+            print "Deleting .git directory"
+            shell.call("rm", "-Rf", ".git")
+        if did_git_checkout_scripts:
+            print "Deleting .scripts directory"
+            shell.call("rm", "-Rf", ".scripts")
+        raise