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': [
+# ("""
+#""", [])
+# ]
+}
+
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 resolveConflicts(self, dir):
+ # XXX: this is pretty generic
+ resolved = True
+ with util.ChangeDirectory(dir):
+ sh = shell.Shell()
+ for file in sh.eval("git", "ls-files", "--unmerged").splitlines():
+ if file in resolutions:
+ contents = open(file, "r").read()
+ for spec, result in resolutions:
+ contents = resolve.resolve(contents, spec, result)
+ if not resolve.is_conflict(contents):
+ open(file, "w").write(contents)
+ sh.call("git", "add", file)
+ else:
+ resolved = False
+ else:
+ resolved = False
+ return resolved
def install(self, version, options):
try:
os.unlink("LocalSettings.php")
try:
sh.call("git", "merge", next_virtual_commit)
except shell.CallError:
+ # Run the application's specific merge resolution algorithms
+ # and see if we can salvage it
curdir = os.getcwd()
+ if d.application.resolveConflicts(curdir):
+ logging.info("Resolved conflicts with application specific knowledge")
+ sh.call("git", "commit", "-a", "-m", "merge")
+ return
logging.info("Conflict info:\n", sh.eval("git", "diff"))
if use_shm:
# Keeping all of our autoinstalls in shared memory is
contents = contents.replace(key, value)
f = open(fullpath, "w")
f.write(contents)
+ def resolveConflicts(self, dir):
+ """
+ Takes a directory with conflicted files and attempts to
+ resolve them. Returns whether or not all conflicted
+ files were resolved or not. Fully resolved files are
+ added to the index, but no commit is made.
+ """
+ return False
def prepareConfig(self, deployment):
"""
Takes a deployment and replaces any explicit instances
def resolve(contents, spec, result):
rstring, mappings = spec_to_regex(spec)
- print rstring
regex = re.compile(rstring, re.DOTALL)
repl = result_to_repl(result, mappings)
return regex.sub(repl, contents)
+
+def is_conflict(contents):
+ # Really really simple heuristic
+ return "<<<<<<<" in contents