]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/mediawiki.py
More bugfixes from running live.
[wizard.git] / wizard / app / mediawiki.py
index 6b39c8fd54d5721888c2a51ef13dde55a1fefc4b..600eccdbd20863cf56f24dc35dfe6d0bb0a33be0 100644 (file)
@@ -6,7 +6,7 @@ import logging
 import shlex
 import shutil
 
-from wizard import app, deploy, install, scripts, shell, util
+from wizard import app, deploy, install, resolve, scripts, shell, util
 from wizard.app import php
 
 def make_filename_regex(var):
@@ -26,6 +26,101 @@ seed = {
         'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
         }
 
+resolutions = {
+'LocalSettings.php': [
+    ("""
+<<<<<<<
+***1***
+=======
+## The URL base path to the directory containing the wiki;
+## defaults for all runtime URL paths are based off of this.
+## For more information on customizing the URLs please see:
+## http://www.mediawiki.org/wiki/Manual:Short_URL
+***2***
+$wgScriptExtension  = ".php";
+
+## UPO means: this is also a user preference option
+>>>>>>>
+""", [-1]),
+    ("""
+<<<<<<<
+***1***
+=======
+
+# MySQL specific settings
+$wgDBprefix         = "";
+>>>>>>>
+""", ["\n# MySQL specific settings", 1]),
+    ("""
+<<<<<<<
+## is writable, then uncomment this:
+***1***
+=======
+## is writable, then set this to true:
+$wgEnableUploads       = false;
+>>>>>>>
+""", [-1]),
+    ("""
+<<<<<<<
+***1***
+$wgMathPath         = "{$wgUploadPath}/math";
+$wgMathDirectory    = "{$wgUploadDirectory}/math";
+$wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
+=======
+$wgUseTeX           = false;
+>>>>>>>
+""", [1]),
+    # order of these rules is important
+    ("""
+<<<<<<<
+$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
+$wgCacheEpoch = max( $wgCacheEpoch, $configdate );
+***1***
+?>
+=======
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [0, 1]),
+    ("""
+<<<<<<<
+$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
+$wgCacheEpoch = max( $wgCacheEpoch, $configdate );
+***1***
+=======
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [0, 1]),
+    ("""
+<<<<<<<
+?>
+=======
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [0]),
+    ("""
+<<<<<<<
+***1***
+?>
+=======
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [1, 0]),
+    ("""
+<<<<<<<
+***1***
+=======
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [1, 0]),
+    ]
+}
+
 class Application(deploy.Application):
     parametrized_files = ['LocalSettings.php', 'php.ini']
     deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
@@ -54,9 +149,44 @@ 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):
-        page = d.fetch("index.php?title=Special:Version")
-        return page.find("MediaWiki is free software") != -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 prepareMerge(self, dir):
+        with util.ChangeDirectory(dir):
+            # XXX: this should be factored out
+            old_contents = open("LocalSettings.php", "r").read()
+            contents = old_contents
+            while "\r\n" in contents:
+                contents = contents.replace("\r\n", "\n")
+            contents = contents.replace("\r", "\n")
+            if contents != old_contents:
+                logging.info("Converted LocalSettings.php to UNIX file endings")
+                open("LocalSettings.php", "w").write(contents)
+    def resolveConflicts(self, dir):
+        # XXX: this is pretty generic
+        resolved = True
+        with util.ChangeDirectory(dir):
+            sh = shell.Shell()
+            for status in sh.eval("git", "ls-files", "--unmerged").splitlines():
+                file = status.split()[-1]
+                if file in resolutions:
+                    contents = open(file, "r").read()
+                    for spec, result in resolutions[file]:
+                        old_contents = contents
+                        contents = resolve.resolve(contents, spec, result)
+                        if old_contents != contents:
+                            logging.info("Did resolution with spec:\n" + spec)
+                    open(file, "w").write(contents)
+                    if not resolve.is_conflict(contents):
+                        sh.call("git", "add", file)
+                    else:
+                        resolved = False
+                else:
+                    resolved = False
+        return resolved
     def install(self, version, options):
         try:
             os.unlink("LocalSettings.php")
@@ -79,7 +209,7 @@ 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()
@@ -87,7 +217,7 @@ class Application(deploy.Application):
     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")
+            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:
@@ -111,6 +241,7 @@ 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):
@@ -129,7 +260,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