]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/mediawiki.py
Suppress ^M characters from Git progress bars.
[wizard.git] / wizard / app / mediawiki.py
index 65a8704cb40afc474ed5dc4dcec1b321da303ef8..3fdec143f66fce2a0da23cbb42f939ad021e3cd6 100644 (file)
@@ -54,6 +54,11 @@ class Application(deploy.Application):
         match = regex.search(contents)
         if not match: return None
         return distutils.version.LooseVersion(match.group(2)[1:-1])
+    def checkWeb(self, d, out=None):
+        page = d.fetch("/index.php?title=Main_Page")
+        if type(out) is list:
+            out.append(page)
+        return page.find("<!-- Served") != -1
     def install(self, version, options):
         try:
             os.unlink("LocalSettings.php")
@@ -76,23 +81,28 @@ class Application(deploy.Application):
             'SysopPass': options.admin_password,
             'SysopPass2': options.admin_password,
             }
-        result = install.fetch(options, 'config/index.php', post=postdata)
+        result = install.fetch(options, '/config/index.php', post=postdata)
         if options.verbose: print result
         if result.find("Installation successful") == -1:
             raise install.Failure()
         os.rename('config/LocalSettings.php', 'LocalSettings.php')
-    def upgrade(self, version, options):
+    def upgrade(self, d, version, options):
         sh = shell.Shell()
         if not os.path.isfile("AdminSettings.php"):
-            sh.call("git", "checkout", "mediawiki-" + str(version), "--", "AdminSettings.php")
-        result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
-        if not result.rstrip().split()[-1] == "Done.":
+            sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
+        try:
+            result = sh.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))
+        results = result.rstrip().split()
+        if not results or not results[-1] == "Done.":
             raise app.UpgradeFailure(result)
     def backup(self, deployment, options):
         sh = shell.Shell()
         # XXX: duplicate code, refactor, also, race condition
         backupdir = os.path.join(".scripts", "backups")
-        outdir = os.path.join(backupdir, str(deployment.version) + "-" + datetime.date.today().isoformat())
+        backup = str(deployment.version) + "-" + datetime.date.today().isoformat()
+        outdir = os.path.join(backupdir, backup)
         if not os.path.exists(backupdir):
             os.mkdir(backupdir)
         if os.path.exists(outdir):
@@ -103,7 +113,9 @@ class Application(deploy.Application):
             sh.call("mysqldump", "--compress", "-r", outfile, *get_mysql_args(deployment))
             sh.call("gzip", "--best", outfile)
         except shell.CallError as e:
+            shutil.rmtree(outdir)
             raise app.BackupFailure(e.stderr)
+        return backup
     def restore(self, deployment, backup, options):
         sh = shell.Shell()
         backup_dir = os.path.join(".scripts", "backups", backup)
@@ -120,7 +132,7 @@ def get_mysql_args(d):
     vars = d.extract()
     if 'WIZARD_DBNAME' not in vars:
         raise app.BackupFailure("Could not determine database name")
-    triplet = scripts.get_sql_credentials()
+    triplet = scripts.get_sql_credentials(vars)
     args = []
     if triplet is not None:
         server, user, password = triplet