_applications = dict([(n,Application.make(n)) for n in _application_list ])
return _applications
+def getApplication(appname):
+ """Retrieves application instance given a name"""
+ return applications()[appname]
class Application(object):
"""
"""
resolved = True
files = set()
+ files = {}
for status in shell.eval("git", "ls-files", "--unmerged").splitlines():
- files.add(status.split()[-1])
- for file in files:
- # check for newline mismatch
- # HACK: using git diff to tell if files are binary or not
- if not len(shell.eval("git", "diff", file).splitlines()) == 1 and util.mixed_newlines(file):
- # this code only works on Unix
- def get_newline(filename):
- f = open(filename, "U")
- # for some reason I need two
- s = f.readline()
- if s != "" and f.newlines is None:
- f.readline()
- if not isinstance(f.newlines, str):
- raise Exception("Assert: expected newlines to be string, instead was %s in %s" % (repr(f.newlines), file))
- return f.newlines
- def create_reference(id):
- f = tempfile.NamedTemporaryFile(prefix="wizardResolve", delete=False)
- shell.call("git", "cat-file", "blob", ":%d:%s" % (id, file), stdout=f)
- f.close()
- return get_newline(f.name), f.name
- def convert(filename, dest_nl):
- contents = open(filename, "U").read().replace("\n", dest_nl)
- open(filename, "wb").write(contents)
- logging.info("Mixed newlines detected in %s", file)
- common_nl, common_file = create_reference(1)
- our_nl, our_file = create_reference(2)
- their_nl, their_file = create_reference(3)
- remerge = False
- if common_nl != their_nl:
- # upstream can't keep their newlines straight
- logging.info("Converting common file (1) from %s to %s newlines", repr(common_nl), repr(their_nl))
- convert(common_file, their_nl)
- remerge = True
- if our_nl != their_nl:
- # common case
- logging.info("Converting our file (2) from %s to %s newlines", repr(our_nl), repr(their_nl))
- convert(our_file, their_nl)
- remerge = True
- if remerge:
- logging.info("Remerging %s", file)
- with open(file, "wb") as f:
- try:
- shell.call("git", "merge-file", "--stdout", our_file, common_file, their_file, stdout=f)
- logging.info("New merge was clean")
- shell.call("git", "add", file)
- continue
- except shell.CallError:
- pass
- logging.info("Merge was still unclean")
- else:
- logging.warning("Mixed newlines detected in %s, but no remerge possible", file)
+ mode, hash, role, name = status.split()
+ files.setdefault(name, set()).add(int(role))
+ for file, roles in files.items():
+ # some automatic resolutions
+ if 1 not in roles and 2 not in roles and 3 in roles:
+ # upstream added a file, but it conflicted for whatever reason
+ shell.call("git", "add", file)
+ continue
+ elif 1 in roles and 2 not in roles and 3 in roles:
+ # user deleted the file, but upstream changed it
+ shell.call("git", "rm", file)
+ continue
# manual resolutions
if file in self.resolutions:
contents = open(file, "r").read()
not to depend on pages that are not the main page.
"""
raise NotImplementedError
- def checkWebPage(self, deployment, page, output):
+ def checkWebPage(self, deployment, page, outputs=[], exclude=[]):
"""
Checks if a given page of an autoinstall contains a particular string.
"""
page = deployment.fetch(page)
- result = page.find(output) != -1
- if result:
+ for x in exclude:
+ if page.find(x) != -1:
+ logging.info("checkWebPage (failed due to %s):\n\n%s", x, page)
+ return False
+ votes = 0
+ for output in outputs:
+ votes += page.find(output) != -1
+ if votes > len(outputs) / 2:
logging.debug("checkWebPage (passed):\n\n" + page)
+ return True
else:
logging.info("checkWebPage (failed):\n\n" + page)
- return result
+ return False
def checkConfig(self, deployment):
"""
Checks whether or not an autoinstall has been configured/installed