]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/command/massmigrate.py
Document wizard.shell, and fix bug in massmigrate.
[wizard.git] / wizard / command / massmigrate.py
index 40580198966410714c5d9a27f8e2e5c852d5b47d..ff1ded28f34cc5d8e6f088140013efc1e436a9fc 100644 (file)
@@ -2,17 +2,14 @@ import optparse
 import logging
 import os
 import os.path
 import logging
 import os
 import os.path
+import pwd
 
 import wizard
 
 import wizard
-from wizard import deploy
-from wizard import util
-from wizard import shell
-from wizard import sset
-from wizard.command import _base
+from wizard import deploy, util, shell, sset, command
 from wizard.command import migrate
 
 from wizard.command import migrate
 
-def main(argv, global_options):
-    options, args = parse_args(argv)
+def main(argv, baton):
+    options, args = parse_args(argv, baton)
     app = args[0]
     base_args = calculate_base_args(options)
     sh = make_shell(options)
     app = args[0]
     base_args = calculate_base_args(options)
     sh = make_shell(options)
@@ -21,19 +18,19 @@ def main(argv, global_options):
     # loop stuff
     errors = {}
     uid = None
     # loop stuff
     errors = {}
     uid = None
-    for line in deploy.getInstallLines(global_options):
+    for line in deploy.get_install_lines(options.versions_path):
         # validate and filter the deployments
         try:
             d = deploy.Deployment.parse(line)
         except deploy.DeploymentParseError, deploy.NoSuchApplication:
             continue
         # validate and filter the deployments
         try:
             d = deploy.Deployment.parse(line)
         except deploy.DeploymentParseError, deploy.NoSuchApplication:
             continue
-        name = d.getApplication().name
+        name = d.application.name
         if name != app: continue
         if d.location in seen:
             continue
         # security check: see if the user's directory is the prefix of what
         if not my_uid:
         if name != app: continue
         if d.location in seen:
             continue
         # security check: see if the user's directory is the prefix of what
         if not my_uid:
-            uid = get_dir_uid(d.location)
+            uid = util.get_dir_uid(d.location)
             real = os.path.realpath(d.location)
             if not real.startswith(pwd.getpwuid(uid).pw_dir + "/"):
                 logging.error("Security check failed, owner of deployment and owner of home directory mismatch for %s" % d.location)
             real = os.path.realpath(d.location)
             if not real.startswith(pwd.getpwuid(uid).pw_dir + "/"):
                 logging.error("Security check failed, owner of deployment and owner of home directory mismatch for %s" % d.location)
@@ -54,13 +51,13 @@ def main(argv, global_options):
             return (on_success, on_error)
         on_success, on_error = make_on_pair(d)
         sh.wait() # wait for a parallel processing slot to be available
             return (on_success, on_error)
         on_success, on_error = make_on_pair(d)
         sh.wait() # wait for a parallel processing slot to be available
-        sh.callAsUser(shell.wizard, "migrate", d.location, *base_args,
+        sh.callAsUser(shell.wizard_bin, "migrate", d.location, *base_args,
                       uid=uid, on_success=on_success, on_error=on_error)
     sh.join()
     for name, deploys in errors.items():
         logging.warning("%s from %d installs" % (name, len(deploys)))
 
                       uid=uid, on_success=on_success, on_error=on_error)
     sh.join()
     for name, deploys in errors.items():
         logging.warning("%s from %d installs" % (name, len(deploys)))
 
-def parse_args(argv):
+def parse_args(argv, baton):
     usage = """usage: %prog massmigrate [ARGS] APPLICATION
 
 Mass migrates an application to the new repository format.
     usage = """usage: %prog massmigrate [ARGS] APPLICATION
 
 Mass migrates an application to the new repository format.
@@ -75,9 +72,8 @@ stat every install to find out if it migrated it yet).
 This command is intended to be run as root on a server with
 the scripts AFS patch.  You may run it as an unpriviledged
 user for testing purposes, but then you MUST NOT run this on
 This command is intended to be run as root on a server with
 the scripts AFS patch.  You may run it as an unpriviledged
 user for testing purposes, but then you MUST NOT run this on
-untrusted repositories.
-"""
-    parser = _base.WizardOptionParser(usage)
+untrusted repositories."""
+    parser = command.WizardOptionParser(usage)
     parser.add_option("--no-parallelize", dest="no_parallelize", action="store_true",
             default=False, help="Turn off parallelization")
     parser.add_option("--dry-run", dest="dry_run", action="store_true",
     parser.add_option("--no-parallelize", dest="no_parallelize", action="store_true",
             default=False, help="Turn off parallelization")
     parser.add_option("--dry-run", dest="dry_run", action="store_true",
@@ -86,6 +82,7 @@ untrusted repositories.
             default=10, help="Maximum subprocesses to run concurrently")
     parser.add_option("--seen", dest="seen",
             default=None, help="File to read/write paths of already processed installs. These will be skipped.")
             default=10, help="Maximum subprocesses to run concurrently")
     parser.add_option("--seen", dest="seen",
             default=None, help="File to read/write paths of already processed installs. These will be skipped.")
+    baton.push(parser, "versions_path")
     options, args, = parser.parse_all(argv)
     if len(args) > 1:
         parser.error("too many arguments")
     options, args, = parser.parse_all(argv)
     if len(args) > 1:
         parser.error("too many arguments")
@@ -96,7 +93,7 @@ untrusted repositories.
     return options, args
 
 def calculate_base_args(options):
     return options, args
 
 def calculate_base_args(options):
-    base_args = _base.makeBaseArgs(options, dry_run="--dry-run")
+    base_args = command.makeBaseArgs(options, dry_run="--dry-run")
     if not options.debug:
         base_args.append("--quiet")
     return base_args
     if not options.debug:
         base_args.append("--quiet")
     return base_args