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