X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/ad795d92aed9f47636c46a2a4604253be06eb526..10fea9a7ddab6a654922514b13b135772cc98a01:/wizard/command/blacklist.py diff --git a/wizard/command/blacklist.py b/wizard/command/blacklist.py index f20e43d..d300763 100644 --- a/wizard/command/blacklist.py +++ b/wizard/command/blacklist.py @@ -1,28 +1,46 @@ import os +import errno +import logging -from wizard import command, shell, util +from wizard import command, deploy, shell, util def main(argv, baton): options, args = parse_args(argv, baton) - reason = args[0] - # XXX: this should be abstracted away! - if os.path.exists(".git/WIZARD_REPO"): - util.chdir(shell.eval('git', 'config', 'remote.origin.url')) # Directory information not transferred via command line, so this # will not error due to the changed directory. shell.drop_priviledges(".", options.log_file) - open('.scripts/blacklisted', 'w').write(reason + "\n") + command.chdir_to_production() + production = deploy.ProductionCopy(".") + production.verify() + if options.delete: + try: + os.unlink(production.blacklisted_file) + except OSError as e: + if e.errno == errno.ENOENT: + logging.warning("No-op: application was not blacklisted") + else: + raise + else: + open(production.blacklisted_file, 'w').write(args[0] + "\n") def parse_args(argv, baton): usage = """usage: %prog blacklist [ARGS] REASON + %prog blacklist --delete -Touches .scripts/blacklisted so that we don't attempt -to upgrade the script in the future.""" +Adds the file .wizard/blacklisted so that future upgrades +are not attempted without manual intervention. If run +with the flag --delete, it deletes the blacklist file.""" parser = command.WizardOptionParser(usage) + parser.add_option("--delete", dest="delete", action="store_true", + default=False, help="Delete the blacklist entry, enabling normal usage.") options, args = parser.parse_all(argv) - if len(args) > 2: - parser.error("too many arguments") - if len(args) < 1: - parser.error("must specify reason") + if options.delete: + if len(args) > 1: + parser.error("too many arguments") + else: + if len(args) > 2: + parser.error("too many arguments") + if len(args) < 1: + parser.error("must specify reason") return options, args