Exemplo n.º 1
0
	def getPrettyGHDiff(self):
		blobOld = Blob(self.commit.commit.repo, unhexlify(self.oldSha)).data_stream.read()
		blobNew = Blob(self.commit.commit.repo, unhexlify(self.newSha)).data_stream.read()
		try:
			diffContent = ghdiff.diff(smart_unicode(blobOld).splitlines(), smart_unicode(blobNew).splitlines())
		except DjangoUnicodeDecodeError:
			diffContent = ghdiff.diff(str(blobOld).decode('latin1').splitlines(),
			                          str(blobNew).decode('latin1').splitlines())
		return diffContent
Exemplo n.º 2
0
    def _compare_sheet(self, sheet_name, uploaded_rows, for_type):
        """
        :param uploaded_rows: dict
        :param for_type: type of sheet, module_and_forms, module, form
        :return: diff generated by ghdiff or None
        """
        columns_to_compare = COLUMNS_TO_COMPARE[
            for_type] + self.lang_cols_to_compare
        expected_rows = self._filter_rows(for_type,
                                          self.expected_rows[sheet_name],
                                          sheet_name)

        parsed_expected_rows = []
        parsed_uploaded_rows = []
        for expected_row in expected_rows:
            parsed_expected_rows.append([
                expected_row[self._get_header_index(sheet_name, column_name)]
                for column_name in columns_to_compare
            ])
        for uploaded_row in uploaded_rows:
            parsed_uploaded_rows.append([
                uploaded_row.get(column_name)
                for column_name in columns_to_compare
            ])

        expected_rows_as_string = '\n'.join(
            [', '.join(row) for row in parsed_expected_rows])
        uploaded_rows_as_string = '\n'.join(
            [', '.join(row) for row in parsed_uploaded_rows])
        diff = ghdiff.diff(expected_rows_as_string,
                           uploaded_rows_as_string,
                           css=False)
        if diff == NO_GHDIFF_MESSAGE:
            return None
        return diff
Exemplo n.º 3
0
 def save(self, topic):
     if self.title.data != topic.title:
         title = self.title.data
         history = History(diff_content="将标题从 %s 修改为 %s" %
                           (topic.title, title),
                           topic=topic,
                           author=g.user)
         history.save()
         topic.title = title
     if self.node.data != topic.node:
         node = self.node.data
         history = History(diff_content="从 %s 移动到 %s" %
                           (topic.node.name, node.name),
                           topic=topic,
                           author=g.user)
         history.save()
         topic.node = node
     if self.content.data != topic.content:
         content = self.content.data
         history = History(diff_content=diff(topic.content,
                                             content,
                                             css=False),
                           topic=topic,
                           author=g.user)
         history.save()
         topic.content = content
     topic.changed = datetime.utcnow()
     return topic.save()
Exemplo n.º 4
0
 def save(self, topic):
     if self.title.data != topic.title:
         title = self.title.data
         history = History(
             diff_content="将标题从 %s 修改为 %s" % (topic.title, title),
             topic=topic,
             author=g.user
         )
         history.save()
         topic.title = title
     if self.node.data != topic.node:
         node = self.node.data
         history = History(
             diff_content="从 %s 移动到 %s" % (topic.node.name, node.name),
             topic=topic,
             author=g.user
         )
         history.save()
         topic.node = node
     if self.content.data != topic.content:
         content = self.content.data
         history = History(
             diff_content=diff(topic.content, content, css=False),
             topic=topic,
             author=g.user
         )
         history.save()
         topic.content = content
     topic.changed = datetime.utcnow()
     return topic.save()
Exemplo n.º 5
0
def diff(link):
    """ two pages (newid, and oldid) and show the changes.
    """
    result = wiki_for(link)

    new_id = request.args.get('newid', None)
    old_id = request.args.get('oldid', None)
    if new_id is not None and old_id is not None:
        new_id = int(new_id)
        old_id = int(old_id)

        results = (current_session.query(Wiki).filter(
            Wiki.id.in_([new_id, old_id])).all())
        if not results or len(results) != 2:
            abort(404)

        old_wiki = [o for o in results if o.id == old_id][0]
        new_wiki = [o for o in results if o.id == new_id][0]

        html_diff = ghdiff.diff(old_wiki.content_rendered,
                                new_wiki.content_rendered)
    else:
        abort(404)

    return render_template('wiki/diff.html', wiki=result, html_diff=html_diff)
Exemplo n.º 6
0
    def diff(self, oth):
        left = str(self)
        right = str(oth)

        import ghdiff

        out = ghdiff.diff(left, right)
        return {"type": "html", "diff": out}
Exemplo n.º 7
0
 def validate(self):
     self.new_preview_store = frappe.utils.md_to_html(self.new_code)
     if not self.new:
         self.orignal_code = frappe.db.get_value("Wiki Page",
                                                 self.wiki_page, "content")
         self.diff = diff(self.orignal_code, self.new_code)
         self.orignal_preview_store = frappe.utils.md_to_html(
             self.orignal_code)
