]> scripts.mit.edu Git - wizard.git/commitdiff
Final touches on migration script.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Wed, 17 Jun 2009 04:46:37 +0000 (00:46 -0400)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Wed, 17 Jun 2009 04:46:37 +0000 (00:46 -0400)
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
lib/wizard/command/migrate.py

index dbf93d32c2d81e9678b116b8d96618cd087c9cdc..dc5f5aa265971850dc608d04913a8773e2009ee3 100644 (file)
@@ -85,6 +85,8 @@ what repository and tag to use."""
     parser = WizardOptionParser(usage)
     parser.add_option("--dry-run", dest="dry_run", action="store_true",
             default=False, help="Prints would would be run without changing anything")
+    parser.add_option("--force", "-f", dest="force", action="store_true",
+            default=False, help="If .git or .scripts directory already exists, delete them and migrate")
     options, args, logger = parser.parse_all(argv, logger)
     if len(args) > 1:
         parser.error("too many arguments")
@@ -99,8 +101,16 @@ what repository and tag to use."""
         elif e.errno == 2:
             raise NoSuchDirectoryError(dir)
         else: raise e
-    if os.path.isdir(".git"):
-        raise AlreadyMigratedError(dir)
+    if os.path.isdir(".git") or os.path.isdir(".scripts"):
+        if not options.force:
+            raise AlreadyMigratedError(dir)
+        else:
+            if os.path.isdir(".git"):
+                logger.warning("Force removing .git directory")
+                shutil.rmtree(".git")
+            if os.path.isdir(".scripts"):
+                logger.warning("Force removing .scripts directory")
+                shutil.rmtree(".scripts")
     try:
         deploy = wd.Deployment.fromDir(".")
         version = deploy.getAppVersion()
@@ -144,12 +154,12 @@ what repository and tag to use."""
         did_git_checkout_scripts = True
         # XXX: setup .scripts/version???
         # for verbose purposes, give us a git status and git diff
-        raise NotImplementedError
         if options.verbose:
             shell.call("git", "status")
             shell.call("git", "diff")
     except:
-        logger.error("ERROR: Exception detected! Rolling back...")
+        # this... is pretty bad
+        logger.critical("ERROR: Exception detected! Rolling back...")
         if did_git_init:
             shell.call("rm", "-Rf", ".git")
         if did_git_checkout_scripts: