]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/command/blacklist.py
Fix bug where php.ini not being rewritten for MediaWiki.
[wizard.git] / wizard / command / blacklist.py
index 36b2a9864ef19f4be057074fcfeb4a4195dc404a..d3007638d2e7bec860f5d0af3995c386fac63188 100644 (file)
@@ -1,30 +1,46 @@
-import logging
 import os
-import optparse
-import sys
-import distutils.version
+import errno
+import logging
 
-from wizard import command, deploy, git, shell, util
+from wizard import command, deploy, shell, util
 
 def main(argv, baton):
     options, args = parse_args(argv, baton)
-    if not args:
-        reason = ""
+    # Directory information not transferred via command line, so this
+    # will not error due to the changed directory.
+    shell.drop_priviledges(".", options.log_file)
+    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:
-        reason = args[0]
-    sh = shell.Shell()
-    if os.path.exists(".git/WIZARD_REPO"):
-        util.chdir(sh.eval('git', 'config', 'remote.origin.url'))
-    open('.scripts/blacklisted', 'w').write(reason + "\n")
+        open(production.blacklisted_file, 'w').write(args[0] + "\n")
 
 def parse_args(argv, baton):
-    usage = """usage: %prog blacklist [ARGS] [REASON]
+    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) > 1:
-        parser.error("too many arguments")
+    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