Exemplo n.º 8
0
 def validate_new_file(self):
     self.orignal_code = ""
     self.diff = diff(self.orignal_code, self.new_code)
     old_html = frappe.utils.md_to_html(self.orignal_code)
     new_html = frappe.utils.md_to_html(self.new_code)
     self.new = 1
     self.orignal_preview_store = ""
     self.new_preview_store = new_html
Exemplo n.º 9
0
    def diff(self, oth):
        left = str(self)
        right = str(oth)

        #pyenvdiff is designed to be dependency free, so we put import statements for a few dependencies in nice-to-have features.
        import ghdiff

        out = ghdiff.diff(left, right)
        return {"type": "html", "diff": out}
Exemplo n.º 10
0
    def compare(self, old_sha):
        """Compare two revisions of the same page.

        :param old_sha: Older sha.
        :return: str - Raw markup with styles

        """
        old = self.wiki.get_page(self.name, sha=old_sha)
        return ghdiff.diff(old.data, self.data)
Exemplo n.º 11
0
 def getDiff(self, oldValue, newValue):
     """
     Renvoie un diff formaté entre deux valeurs
     Si le champs contient des tags html, ceux-ci sont ignorés
     """
     if oldValue == newValue:
         return None
     oldValue = self.stripHTML(oldValue)
     newValue = self.stripHTML(newValue)
     return diff(oldValue, newValue)
Exemplo n.º 12
0
 def _generate_diff(parsed_current_rows, parsed_uploaded_rows):
     current_rows_as_string = '\n'.join(
         [', '.join(row) for row in parsed_current_rows])
     uploaded_rows_as_string = '\n'.join(
         [', '.join(row) for row in parsed_uploaded_rows])
     diff = ghdiff.diff(current_rows_as_string,
                        uploaded_rows_as_string,
                        css=False)
     if diff == NO_GHDIFF_MESSAGE:
         return None
     return diff
Exemplo n.º 13
0
 def save_history(self, id, before, after, type="content"):
     data = {
         "author": self.current_user['name'],
         "before": before,
         "after": after,
         "ghdiff": ghdiff.diff(before, after, css=False),
         "target_id": ObjectId(id),
         "created": time.time(),
         "type": type
     }
     self.db.histories.insert(data)
Exemplo n.º 14
0
    def compare(self, old_sha):
        """Compare two revisions of the same page.

        :param old_sha: Older sha.
        :return: str - Raw markup with styles

        """

        # TODO: This could be effectively done in the browser
        old = self.wiki.get_page(self.name, sha=old_sha)
        return ghdiff.diff(old.data, self.data)
Exemplo n.º 15
0
 def save(self, reply):
     if self.content.data != reply.content:
         content = self.content.data
         history = History(diff_content=diff(reply.content,
                                             content,
                                             css=False),
                           reply=reply,
                           author=g.user)
         history.save()
         reply.content = content
     return reply.save()
Exemplo n.º 16
0
 def save(self, reply):
     if self.content.data != reply.content:
         content = self.content.data
         history = History(
             diff_content=diff(reply.content, content, css=False),
             reply=reply,
             author=g.user
         )
         history.save()
         reply.content = content
     return reply.save()
Exemplo n.º 17
0
    def compare(self, old_sha):
        """Compare two revisions of the same page.

        :param old_sha: Older sha.
        :return: str - Raw markup with styles

        """

        # TODO: This could be effectively done in the browser
        old = self.wiki.get_page(self.name, sha=old_sha)
        return ghdiff.diff(old.data, self.data)
Exemplo n.º 18
0
 def save_history(self, id, before, after, type="content"):
     data = {
         "author": self.current_user['name'],
         "before": before,
         "after": after,
         "ghdiff": ghdiff.diff(before, after, css=False),
         "target_id": ObjectId(id),
         "created": time.time(),
         "type": type
     }
     self.db.histories.insert(data)
Exemplo n.º 19
0
def preview(content, path, attachments="{}"):

    raw_edited_content = content

    attachments = json.loads(attachments)

    for attachment in attachments:
        if attachment.get("save_path"):
            content = content.replace(attachment.get("save_path"),
                                      attachment.get("file_url"))

    try:
        resolved_route = resolve_route(get_path_without_slash(path))
    except Exception:
        frappe.throw(frappe.get_traceback(),
                     title=_(f"Please recheck the path: {path}"))

    if not resolved_route:
        return {
            "diff": diff("", content),
            "html": frappe.utils.md_to_html(content)
        }

    resolved_route.route = get_path_without_slash(path)
    resolved_route.path = resolved_route.route

    resolved_route = build_context(resolved_route)

    jenv = frappe.get_jenv()

    old_code_md = get_source(resolved_route, jenv)

    if resolved_route.page_or_generator == "Page":
        if resolved_route.template.endswith(".md"):
            content = frappe.utils.md_to_html(content)
            old_code = frappe.utils.md_to_html(old_code_md)
        content = clean_js_css(resolved_route, content, jenv)

    return {"diff": diff(old_code_md, raw_edited_content), "html": content}
Exemplo n.º 20
0
def preview(content, name, new, type, diff_css=False):
    html = frappe.utils.md_to_html(content)
    if new:
        return {"html": html}
    from ghdiff import diff

    old_content = frappe.db.get_value("Wiki Page", name, "content")
    diff = diff(old_content, content, css=diff_css)
    return {
        "html": html,
        "diff": diff,
        "orignal_preview": frappe.utils.md_to_html(old_content)
    }
