]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/mediawiki.py
Use CLI installer for MediaWiki 1.17.0 and later.
[wizard.git] / wizard / app / mediawiki.py
index 1505fa17d63647f7890ba01832c4c7c5628d0ffc..2b6498b298362aaae7a120632e5b3f186a492135 100644 (file)
@@ -6,9 +6,17 @@ import lxml.etree
 import StringIO
 import logging
 
-from wizard import app, install, resolve, shell, util
+from wizard import app, install, resolve, shell, sql, util
 from wizard.app import php
 
+# Note: Maintenance script exit codes
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# MediaWiki has notoriously spotty support for exit codes.  It has
+# gotten better, but there are still always cases that slip through,
+# such as <https://bugzilla.wikimedia.org/show_bug.cgi?id=29588>.
+# As a result, we check both for exit codes AND for the "success"
+# message in stdout.
+
 def make_filename_regex(var):
     """See :ref:`versioning config <seed>` for more information."""
     return 'LocalSettings.php', php.re_var(var)
@@ -44,6 +52,32 @@ class Application(app.Application):
     def checkWeb(self, deployment):
         return self.checkWebPage(deployment, "/index.php?title=Main_Page", outputs=["<!-- Served"])
     def install(self, version, options):
+        if version >= distutils.version.LooseVersion("1.17.0"):
+            self.install_1_17_0(options)
+        else:
+            self.install_old(options)
+    def install_1_17_0(self, options):
+        util.soft_unlink("LocalSettings.php")
+        try:
+            result = shell.eval(
+                    "php", "maintenance/install.php",
+                    "--dbname", options.dsn.database,
+                    "--dbpass", options.dsn.password,
+                    "--dbserver", options.dsn.host,
+                    "--dbuser", options.dsn.username,
+                    "--email", options.email,
+                    "--pass", options.admin_password,
+                    options.title, options.admin_name,
+                    log=True)
+        except shell.CallError as e:
+            raise app.RecoverableInstallFailure("Install script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
+        logging.debug("Install script output:\n\n" + result)
+        # See [Note: Maintenance script exit codes]
+        results = result.rstrip().split()
+        if not results or not results[-1] == "done":
+            raise app.RecoverableInstallFailure(result)
+
+    def install_old(self, options):
         util.soft_unlink("LocalSettings.php")
         os.chmod("config", 0777) # XXX: vaguely sketchy
 
@@ -81,15 +115,20 @@ class Application(app.Application):
             result = shell.eval("php", "maintenance/update.php", "--quick", log=True)
         except shell.CallError as e:
             raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
+        logging.debug("Upgrade script output:\n\n" + result)
+        # See [Note: Maintenance script exit codes]
         results = result.rstrip().split()
         if not results or not results[-1] == "Done.":
             raise app.UpgradeFailure(result)
+    @app.throws_database_errors
     def backup(self, deployment, backup_dir, options):
-        app.backup_database(backup_dir, deployment)
+        sql.backup(backup_dir, deployment)
+    @app.throws_database_errors
     def restore(self, deployment, backup_dir, options):
-        app.restore_database(backup_dir, deployment)
+        sql.restore(backup_dir, deployment)
+    @app.throws_database_errors
     def remove(self, deployment, options):
-        app.remove_database(deployment)
+        sql.drop(deployment.dsn)
     def researchFilter(self, filename, added, deleted):
         if filename == "LocalSettings.php":
             return added == deleted == 10 or added == deleted == 9