]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/command/migrate.py
Move a bunch of summary items to full class commands.
[wizard.git] / wizard / command / migrate.py
index b1459e33b6e0fcff7faaaf3306bc10cd988681d6..d5ae90ef862927d1f338cb4161a2257b361f158c 100644 (file)
@@ -4,10 +4,7 @@ import logging
 import errno
 import sys
 
-from wizard import deploy
-from wizard import shell
-from wizard import util
-from wizard.command import _command
+from wizard import command, deploy, shell, util
 
 def main(argv, baton):
     options, args = parse_args(argv)
@@ -15,10 +12,11 @@ def main(argv, baton):
 
     logging.debug("uid is %d" % os.getuid())
 
-    _command.chdir(dir)
+    command.chdir(dir)
     check_if_already_migrated(options)
 
-    version = calculate_version()
+    deployment = make_deployment() # uses chdir
+    version = deployment.app_version
     repo    = version.application.repository
     tag     = version.scripts_tag
 
@@ -27,8 +25,14 @@ def main(argv, baton):
     sh = shell.Shell(options.dry_run)
     check_if_tag_exists(sh, repo, tag)
     make_repository(sh, options, repo, tag)
+    make_variables(deployment, options)
 
-    os.rename(".scripts-version", ".scripts/old-version") # archive
+    if not options.dry_run:
+        deployment.updateVersion()
+        os.rename(".scripts-version", ".scripts/old-version") # archive
+    else:
+        logging.info("# create .scripts/version containing \"%s-%s\"" % (deployment.application.name, deployment.version))
+        logging.info("mv .scripts-version .scripts/old-version")
 
 def parse_args(argv):
     usage = """usage: %prog migrate [ARGS] DIR
@@ -40,7 +44,7 @@ what repository and tag to use.
 This command is meant to be run as the owner of the install
 it is upgrading (see the scripts AFS kernel patch).  Do
 NOT run this command as root."""
-    parser = _command.WizardOptionParser(usage)
+    parser = command.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",
@@ -64,10 +68,9 @@ def check_if_already_migrated(options):
                 logging.warning("Force removing .scripts directory")
                 if not options.dry_run: shutil.rmtree(".scripts")
 
-def calculate_version():
+def make_deployment():
     try:
-        d = deploy.Deployment.fromDir(".")
-        return d.app_version
+        return deploy.Deployment(".")
     except IOError as e:
         if e.errno == errno.ENOENT:
             raise NotAutoinstallError(dir)
@@ -128,7 +131,25 @@ def make_repository(sh, options, repo, tag):
         except shell.CallError:
             pass
 
-class Error(_command.Error):
+def make_variables(d, options):
+    """Make .scripts/variables which contains variables based off of
+    what was regexed out of existing configuration files."""
+    variables = d.extract()
+    if not options.dry_run: f = open(".scripts/variables", "w")
+    for k,v in variables.items():
+        if v is None:
+            # once we get everything on the same version, you should
+            # actually start paying attention to these warnings
+            logging.warning("Variable %s not found" % k)
+        else:
+            logging.debug("Variable %s is %s" % (k,v))
+            if not options.dry_run:
+                f.write("%s %s\n" % (k,v))
+            else:
+                logging.info('# write line "%s %s" to .scripts/variables' % (k,v))
+    if not options.dry_run: f.close()
+
+class Error(command.Error):
     """Base exception for all exceptions raised by migrate"""
     pass