Exemplo n.º 21
0
    def compare(self, name, old_sha, new_sha):
        """Compare two revisions of the same page.

        :param name: Name of page.
        :param old_sha: Older sha.
        :param new_sha: Newer sha.
        :return: str - Raw markup with styles

        """

        # TODO: This could be effectively done in the browser
        old = self.get_page(name, sha=old_sha)
        new = self.get_page(name, sha=new_sha)
        return ghdiff.diff(old['data'], new['data'])
Exemplo n.º 22
0
 def ghdiff(self, line):
     """
     Generate Github-style HTML for unified diffs
     """
     args = magic_arguments.parse_argstring(self.ghdiff, line)
     try:
         a = self.shell.user_ns[args.var1]
     except KeyError:
         raise UsageError("Unknown variable %s" % args.var1)
     try:
         b = self.shell.user_ns[args.var2]
     except KeyError:
         raise UsageError("Unknown variable %s" % args.var2)
     return HTML(ghdiff.diff(a, b))
Exemplo n.º 23
0
 def ghdiff(self, line):
     """
     Generate Github-style HTML for unified diffs
     """
     args = magic_arguments.parse_argstring(self.ghdiff, line)
     try:
         a = self.shell.user_ns[args.var1]
     except KeyError:
         raise UsageError("Unknown variable %s" % args.var1)
     try:
         b = self.shell.user_ns[args.var2]
     except KeyError:
         raise UsageError("Unknown variable %s" % args.var2)
     return HTML(ghdiff.diff(a, b))
Exemplo n.º 24
0
def recreate_body_diffs(comments):
    """
    Take a list of comments, extract their bodies, re-create full text from diffs and generate pretty html diffs.
    Returns: (OriginalText, [diffs])
    """
    body_diffs = [x['body'] for x in comments]

    full_versions = reverse_patch(body_diffs)

    results = [full_versions[0]]
    for i, diff in enumerate(full_versions[1:]):
        results.append(ghdiff.diff(full_versions[i], diff).replace('\n', ''))

    return first(results), list(rest(results))
Exemplo n.º 25
0
    def compare(self, name, old_sha, new_sha):
        """Compare two revisions of the same page.

        :param name: Name of page.
        :param old_sha: Older sha.
        :param new_sha: Newer sha.
        :return: str - Raw markup with styles

        """

        # TODO: This could be effectively done in the browser
        old = self.get_page(name, sha=old_sha)
        new = self.get_page(name, sha=new_sha)
        return ghdiff.diff(old['data'], new['data'])
Exemplo n.º 26
0
def _get_app_diffs(first_app, second_app):
    """
    Return a list of tuples. The first value in each tuple is a file name,
    the second value is an html snippet representing the diff of that file
    in the two given apps.
    """
    file_pairs = _get_file_pairs(first_app, second_app)
    diffs = []
    for name, files in file_pairs.iteritems():
        diff_html = ghdiff.diff(files[0], files[1], n=4, css=False)
        additions, deletions = _get_change_counts(diff_html)
        if additions == 0 and deletions == 0:
            diff_html = ""
        diffs.append({"name": name, "source": diff_html, "add_count": additions, "del_count": deletions})
    return sorted(diffs, key=lambda f: f["name"])
Exemplo n.º 27
0
def get_context(context):
	context.no_cache = 1

	wiki_settings = frappe.get_single("Wiki Settings")
	context.banner_image = wiki_settings.logo
	context.script = wiki_settings.javascript
	context.docs_search_scope = ""
	can_edit = frappe.session.user != "Guest"
	context.can_edit = can_edit
	context.show_my_account = False


	context.doc = frappe.get_doc('Wiki Page', frappe.form_dict.wiki_page)
	context.doc.set_breadcrumbs(context)


	from ghdiff import diff

	revision = frappe.form_dict.compare
	context.title = "Revision: " + revision
	context.parents = [
		{"route": "/" + context.doc.route, "label": context.doc.title},
		{"route": "/" + context.doc.route + "?revisions=true", "label": "Revisions"},
	]

	revision = frappe.get_doc("Wiki Page Revision", revision)

	context.revision = revision
	previous_revision_content = frappe.db.get_value(
		"Wiki Page Revision",
		filters={"creation": ("<", revision.creation), "wiki_page": context.doc.name},
		fieldname=["content"],
		order_by="creation asc",
	)

	if not previous_revision_content:
		return

	context.diff = diff(previous_revision_content, revision.content, css=False)


	return context
Exemplo n.º 28
0
def _get_app_diffs(first_app, second_app):
    """
    Return a list of tuples. The first value in each tuple is a file name,
    the second value is an html snippet representing the diff of that file
    in the two given apps.
    """
    file_pairs = _get_file_pairs(first_app, second_app)
    diffs = []
    for name, files in six.iteritems(file_pairs):
        diff_html = ghdiff.diff(files[0], files[1], n=4, css=False)
        additions, deletions = _get_change_counts(diff_html)
        if additions == 0 and deletions == 0:
            diff_html = ""
        diffs.append({
            'name': name,
            'source': diff_html,
            'add_count': additions,
            'del_count': deletions,
        })
    return sorted(diffs, key=lambda f: f['name'])
