6 from wizard import deploy, 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 report = command.open_reports(options.log_dir)
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 report.warnings.write("%s\n" % d.location) # pylint: disable-msg=E1101
40 logging.warning("Warnings [%04d] %s:\n%s" % (i, d.location, stderr))
43 if e.name == "wizard.command.migrate.AlreadyMigratedError" or \
44 e.name == "AlreadyMigratedError":
46 logging.info("Skipped already migrated %s" % d.location)
49 if name not in errors: errors[name] = []
50 errors[name].append(d)
51 logging.error("%s in [%04d] %s" % (name, i, d.location))
52 report.errors.write("%s\n" % d.location) # pylint: disable-msg=E1101
53 return (on_success, on_error)
54 on_success, on_error = make_on_pair(d, i)
55 sh.call("wizard", "migrate", d.location, *child_args,
56 on_success=on_success, on_error=on_error)
58 for name, deploys in errors.items():
59 logging.warning("%s from %d installs" % (name, len(deploys)))
61 def parse_args(argv, baton):
62 usage = """usage: %prog mass-migrate [ARGS] APPLICATION
64 Mass migrates an application to the new repository format.
65 Essentially equivalent to running '%prog migrate' on all
66 autoinstalls for a particular application found by parallel-find,
67 but with advanced reporting.
69 This command is intended to be run as root on a server with
70 the scripts AFS patch."""
71 parser = command.WizardOptionParser(usage)
72 baton.push(parser, "log_dir")
73 baton.push(parser, "seen")
74 baton.push(parser, "no_parallelize")
75 baton.push(parser, "dry_run")
76 baton.push(parser, "max_processes")
77 parser.add_option("--force", dest="force", action="store_true",
78 default=False, help="Force migrations to occur even if .scripts or .git exists.")
79 baton.push(parser ,"limit")
80 baton.push(parser, "versions_path")
81 baton.push(parser, "srv_path")
82 baton.push(parser, "user")
83 options, args, = parser.parse_all(argv)
85 parser.error("too many arguments")
87 parser.error("must specify application to migrate")
90 def calculate_base_args(options):
91 return command.make_base_args(options, dry_run="--dry-run", srv_path="--srv-path",