X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/e52b4daaec6159bab7e40c0903cccee1f760918f..4b2ee92aafcc380eaf4a2c16f9ee08c53ad3a5f8:/wizard/command/migrate.py diff --git a/wizard/command/migrate.py b/wizard/command/migrate.py index a1e4957..fd39dbe 100644 --- a/wizard/command/migrate.py +++ b/wizard/command/migrate.py @@ -4,31 +4,33 @@ import logging import errno import sys -from wizard import deploy -from wizard import shell -from wizard import util -from wizard.command import _base +from wizard import command, deploy, shell, util -def main(argv, global_options): +def main(argv, baton): options, args = parse_args(argv) dir = args[0] logging.debug("uid is %d" % os.getuid()) - _base.chdir(dir) + command.chdir(dir) check_if_already_migrated(options) - version = calculate_version() - repo = version.application.getRepository() - tag = version.getScriptsTag() + deployment = make_deployment() # uses chdir + version = deployment.app_version + repo = version.application.repository + tag = version.scripts_tag os.unsetenv("GIT_DIR") # prevent some perverse errors sh = shell.Shell(options.dry_run) check_if_tag_exists(sh, repo, tag) make_repository(sh, options, repo, tag) + make_variables(deployment, options) - os.rename(".scripts-version", ".scripts/old-version") # archive + if not options.dry_run: + os.rename(".scripts-version", ".scripts/old-version") # archive + else: + logging.info("mv .scripts-version .scripts/old-version") def parse_args(argv): usage = """usage: %prog migrate [ARGS] DIR @@ -40,7 +42,7 @@ what repository and tag to use. This command is meant to be run as the owner of the install it is upgrading (see the scripts AFS kernel patch). Do NOT run this command as root.""" - parser = _base.WizardOptionParser(usage) + parser = command.WizardOptionParser(usage) parser.add_option("--dry-run", dest="dry_run", action="store_true", default=False, help="Prints would would be run without changing anything") parser.add_option("--force", "-f", dest="force", action="store_true", @@ -64,10 +66,9 @@ def check_if_already_migrated(options): logging.warning("Force removing .scripts directory") if not options.dry_run: shutil.rmtree(".scripts") -def calculate_version(): +def make_deployment(): try: - d = deploy.Deployment.fromDir(".") - return d.getAppVersion() + return deploy.Deployment(".") except IOError as e: if e.errno == errno.ENOENT: raise NotAutoinstallError(dir) @@ -91,8 +92,12 @@ def make_repository(sh, options, repo, tag): alternates = open(file, "w") alternates.write(data) alternates.close() + htaccess = open(".git/.htaccess", "w") + htaccess.write("Deny from all\n") + htaccess.close() else: logging.info("# create %s containing \"%s\"" % (file, data)) + logging.info('# create .htaccess containing "Deny from all"') # configure our remote (this is merely for convenience; wizard scripts # will not rely on this) sh.call("git", "remote", "add", "origin", repo) @@ -106,26 +111,13 @@ def make_repository(sh, options, repo, tag): # checkout the .scripts directory sh.call("git", "checkout", ".scripts") # commit user local changes - lines = ["Initial commit after migration." - ,"" - ,"Wizard-revision: %s" % util.get_revision() - ,"Wizard-args: %s" % " ".join(sys.argv) - ] + message = "Autoinstall migration of %s locker.\n\n%s" % (util.get_dir_owner(), util.get_git_footer()) + util.set_git_env() try: - lines.append("Migrated-by: " + util.get_operator_git()) - # maybe this should go in massmigrate - op_realname, op_email = util.get_operator_info() - os.putenv("GIT_COMMITTER_NAME", op_realname) - os.putenv("GIT_COMMITTER_EMAIL", op_email) + message += "\nMigrated-by: " + util.get_operator_git() except util.NoOperatorInfo: pass - try: - lockername = util.get_dir_owner(".") - os.putenv("GIT_AUTHOR_NAME", "%s locker" % lockername) - os.putenv("GIT_AUTHOR_EMAIL", "%s@scripts.mit.edu" % lockername) - except KeyError: - pass - sh.call("git", "commit", "--allow-empty", "-a", "-m", "\n".join(lines)) + sh.call("git", "commit", "--allow-empty", "-a", "-m", message) # for verbose purposes, give us a git status and git diff if options.verbose: try: @@ -137,7 +129,25 @@ def make_repository(sh, options, repo, tag): except shell.CallError: pass -class Error(_base.Error): +def make_variables(d, options): + """Make .scripts/variables which contains variables based off of + what was regexed out of existing configuration files.""" + variables = d.extract() + if not options.dry_run: f = open(".scripts/variables", "w") + for k,v in variables.items(): + if v is None: + # once we get everything on the same version, you should + # actually start paying attention to these warnings + logging.warning("Variable %s not found" % k) + else: + logging.debug("Variable %s is %s" % (k,v)) + if not options.dry_run: + f.write("%s %s\n" % (k,v)) + else: + logging.info('# write line "%s %s" to .scripts/variables' % (k,v)) + if not options.dry_run: f.close() + +class Error(command.Error): """Base exception for all exceptions raised by migrate""" pass @@ -161,17 +171,6 @@ ERROR: Could not find .scripts-version file. Are you sure this is an autoinstalled application? """ -class NoRepositoryError(Error): - def __init__(self, app): - self.app = app - def __str__(self): - return """ - -ERROR: Could not find repository for this application. Have -you converted the repository over? Is the name %s -the same as the name of the .git folder? -""" % self.app - class NoTagError(Error): def __init__(self, version): self.version = version