Example #1
0
    def get_page(self,arch,source_version,target_version,path):
        if path == '' or path == '/':
            return self.ChangeSet(arch,source_version,target_version)
        out = ''
        diffable = is_diffable(path)

        if not diffable:
            return 'Sorry, this file is not diffable'
        arches = self.request.get('arches')
        if arches:
            oarch,narch = (int(_) for _ in arches.split('|')[:2])
        else:
            oarch = version_arch(source_version)
            narch = version_arch(target_version)
        odata = fetcher.fetch(oarch,source_version,path)
        ndata = fetcher.fetch(narch,target_version,path)
        if odata is None:
            out += ('Sorry, could not fetch file %s for version %s.<br>' % \
                    (source_version,path))
        elif ndata is None:
            out += ('Sorry, could not fetch file %s for version %s.<br>' % \
                    (target_version,path))
        else:
            odata = odata.read()
            ndata = ndata.read()
            try:
                odata = odata.decode('utf8')
            except:
                odata = odata.decode('cp1251')

            try:
                ndata = ndata.decode('utf8')
            except:
                ndata = ndata.decode('cp1251')
            #return htmldiff.make_table(odata.splitlines(),ndata.splitlines())

            out += ('<div class="unified_diff">')
            out += ("<pre>")
            diff = unified_diff(odata.splitlines(),ndata.splitlines(),fromfile=source_version,tofile=target_version)
            prevdiv = ' '
            divs = { ' ' : '', '+' : 'add' , '-' : 'del' , '@' : 'linenum'}
            curdiv = ''
            for l in diff:
                line = escape(l)
                curdiv = line[0]

                if curdiv != prevdiv:
                    if prevdiv != ' ':
                        out += ('</div>')
                    if curdiv != ' ':
                        out += ('<div class="%s">' % divs[curdiv])
                out += (escape(l))
                out += ("\n")
                prevdiv = curdiv
            if curdiv != ' ':
                out += ('</div>')
            out += ("</div>")
            out += ("\n</pre>")
        return out
Example #2
0
    def get_page(self, arch, version, path):
        lang = self.request.query_string
        if lang == "":
            lang = "text"
        if not is_diffable(path):
            return "Sorry, viewing this types of files is not allowed"
        data = fetcher.fetch(arch, version, path)
        if data is None:
            self.response.out.write("Sorry, could not fetch file %s for version %s.<br>" % (version, path))
            return None
        else:
            data = data.read()
            try:
                data = data.decode("utf8")
            except:
                data = data.decode("cp1251")

            template_values = {"data": pygmentize(lang, data)}

            template = get_template("highlight.html")
            return template.render(template_values)