]> scripts.mit.edu Git - wizard.git/commitdiff
Allow migration of non old-scripts autoinstalls.
authorEdward Z. Yang <ezyang@mit.edu>
Fri, 17 Sep 2010 18:46:27 +0000 (14:46 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Fri, 17 Sep 2010 18:46:27 +0000 (14:46 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/command/migrate.py
wizard/deploy.py

index 83b3d1e4780ae21df052c750850874b9ef5f036f..d3dce85ef3f10b0e82620b24dea53fca3c6322be 100644 (file)
@@ -3,10 +3,7 @@ import os.path
 import shutil
 import logging
 
-from wizard import command, deploy, shell, util
-
-# LEGACY (but still necessary, since we haven't migrated all of scripts
-# yet.  Maybe if we plugin-ify the commands interface move this.)
+from wizard import app, command, deploy, shell, util
 
 def main(argv, baton):
     options, args = parse_args(argv, baton)
@@ -26,29 +23,39 @@ def main(argv, baton):
     try:
         deployment.verify()
         raise AlreadyMigratedError(deployment.location)
+    except deploy.NotAutoinstallError:
+        # Previously, this was a fatal error, but now let's try
+        # a little harder.
+        # XXX: The user still has to tell us what application ; a more
+        # user friendly thing to do is figure it out automatically
+        if not options.force_app:
+            raise
+        # actual version number will get overwritten shortly
+        deployment.setAppVersion(app.ApplicationVersion.make(options.force_app, "unknown"))
     except deploy.NotMigratedError:
+        # LEGACY
         pass
     except (deploy.CorruptedAutoinstallError, AlreadyMigratedError):
         if not options.force:
             raise
 
-    deployment.verifyTag(options.srv_path)
-
     if options.force_version:
-        version = deployment.application.makeVersion(options.force_version)
+        deployment.setAppVersion(deployment.application.makeVersion(options.force_version))
     else:
         try:
             deployment.verifyVersion()
-            version = deployment.app_version
         except deploy.VersionMismatchError as e:
             # well, we'll use that then
-            version = deployment.application.makeVersion(str(e.real_version))
-    repo = version.application.repository(options.srv_path)
-    tag = version.wizard_tag
+            deployment.setAppVersion(deployment.application.makeVersion(str(e.real_version)))
+
+    deployment.verifyTag(options.srv_path)
+
+    repo = deployment.application.repository(options.srv_path)
+    tag = deployment.app_version.wizard_tag
     try:
         sh.call("git", "--git-dir=%s" % repo, "rev-parse", tag)
     except shell.CallError:
-        raise UnsupportedVersion(version.version)
+        raise UnsupportedVersion(deployment.version)
 
     with util.LockDirectory(".wizard-migrate-lock"):
         try:
@@ -77,11 +84,14 @@ upgrading .  Do NOT run this command as root."""
     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 .wizard directory already exists,"
+            default=False, help="If .git or .wizard directory already exists, "
             "delete them and migrate")
     parser.add_option("--force-version", dest="force_version",
-            default=None, help="If .scripts-version tells lies, explicitly specify"
+            default=None, help="If .scripts-version is corrupted or non-existent, explicitly specify "
             "a version to migrate to.")
+    parser.add_option("--force-app", dest="force_app",
+            default=None, help="If .scripts-version is corrupted or non-existent, explicitly specify "
+            "an application to migrate to.")
     options, args = parser.parse_all(argv)
     if len(args) > 1:
         parser.error("too many arguments")
index 158ad4033eaf16095e4d1969b0d537bf3234bf13..12a27818cff1b4b4e235cd7830863b9ab048ae10 100644 (file)
@@ -161,6 +161,13 @@ class Deployment(object):
         self._app_version = None
         self._read_cache = {}
         self._old_log = None
+    def setAppVersion(self, app_version):
+        """
+        Manually resets the application version; useful if the working
+        copy is off in space (i.e. not anchored to something we can
+        git describe off of) or there is no metadata to be heard of.
+        """
+        self._app_version = app_version
     def read(self, file, force = False):
         """
         Reads a file's contents, possibly from cache unless ``force``
@@ -507,13 +514,6 @@ class WorkingCopy(Deployment):
     modifications to without fear of interfering with a production
     deployment.  More operations are permitted on these copies.
     """
-    def setAppVersion(self, app_version):
-        """
-        Manually resets the application version; useful if the working
-        copy is off in space (i.e. not anchored to something we can
-        git describe off of.)
-        """
-        self._app_version = app_version
     @chdir_to_location
     def parametrize(self, deployment):
         """