12 from wizard import deploy, util, shell, sset, command
14 def main(argv, baton):
15 options, args = parse_args(argv, baton)
17 base_args = calculate_base_args(options)
18 sh = shell.ParallelShell.make(options.no_parallelize, options.max_processes)
19 seen = sset.make(options.seen)
20 is_root = not os.getuid()
21 warnings_log, errors_log = command.open_logs(options.log_dir)
25 deploys = deploy.parse_install_lines(app, options.versions_path)
26 requested_deploys = itertools.islice(deploys, options.limit)
27 for i, d in enumerate(requested_deploys, 1):
28 # check if we want to punt due to --limit
29 if d.location in seen:
31 if is_root and not command.security_check_homedir(d):
33 logging.info("Processing %s" % d.location)
34 child_args = list(base_args)
35 # calculate the log file, if a log dir was specified
37 log_file = command.calculate_log_name(options.log_dir, i, d.location)
38 child_args.append("--log-file=" + log_file)
40 def make_on_pair(d, i):
41 # we need to make another stack frame so that d and i get specific bindings.
42 def on_success(stdout, stderr):
44 warnings_log.write("%s\n" % d.location)
45 logging.warning("Warnings [%04d] %s:\n%s" % (i, d.location, stderr))
48 if e.name == "wizard.command.migrate.AlreadyMigratedError" or \
49 e.name == "AlreadyMigratedError":
51 logging.info("Skipped already migrated %s" % d.location)
54 if name not in errors: errors[name] = []
55 errors[name].append(d)
56 logging.error("%s in [%04d] %s" % (name, i, d.location))
57 errors_log.write("%s\n" % d.location)
58 return (on_success, on_error)
59 on_success, on_error = make_on_pair(d, i)
60 sh.call("wizard", "migrate", d.location, *child_args,
61 on_success=on_success, on_error=on_error)
63 for name, deploys in errors.items():
64 logging.warning("%s from %d installs" % (name, len(deploys)))
66 def parse_args(argv, baton):
67 usage = """usage: %prog mass-migrate [ARGS] APPLICATION
69 Mass migrates an application to the new repository format.
70 Essentially equivalent to running '%prog migrate' on all
71 autoinstalls for a particular application found by parallel-find,
72 but with advanced reporting.
74 This command is intended to be run as root on a server with
75 the scripts AFS patch."""
76 parser = command.WizardOptionParser(usage)
77 baton.push(parser, "log_dir")
78 baton.push(parser, "seen")
79 baton.push(parser, "no_parallelize")
80 baton.push(parser, "dry_run")
81 baton.push(parser, "max_processes")
82 parser.add_option("--force", dest="force", action="store_true",
83 default=False, help="Force migrations to occur even if .scripts or .git exists.")
84 baton.push(parser ,"limit")
85 baton.push(parser, "versions_path")
86 baton.push(parser, "srv_path")
87 options, args, = parser.parse_all(argv)
89 parser.error("too many arguments")
91 parser.error("must specify application to migrate")
94 def calculate_base_args(options):
95 return command.makeBaseArgs(options, dry_run="--dry-run", srv_path="--srv-path",