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 command.create_logdir(options.log_dir)
20 seen = sset.make(options.seen)
21 is_root = not os.getuid()
22 report = command.open_reports(options.log_dir)
26 deploys = deploy.parse_install_lines(app, options.versions_path)
27 requested_deploys = itertools.islice(deploys, options.limit)
28 for i, d in enumerate(requested_deploys, 1):
29 # check if we want to punt due to --limit
30 if d.location in seen:
32 if is_root and not command.security_check_homedir(d):
34 logging.info("Processing %s" % d.location)
35 child_args = list(base_args)
36 # calculate the log file, if a log dir was specified
38 log_file = command.calculate_log_name(options.log_dir, i)
39 child_args.append("--log-file=" + log_file)
41 def make_on_pair(d, i):
42 # we need to make another stack frame so that d and i get specific bindings.
43 def on_success(stdout, stderr):
45 report.warnings.write("%s\n" % d.location) # pylint: disable-msg=E1101
46 logging.warning("Warnings [%04d] %s:\n%s" % (i, d.location, stderr))
49 if e.name == "wizard.command.migrate.AlreadyMigratedError" or \
50 e.name == "AlreadyMigratedError":
52 logging.info("Skipped already migrated %s" % d.location)
55 if name not in errors: errors[name] = []
56 errors[name].append(d)
57 logging.error("%s in [%04d] %s" % (name, i, d.location))
58 report.errors.write("%s\n" % d.location) # pylint: disable-msg=E1101
59 return (on_success, on_error)
60 on_success, on_error = make_on_pair(d, i)
61 sh.call("wizard", "migrate", d.location, *child_args,
62 on_success=on_success, on_error=on_error)
64 for name, deploys in errors.items():
65 logging.warning("%s from %d installs" % (name, len(deploys)))
67 def parse_args(argv, baton):
68 usage = """usage: %prog mass-migrate [ARGS] APPLICATION
70 Mass migrates an application to the new repository format.
71 Essentially equivalent to running '%prog migrate' on all
72 autoinstalls for a particular application found by parallel-find,
73 but with advanced reporting.
75 This command is intended to be run as root on a server with
76 the scripts AFS patch."""
77 parser = command.WizardOptionParser(usage)
78 baton.push(parser, "log_dir")
79 baton.push(parser, "seen")
80 baton.push(parser, "no_parallelize")
81 baton.push(parser, "dry_run")
82 baton.push(parser, "max_processes")
83 parser.add_option("--force", dest="force", action="store_true",
84 default=False, help="Force migrations to occur even if .scripts or .git exists.")
85 baton.push(parser ,"limit")
86 baton.push(parser, "versions_path")
87 baton.push(parser, "srv_path")
88 options, args, = parser.parse_all(argv)
90 parser.error("too many arguments")
92 parser.error("must specify application to migrate")
95 def calculate_base_args(options):
96 return command.make_base_args(options, dry_run="--dry-run", srv_path="--srv-path",