Exemplo n.º 29
0
    def _compare_sheet(self, sheet_name, uploaded_rows, for_type):
        """
        :param uploaded_rows: dict
        :param for_type: type of sheet, module_and_forms, module, form
        :return: diff generated by ghdiff or None
        """
        columns_to_compare = COLUMNS_TO_COMPARE[for_type] + [self.default_language_column]
        expected_rows = self._filter_rows(for_type, self.expected_rows[sheet_name], sheet_name)

        iterate_on = [expected_rows, uploaded_rows]
        parsed_expected_rows = []
        parsed_uploaded_rows = []
        for i, (expected_row, uploaded_row) in enumerate(zip(*iterate_on), 2):
            parsed_expected_row = [uploaded_row.get(column_name) for column_name in columns_to_compare]
            parsed_uploaded_row = [expected_row[self._get_header_index(sheet_name, column_name)]
                                   for column_name in columns_to_compare]
            parsed_expected_rows.append(parsed_expected_row)
            parsed_uploaded_rows.append(parsed_uploaded_row)
        expected_rows_as_string = '\n'.join([', '.join(row) for row in parsed_expected_rows])
        uploaded_rows_as_string = '\n'.join([', '.join(row) for row in parsed_uploaded_rows])
        diff = ghdiff.diff(expected_rows_as_string, uploaded_rows_as_string, css=False)
        if diff == NO_GHDIFF_MESSAGE:
            return None
        return diff
Exemplo n.º 30
0
def diff_rst(actual_rst, expected_rst):
    return ghdiff.diff(actual_rst.text, expected_rst.text)
Exemplo n.º 31
0
from corehq.apps.translations.app_translations import (
    expected_bulk_app_sheet_headers,
    expected_bulk_app_sheet_rows,
    get_unicode_dicts,
)
from corehq.apps.translations.const import MODULES_AND_FORMS_SHEET_NAME
from corehq.apps.translations.generators import SKIP_TRANSFEX_STRING, AppTranslationsGenerator

COLUMNS_TO_COMPARE = {
    'module_and_form': ['Type', 'sheet_name'],
    'module': ['case_property', 'list_or_detail'],
    'form': ['label'],
}
# return from ghdiff in case of no differences
NO_GHDIFF_MESSAGE = ghdiff.diff([], [], css=False)


