def compare_revisions(self, document_name: str, revisions: list = [], pretty_html: bool = False) -> list: diffs = [] if len(revisions) == 0: revisions = self.get_revisions(document_name) request_ids = [ self.get_request_id(document_name, i) for i in revisions ] for i in range(0, len(request_ids) - 1): request_id1 = request_ids[i] request_id2 = request_ids[i + 1] md1 = self.get_markdown(request_id1) md2 = self.get_markdown(request_id2) if pretty_html: sxsdiff_result = DiffCalculator().run(md1, md2) html_store = StringIO() GitHubStyledGenerator(file=html_store).run(sxsdiff_result) html_diff = html_store.getvalue() diffs.append(html_diff) else: dmp = diff_match_patch.diff_match_patch() diff = dmp.diff_main(md1, md2) dmp.diff_cleanupSemantic(diff) diffs.append(diff) return diffs
def main(argv): if len(argv) != 3: print("Usage: %s <oldfile> <newfile>" % argv[0]) sys.exit(1) # Read file content as unicode text old = readfile_unicode(argv[1]) new = readfile_unicode(argv[2]) stdout = sys.stdout # Do special handling for windows and python2 if six.PY2 and sys.platform == 'win32': stdout = codecs.getwriter('utf-8')(sys.stdout) sxsdiff_result = DiffCalculator().run(old, new) GitHubStyledGenerator(file=stdout).run(sxsdiff_result)
def compare_revisions( self, document_name: str, revisions: list = [], pretty_html: bool = False) -> list: """Compare two documents and return the diff between them - document_name: the name of the document - revisions: the list of revisions to be taken into consideration. When nothing is supplied, all the revisions of the document are compared - pretty_html: if a general diff is to be returned or should a pretty html document is to be generated instead """ diffs = [] if len(revisions) == 0: revisions = self.get_revisions(document_name) request_ids = [ self.get_request_id( document_name, i) for i in revisions] for i in range(0, len(request_ids) - 1): request_id1 = request_ids[i] request_id2 = request_ids[i + 1] md1 = self.get_markdown(request_id1) md2 = self.get_markdown(request_id2) if pretty_html: sxsdiff_result = DiffCalculator().run(md1, md2) html_store = StringIO() GitHubStyledGenerator(file=html_store).run(sxsdiff_result) html_diff = html_store.getvalue() diffs.append(html_diff) else: dmp = diff_match_patch.diff_match_patch() diff = dmp.diff_main(md1, md2) dmp.diff_cleanupSemantic(diff) diffs.append(diff) return diffs
def diff_calc(): return DiffCalculator()