]> scripts.mit.edu Git - wizard.git/blob - wizard/command/blacklist.py
Remove string exception from remaster.
[wizard.git] / wizard / command / blacklist.py
1 import os
2 import errno
3 import logging
4
5 from wizard import command, deploy, shell, util
6
7 def main(argv, baton):
8     options, args = parse_args(argv, baton)
9     # Directory information not transferred via command line, so this
10     # will not error due to the changed directory.
11     shell.drop_priviledges(".", options.log_file)
12     command.chdir_to_production()
13     production = deploy.ProductionCopy(".")
14     production.verify()
15     if options.delete:
16         try:
17             os.unlink(production.blacklisted_file)
18         except OSError as e:
19             if e.errno == errno.ENOENT:
20                 logging.warning("No-op: application was not blacklisted")
21             else:
22                 raise
23     else:
24         open(production.blacklisted_file, 'w').write(args[0] + "\n")
25
26 def parse_args(argv, baton):
27     usage = """usage: %prog blacklist [ARGS] REASON
28        %prog blacklist --delete
29
30 Adds the file .wizard/blacklisted so that future upgrades
31 are not attempted without manual intervention.  If run
32 with the flag --delete, it deletes the blacklist file."""
33     parser = command.WizardOptionParser(usage)
34     parser.add_option("--delete", dest="delete", action="store_true",
35             default=False, help="Delete the blacklist entry, enabling normal usage.")
36     options, args = parser.parse_all(argv)
37     if options.delete:
38         if len(args) > 1:
39             parser.error("too many arguments")
40     else:
41         if len(args) > 2:
42             parser.error("too many arguments")
43         if len(args) < 1:
44             parser.error("must specify reason")
45     return options, args
46