class UploadedTranslationsValidator(object):
    """
    this compares the excel sheet uploaded with translations with what would be generated
    with current app state and flags any discrepancies found between the two
    """
    def __init__(self, app, uploaded_workbook, lang_prefix='default_'):
        self.app = app
        self.uploaded_workbook = uploaded_workbook
        self.headers = None
        self.expected_rows = None
        self.lang_prefix = lang_prefix
        self.default_language_column = self.lang_prefix + self.app.default_language
        self.app_translation_generator = AppTranslationsGenerator(
Exemplo n.º 32
0
def paste_view(url, commit=None, flag=None):
    # TODO: simplify paste view controller

    flag = PasteAction.get(flag)
    flag_path = "/" + flag.value if flag.value else ""

    # redirect to the base url if commit is "base"
    if commit == "base":
        return redirect(f"/paste/{url}{flag_path}")

    # Disable the ability to use diff on the base commit only
    if not commit and flag == PasteAction.DIFF:
        return redirect(f"/paste/{url}")

    # Select the paste from `files`
    file = FileService.get_by_url(url)
    if not file:
        abort(404)

    paste = PasteService.get_by_id(file["original"])
    if not paste:
        # Paste exists in files table but not in pastes table... remove it.
        db.delete("files", {"id": file["id"]})
        abort(404)

    # redirect user to the latest revision if commit is "latest"
    if commit == "latest":
        revision = PasteService.get_latest_revision(paste)
        if revision:
            # add latest commit hash to the URL
            url = f"{url}:{revision['commit']}"
        return redirect(f"/paste/{url}{flag_path}")

    # Get revisions for specified paste
    revisions = PasteService.get_revisions(
        RevisionInterface(pasteid=paste["id"]))
    commits = ["base"]
    if revisions:
        first_revision = revisions[0]
        if not commit:
            # user navigated to a forked paste, without specifying a commit
            # so redirect to the first commit for the paste.
            if first_revision["fork"]:
                redirect_commit = first_revision["commit"]
                return redirect(f"/paste/{url}:{redirect_commit}{flag_path}")

        is_fork = first_revision["fork"]
        # add the dummy base revision to the revision list
        if not is_fork:
            revisions = (RevisionInterface(commit="base"), *revisions)
        # list all available commits
        commits = [row["commit"] for row in revisions]
    else:
        revisions = []

    # commit provided but is not valid
    if commit and commit not in commits:
        abort(404, "Commit does not exist.")

    # If a commit is provided, get the revision row for that commit
    revision = next(filter(lambda rev: rev["commit"] == commit, revisions),
                    None)

    # Add a hit to the paste file
    # Safe to count paste as viewed here since no errors occur after this point
    FileService.increment_hits(file["id"])

    # save the original paste text before we transform it
    raw_paste = revision["paste"] if revision and commit else paste["content"]
    paste["content"] = raw_paste

    # If the user provided the raw flag, skip all HTML rendering
    if flag == PasteAction.RAW:
        response: Response = make_response(raw_paste)
        response.headers.set("Content-Type", "text/plain", charset="utf-8")
        return response

    lang = paste["lang"]
    # show paste shorturl if no name
    title = f'Paste: {paste["name"] or url}'

    # paste content inc. highlighting or diff view
    content = None

    # Check if to make a diff or not,
    # depending on if the revision exists
    if revision:
        parent, parent_commit, parent_content = PasteService.get_parent(
            revision)
        # diff with parent paste
        if flag == PasteAction.DIFF:
            content = ghdiff.diff(parent_content, revision["paste"], css=False)
        # store URL to parent paste/revision
        revision["parent_url"] = parent["shorturl"] + (":" + parent_commit if
                                                       parent_commit else "")
        # show commit hash in title
        title += f' [{revision["commit"]}]'

    # highlight the paste if not a diff
    if not content:
        content = functions.highlight_code(paste["content"], lang)

    # Decide whether the viewer owns this file (for forking or editing)
    # anon is always a fork
    is_owner = paste["userid"] != 0 and paste["userid"] == current_user.get_id(
    )

    # Get the styles for syntax highlighting
    css = functions.highlight_code_css()

    # paginate the commits for a post
    pagination = functions.Pagination(commits.index(commit or "base") + 1,
                                      1,
                                      len(commits),
                                      data=revisions)

    form_edit = PasteEditForm()
    # set edit data
    form_edit.body.data = raw_paste
    form_edit.id.data = paste["id"]
    if revision:
        form_edit.commit.data = revision["id"]

    # Provide the template with a mass of variables
    return render_template(
        "paste.tpl",
        paste=dict(
            id=paste["id"],
            raw=paste["content"],
            content=content,
            lang=lang,
            length=len(raw_paste),
            lines=len(raw_paste.split("\n")),
            own=is_owner,
            url=url,
            # add 1 hit as incrementing does not update the local value
            hits=file["hits"] + 1,
        ),
        title=title,
        css=css,
        revision=revision,
        pagination=pagination,
        flag=flag,
        form=form_edit,
    )
Exemplo n.º 33
0
 def set_diff(self):
     self.diff = diff(self.orignal_code, self.new_code)
Exemplo n.º 34
0
def diff():
    for from_version,to_version in [("144","160")]:# ["0","32","48","80","128"]:
        if not os.path.isdir("extracted_game/"+from_version) or not os.path.isdir("extracted_game/"+to_version):
            continue
    
        for char in os.listdir("extracted_game/"+from_version+"/fighter"):
            if char == "common" or char == "mii":
                continue
            print char
            lookup = motionpac("extracted_game/%s/fighter/%s/motion/"%(0,char))
            f_params = parseParams((prefix+"../param/fighter/fighter_param_vl_%s.bin")%(from_version,char))
            t_params = parseParams((prefix+"../param/fighter/fighter_param_vl_%s.bin")%(to_version,char))


            for subChar, motionPath, scriptPath,mscsbPath in getProcessList(char,from_version):
                print "\t",char,subChar

                
                ''' Parse ANIMCMD '''
                if os.path.isfile(motionPath %(to_version)):
                    
                    f = open(motionPath %(to_version),"rb")
                    printedAnything = False
                    outdir = "processed/animcmd/diff-%s-%s/" % (from_version,to_version)
                    if not os.path.isdir(outdir):
                        os.makedirs(outdir)
                    
                    if subChar == "":  
                        logfn = outdir+char+".html"
                    else:
                        logfn = outdir+char+"_"+subChar+".html"
                    log = open(logfn,"w")
                    log.write("""<style type="text/css">
        .diff {
            border: 1px solid #cccccc;
            background: none repeat scroll 0 0 #f8f8f8;
            font-family: 'Bitstream Vera Sans Mono','Courier',monospace;
            font-size: 12px;
            line-height: 1.4;
            white-space: normal;
            word-wrap: break-word;
        }
        .diff div:hover {
            background-color:#ffc;
        }
        .diff .control {
            background-color: #eaf2f5;
            color: #999999;
        }
        .diff .insert {
            background-color: #ddffdd;
            color: #000000;
        }
        .diff .insert .highlight {
            background-color: #aaffaa;
            color: #000000;
        }
        .diff .delete {
            background-color: #ffdddd;
            color: #000000;
        }
        .diff .delete .highlight {
            background-color: #ffaaaa;
            color: #000000;
        }
    </style>""")
                    from_animcmd = defaultdict(str)
                    for tmp in ["game","effect","sound","expression"]:
                        from_animcmd[tmp] = parseACMD((scriptPath+"%s.bin")%(from_version,tmp))
                    to_animcmd = defaultdict(str)
                    for tmp in ["game","effect","sound","expression"]:
                        to_animcmd[tmp] = parseACMD((scriptPath+"%s.bin")%(to_version,tmp))
                    i = 0

                    while True:
                        test = f.read(4)
                        if len(test) != 4:
                            break
                        t, = struct.unpack(">I",test)
                        if t in lookup:
                            name = lookup[t]
                        else:
                            name = ""
                        printedHeader = False

                        f_p = f_params[0][i*6:i*6+6]
                        t_p = t_params[0][i*6:i*6+6]
                        if len(f_p) == 6:
                            f_p = "{{{0}, {1}, IASA?={2}, {3}, {4}, {5}}}".format(*f_p)
                        else:
                            f_p = ""
                        
                        if len(t_p) == 6:
                            t_p = "{{{0}, {1}, IASA?={2}, {3}, {4}, {5}}}".format(*t_p)
                        else:
                            t_p = ""
                        if f_p != t_p:
                            printedAnything = True
                            if not printedHeader:
                                    
                                    log.write("<h2 class='toc'>%03X - %s - %08X</h2>\n"%(i,name,t))
                                    printedHeader = True
                                    log.write("<h4>%s</h4>\n%s\n" % ("params",ghdiff.diff(repr(f_p),repr(t_p),css=False)))
                        for tmp in ["game","effect","sound","expression"]:
                            ff = ""
                            tt = ""
                            if t in from_animcmd[tmp]:
                                ff = from_animcmd[tmp][t].split("\n")
                            if t in to_animcmd[tmp]:
                                tt = to_animcmd[tmp][t].split("\n")
                            if ff != tt:
                                printedAnything = True
                                if not printedHeader:
                                    log.write("<h2 class='toc'>%03X - %s - %08X</h2>\n"%(i,name,t))
                                    printedHeader = True
                                o = ""
                                o = ghdiff.diff(ff,tt,css=False)
                                #for line in difflib.unified_diff(ff,tt):
                                #    o += line
                                #    o += "\n"
                                log.write("<h4>%s</h4>\n%s\n" % (tmp,o))
                        i += 1
                    size = log.tell()
                    
                    log.close()
                    if not printedAnything:
                        os.remove(logfn)
Exemplo n.º 35
0
 def _missing_module_or_form_diff(self, for_type):
     return ghdiff.diff(_('{} not found').format(for_type), [], css=False)
Exemplo n.º 36
0
def diff():
    for from_version, to_version in [("144", "160")
                                     ]:  # ["0","32","48","80","128"]:
        if not os.path.isdir("extracted_game/" +
                             from_version) or not os.path.isdir(
                                 "extracted_game/" + to_version):
            continue

        for char in os.listdir("extracted_game/" + from_version + "/fighter"):
            if char == "common" or char == "mii":
                continue
            print char
            lookup = motionpac("extracted_game/%s/fighter/%s/motion/" %
                               (0, char))
            f_params = parseParams(
                (prefix + "../param/fighter/fighter_param_vl_%s.bin") %
                (from_version, char))
            t_params = parseParams(
                (prefix + "../param/fighter/fighter_param_vl_%s.bin") %
                (to_version, char))

            for subChar, motionPath, scriptPath, mscsbPath in getProcessList(
                    char, from_version):
                print "\t", char, subChar
                ''' Parse ANIMCMD '''
                if os.path.isfile(motionPath % (to_version)):

                    f = open(motionPath % (to_version), "rb")
                    printedAnything = False
                    outdir = "processed/animcmd/diff-%s-%s/" % (from_version,
                                                                to_version)
                    if not os.path.isdir(outdir):
                        os.makedirs(outdir)

                    if subChar == "":
                        logfn = outdir + char + ".html"
                    else:
                        logfn = outdir + char + "_" + subChar + ".html"
                    log = open(logfn, "w")
                    log.write("""<style type="text/css">
        .diff {
            border: 1px solid #cccccc;
            background: none repeat scroll 0 0 #f8f8f8;
            font-family: 'Bitstream Vera Sans Mono','Courier',monospace;
            font-size: 12px;
            line-height: 1.4;
            white-space: normal;
            word-wrap: break-word;
        }
        .diff div:hover {
            background-color:#ffc;
        }
        .diff .control {
            background-color: #eaf2f5;
            color: #999999;
        }
        .diff .insert {
            background-color: #ddffdd;
            color: #000000;
        }
        .diff .insert .highlight {
            background-color: #aaffaa;
            color: #000000;
        }
        .diff .delete {
            background-color: #ffdddd;
            color: #000000;
        }
        .diff .delete .highlight {
            background-color: #ffaaaa;
            color: #000000;
        }
    </style>""")
                    from_animcmd = defaultdict(str)
                    for tmp in ["game", "effect", "sound", "expression"]:
                        from_animcmd[tmp] = parseACMD(
                            (scriptPath + "%s.bin") % (from_version, tmp))
                    to_animcmd = defaultdict(str)
                    for tmp in ["game", "effect", "sound", "expression"]:
                        to_animcmd[tmp] = parseACMD(
                            (scriptPath + "%s.bin") % (to_version, tmp))
                    i = 0

                    while True:
                        test = f.read(4)
                        if len(test) != 4:
                            break
                        t, = struct.unpack(">I", test)
                        if t in lookup:
                            name = lookup[t]
                        else:
                            name = ""
                        printedHeader = False

                        f_p = f_params[0][i * 6:i * 6 + 6]
                        t_p = t_params[0][i * 6:i * 6 + 6]
                        if len(f_p) == 6:
                            f_p = "{{{0}, {1}, IASA?={2}, {3}, {4}, {5}}}".format(
                                *f_p)
                        else:
                            f_p = ""

                        if len(t_p) == 6:
                            t_p = "{{{0}, {1}, IASA?={2}, {3}, {4}, {5}}}".format(
                                *t_p)
                        else:
                            t_p = ""
                        if f_p != t_p:
                            printedAnything = True
                            if not printedHeader:

                                log.write(
                                    "<h2 class='toc'>%03X - %s - %08X</h2>\n" %
                                    (i, name, t))
                                printedHeader = True
                                log.write(
                                    "<h4>%s</h4>\n%s\n" %
                                    ("params",
                                     ghdiff.diff(
                                         repr(f_p), repr(t_p), css=False)))
                        for tmp in ["game", "effect", "sound", "expression"]:
                            ff = ""
                            tt = ""
                            if t in from_animcmd[tmp]:
                                ff = from_animcmd[tmp][t].split("\n")
                            if t in to_animcmd[tmp]:
                                tt = to_animcmd[tmp][t].split("\n")
                            if ff != tt:
                                printedAnything = True
                                if not printedHeader:
                                    log.write(
                                        "<h2 class='toc'>%03X - %s - %08X</h2>\n"
                                        % (i, name, t))
                                    printedHeader = True
                                o = ""
                                o = ghdiff.diff(ff, tt, css=False)
                                #for line in difflib.unified_diff(ff,tt):
                                #    o += line
                                #    o += "\n"
                                log.write("<h4>%s</h4>\n%s\n" % (tmp, o))
                        i += 1
                    size = log.tell()

                    log.close()
                    if not printedAnything:
                        os.remove(logfn)
Exemplo n.º 37
0
def paste_view(url, flag=None, ext=None):
    SESSION = request.environ.get('beaker.session', {})

    # Extract the commit from the URL, if it exists.
    if '.' in url:
        url = url.split('.')
        commit = url[-1]
        url = url[0]
    else:
        commit = False

    # Select the paste from `files`
    results = config.db.fetchone(
        'SELECT * FROM `files` WHERE BINARY `shorturl` = %s', [url])

    if results:
        paste_row = config.db.select(
            'pastes', where={'id': results['original']}, singular=True)

        if not paste_row:
            print('Deleting a paste that was not found...')
            # config.db.execute(
            #     'DELETE FROM `files` WHERE `id` = %s', [results['id']])
            config.db.delete('files', {'id': results['id']})
            abort(404, 'File not found.')

        # Select every revision for specified paste
        revisions_rows = config.db.select(
            'revisions', where={'pasteid': paste_row['id'], 'fork': 0})

        # Add a hit to the paste
        config.db.execute(
            'UPDATE `files` SET hits=hits+1 WHERE `id`=%s', [results['id']])

        # Decide whether the viewer owns this file (for forking or editing)
        is_owner = (paste_row['userid'] == SESSION.get('id', 0))

        # If a commit is provided, get the row for that revision
        if commit:
            revisions_row = config.db.select(
                'revisions', where={'commit': commit}, singular=True)
        else:
            revisions_row = None

        # Add the base commit in by default
        commits = ['base']

        # Append every commit which exists
        if revisions_rows:
            for row in revisions_rows:
                commits.append(row['commit'])

        # Check if the commit exists in the commits list
        if commit in commits:
            current_commit = commits.index(commit)
            current_commit = commits[
                current_commit - 1 if current_commit - 1 >= 0 else 0]
        else:
            current_commit = commits[0]

        # Disable the ability to use diff on the base commit only
        if current_commit == 'base' and commit == '' and flag == 'diff':
            flag = ''

        # Function to get the previous commit from the database for diffs
        def previous_commit():
            if current_commit != 'base':
                return config.db.select('revisions', where={'commit': current_commit}, singular=True)['paste']
            else:
                return config.db.select('pastes', where={'id': paste_row['id']}, singular=True)['content']

        # If the user provided the raw flag, skip all HTML rendering
        if flag == 'raw':
            response.content_type = 'text/plain; charset=utf-8'
            return revisions_row['paste'] if commit else paste_row['content']
        else:
            revision = {}

            # Check if the paste has a name, and show the name if it does.
            if paste_row['name']:
                title = f'Paste "{paste_row["name"]}" ({url})'
            else:
                title = f'Paste {url}'

            lang = paste_row['lang']

            # Check if to make a diff or not,
            # depending on if the revision exists
            if revisions_row:
                if flag == 'diff':
                    prev_commit = previous_commit()

                    # Render the diff without CSS, so I can edit it easier
                    paste_row['content'] = ghdiff.diff(
                        prev_commit, revisions_row['paste'], css=False)
                    lang = 'diff'
                else:
                    paste_row['content'] = revisions_row['paste']

                revision = revisions_row

                # Add the parent pastes URL to the revision's data.
                revision['parent_url'] = config.db.select(
                    'pastes', where={'id': revision['parent']}, singular=True)['shorturl']

                title += f' (revision {revision["commit"]})'

            # Decide whether to wrap the response in an extra element
            use_wrapper = not (flag == 'diff' and commit in commits)

            if not use_wrapper:
                content = paste_row['content']
            else:
                content = functions.highlight(
                    paste_row['content'], lang)

            # Get meta data about the pastes
            length = len(paste_row['content'])
            lines = len(paste_row['content'].split('\n'))
            hits = results['hits']

            # Get the styles for syntax highlighting
            css = functions.css()

            # Generate a key and password for the edit form
            if SESSION.get('id'):
                key = SESSION.get('key')
                password = SESSION.get('password')
            else:
                key = functions.id_generator(15)
                password = functions.id_generator(15)

            # Decide if the paste should be in edit/fork mode or not
            edit = (flag == 'edit')

            # Provide the template with a mass of variables
            return template('paste', title=title, content=content, css=css,
                            url=url, lang=lang, length=length,
                            hits=hits, lines=lines, edit=edit,
                            raw_paste=paste_row['content'], is_owner=is_owner,
                            key=key, password=password, id=paste_row['id'],
                            revisions=revisions_rows, revision=revision,
                            flag=flag, _commit=commit, commits=commits,
                            use_wrapper=use_wrapper)
    else:
        abort(404, 'File not found.')
Exemplo n.º 38
0
    SINGLE_SHEET_NAME,
    SINGLE_SHEET_STATIC_HEADERS,
)
from corehq.apps.translations.exceptions import BulkAppTranslationsException
from corehq.apps.translations.generators import (
    AppTranslationsGenerator,
    Unique_ID,
)

