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):
'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
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")