COLUMNS_TO_COMPARE = {
    'module_and_form': ['Type', 'menu_or_form'],
    'module': ['case_property', 'list_or_detail'],
    'form': ['label'],
}
# return from ghdiff in case of no differences
NO_GHDIFF_MESSAGE = ghdiff.diff([], [], css=False)


class UploadedTranslationsValidator(object):
    """
    this compares the excel sheet uploaded with translations with what would be generated
    with current app state and flags any discrepancies found between the two
    """
    def __init__(self,
                 app,
                 uploaded_workbook,
                 lang_to_compare,
                 lang_prefix='default_'):
        self.app = app
        self.uploaded_workbook = uploaded_workbook
        self.uploaded_headers = dict()  # sheet_name: list of headers
Exemplo n.º 39
0
 def compare(self, name, old_sha, new_sha):
     old = self.get_page(name, sha=old_sha)
     new = self.get_page(name, sha=new_sha)
     return ghdiff.diff(old['data'], new['data'])
Exemplo n.º 40
0
    def get_context(self, context):
        self.verify_permission("read")

        wiki_settings = frappe.get_single("Wiki Settings")
        context.banner_image = wiki_settings.logo
        context.home_route = "wiki"
        context.docs_search_scope = "wiki"
        context.can_edit = frappe.session.user != "Guest"
        context.no_cache = 1

        if frappe.form_dict:
            context.parents = [{
                "route": "/" + self.route,
                "label": self.title
            }]
            context.add_breadcrumbs = True

        if frappe.form_dict.new:
            self.verify_permission("create")
            context.title = "New Wiki Page"
            return

        if frappe.form_dict.edit:
            self.verify_permission("write")
            context.title = "Editing " + self.title
            return

        if frappe.form_dict.revisions:
            context.title = "Revisions: " + self.title
            revisions = frappe.db.get_all(
                "Wiki Page Revision",
                filters={"wiki_page": self.name},
                fields=["message", "creation", "owner", "name"],
            )
            context.revisions = revisions
            return

        if frappe.form_dict.compare:
            from ghdiff import diff

            revision = frappe.form_dict.compare
            context.title = "Revision: " + revision
            context.parents = [
                {
                    "route": "/" + self.route,
                    "label": self.title
                },
                {
                    "route": "/" + self.route + "?revisions=true",
                    "label": "Revisions"
                },
            ]

            revision = frappe.get_doc("Wiki Page Revision", revision)

            context.revision = revision
            previous_revision_content = frappe.db.get_value(
                "Wiki Page Revision",
                filters={
                    "creation": ("<", revision.creation),
                    "wiki_page": self.name
                },
                fieldname=["content"],
                order_by="creation asc",
            )

            if not previous_revision_content:
                return

            context.diff = diff(previous_revision_content,
                                revision.content,
                                css=False)
            return

        context.metatags = {"title": self.title}
        sidebar = frappe.db.get_single_value("Wiki Settings", "sidebar")
        context.sidebar_items = frappe.get_doc("Website Sidebar",
                                               sidebar).get_items()
        context.last_revision = self.get_last_revision()
        context.number_of_revisions = frappe.db.count("Wiki Page Revision",
                                                      {"wiki_page": self.name})
        html = frappe.utils.md_to_html(self.content)
        context.content = html
        context.page_toc_html = html.toc_html
Exemplo n.º 41
0
def diff_rst(actual_rst, expected_rst):
    return ghdiff.diff(actual_rst.text, expected_rst.text)