Beispiel #1
0
    def ResLogCompare(self, logName, leftName, left, rightName, right, only_diff = True):
        try:
            with codecs.open(left+'/'+logName, encoding='utf-8', mode='rb') as leftf:
                leftlog = leftf.readlines()
                leftf.close()
        except Exception as e:
            leftlog =["No %s file found!" % logName]
        try:
            with codecs.open(right+'/'+logName, encoding='utf-8', mode='rb') as rightf:
                rightlog = rightf.readlines()
                rightf.close()
        except Exception as e:
            rightlog =["No %s file found!" % logName]
        errorWords = logdiffutil.getErrorWords('./data/rules/errorwords')
        packageDict = logdiffutil.buildPackageDict('./data/rules/LinuxPackageList')
        lefttext = ""
        for line in leftlog:
            text = (line.replace("&", "&")
                        .replace("<", "&lt;")
                        .replace(">", "&gt;"))
            text = logdiffutil.renderline(text, errorWords, packageDict, 'left')
            lefttext = lefttext + text

        righttext = ""
        for line in rightlog:
            text = (line.replace("&", "&amp;")
                        .replace("<", "&lt;")
                        .replace(">", "&gt;"))
            text = logdiffutil.renderline(text, errorWords, packageDict, 'right')
            righttext = righttext + text

        diff_obj = diff_match_patch.diff_match_patch()
        diffs = diff_obj.diff_main(lefttext, righttext)
        diff_obj.diff_cleanupSemantic(diffs)

        left_content = []
        right_content = []
        for (flag, data) in diffs:
            text = data.replace("\n", "<br>")

            if flag == diff_obj.DIFF_DELETE:
                # left_content.append("""<font style=\"background:#aaaaff;\">%s</font>""" % text)
                left_content.append("""%s""" % text)
            elif flag == diff_obj.DIFF_INSERT:
                #right_content.append("""<font style=\"background:#e6ffe6;\">%s</font>""" % text)
                right_content.append("""%s""" % text)
            elif flag == diff_obj.DIFF_EQUAL:
                left_content.append("%s" % text)
                right_content.append("%s" % text)

        leftres={}
        rightres={}
        leftres['diff'] = "".join(left_content)
        rightres['diff'] = "".join(right_content)

        res = {
                "diff": { leftName: leftres["diff"], rightName: rightres["diff"] },
                "results": {}
              }
        return res
Beispiel #2
0
def getlogdiff():
    file1=request.args.get('file1','')
    file2=request.args.get('file2','')

    if len(file1) == 0 or not allowed_file(file1) or len(file2) == 0 or not allowed_file(file2):
        return render_template('fileerror.html')

    leftf = codecs.open(file1,encoding='utf-8',mode='rb')
    leftlog = leftf.readlines()
    leftf.close()

    rightf = codecs.open(file2,encoding='utf-8',mode='rb')
    rightlog = rightf.readlines()
    rightf.close()

    errorWords = logdiffutil.getErrorWords('../data/rules/errorwords')
    packageDict = logdiffutil.buildPackageDict('../data/rules/LinuxPackageList')

    lefttext = ""
    for line in leftlog:
        text = (line.replace("&", "&amp;")
                    .replace("<", "&lt;")
                    .replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        lefttext = lefttext + text

    righttext = ""
    for line in rightlog:
        text = (line.replace("&", "&amp;")
                    .replace("<", "&lt;")
                    .replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        righttext = righttext + text

    diff_obj = diff_match_patch.diff_match_patch()
    diffs = diff_obj.diff_main(lefttext, righttext)
    diff_obj.diff_cleanupSemantic(diffs)

    left_content = []
    right_content = []
    for (flag, data) in diffs:
        text = data.replace("\n", "<br>")

        if flag == diff_obj.DIFF_DELETE:
            left_content.append("""<font style=\"background:#ceceff;\">%s</font>""" % text)
            #left_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_INSERT:
            right_content.append("""<font style=\"background:#e6ffe6;\">%s</font>""" % text)
            #right_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_EQUAL:
            left_content.append("%s" % text)
            right_content.append("%s" % text)

    return render_template('output.html', leftname=file1, rightname=file2, left_content="".join(left_content), right_content="".join(right_content))
Beispiel #3
0
def getTextDiffResults():
    leftlog = request.form['text1']
    rightlog = request.form['text2']

    errorWords = logdiffutil.getErrorWords('../data/rules/errorwords')
    packageDict = logdiffutil.buildPackageDict(
        '../data/rules/LinuxPackageList')

    lefttext = ""
    leftlines = re.split(r"(\r|\n)+", leftlog)
    for line in leftlines:
        text = (line.replace("&",
                             "&amp;").replace("<",
                                              "&lt;").replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        lefttext = lefttext + text

    righttext = ""
    rightlines = re.split(r"(\r|\n)+", rightlog)
    for line in rightlines:
        text = (line.replace("&",
                             "&amp;").replace("<",
                                              "&lt;").replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        righttext = righttext + text

    diff_obj = diff_match_patch.diff_match_patch()
    diffs = diff_obj.diff_main(lefttext, righttext)
    diff_obj.diff_cleanupSemantic(diffs)

    left_content = []
    right_content = []
    for (flag, data) in diffs:
        text = data.replace("\n", "<br>")
        if flag == diff_obj.DIFF_DELETE:
            left_content.append(
                """<font style=\"background:#ceceff;\">%s</font>""" % text)
            # left_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_INSERT:
            right_content.append(
                """<font style=\"background:#e6ffe6;\">%s</font>""" % text)
            #right_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_EQUAL:
            left_content.append(text)
            right_content.append(text)

    return json.jsonify(status="ok",
                        leftname="text fragment1",
                        rightname="text fragment2",
                        leftcontent="".join(left_content),
                        rightcontent="".join(right_content))
Beispiel #4
0
def getTextDiffResults():
    leftlog = request.form['text1']
    rightlog = request.form['text2']

    errorWords = logdiffutil.getErrorWords('../data/rules/errorwords')
    packageDict = logdiffutil.buildPackageDict('../data/rules/LinuxPackageList')

    lefttext = ""
    leftlines = re.split(r"(\r|\n)+",leftlog)
    for line in leftlines:
        text = (line.replace("&", "&amp;")
                    .replace("<", "&lt;")
                    .replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        lefttext = lefttext + text

    righttext = ""
    rightlines = re.split(r"(\r|\n)+",rightlog)
    for line in rightlines:
        text = (line.replace("&", "&amp;")
                    .replace("<", "&lt;")
                    .replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        righttext = righttext + text

    diff_obj = diff_match_patch.diff_match_patch()
    diffs = diff_obj.diff_main(lefttext, righttext)
    diff_obj.diff_cleanupSemantic(diffs)

    left_content = []
    right_content = []
    for (flag, data) in diffs:
        text = data.replace("\n", "<br>")
        if flag == diff_obj.DIFF_DELETE:
            left_content.append("""<font style=\"background:#ceceff;\">%s</font>""" % text)
            # left_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_INSERT:
            right_content.append("""<font style=\"background:#e6ffe6;\">%s</font>""" % text)
            #right_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_EQUAL:
            left_content.append(text)
            right_content.append(text)

    return json.jsonify(status = "ok",
                    leftname = "text fragment1",
                    rightname = "text fragment2",
                    leftcontent = "".join(left_content),
                    rightcontent = "".join(right_content))
Beispiel #5
0
def getFileDiffResults():
    try:
        file1 = request.files['file1']
        file2 = request.files['file2']
    except KeyError:
        return json.jsonify(status="failure",
                    error="No File selected for upload"), 400

    path1 = os.path.dirname(os.path.abspath(__file__)) + "/uploads/file1"
    if not os.path.exists(path1):
        os.makedirs(path1)
    if file1 and allowed_file(file1.filename):
        fname1 = secure_filename(file1.filename)
        file1.save(os.path.join(path1, fname1))
    else:
        return json.jsonify(status="failure",
                error="Allowed file extensions are txt, log, cfg, arti, out"), 400

    path2 = os.path.dirname(os.path.abspath(__file__)) + "/uploads/file2"
    if not os.path.exists(path2):
        os.makedirs(path2)
    if file2 and allowed_file(file2.filename):
        fname2 = secure_filename(file2.filename)
        file2.save(os.path.join(path2, fname2))
    else:
        return json.jsonify(status="failure",
                error="Allowed file extensions are txt, log, cfg, arti,out"), 400


    leftf = codecs.open(path1+'/'+fname1,encoding='utf-8',mode='rb')
    leftlog = leftf.readlines()
    leftf.close()

    rightf = codecs.open(path2+'/'+fname2,encoding='utf-8',mode='rb')
    rightlog = rightf.readlines()
    rightf.close()

    errorWords = logdiffutil.getErrorWords('../data/rules/errorwords')
    packageDict = logdiffutil.buildPackageDict('../data/rules/LinuxPackageList')

    lefttext = ""
    for line in leftlog:
        text = (line.replace("&", "&amp;")
                    .replace("<", "&lt;")
                    .replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        lefttext = lefttext + text

    righttext = ""
    for line in rightlog:
        text = (line.replace("&", "&amp;")
                    .replace("<", "&lt;")
                    .replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        righttext = righttext + text

    diff_obj = diff_match_patch.diff_match_patch()
    diffs = diff_obj.diff_main(lefttext, righttext)
    diff_obj.diff_cleanupSemantic(diffs)

    left_content = []
    right_content = []
    for (flag, data) in diffs:
        text = data.replace("\n", "<br>")

        if flag == diff_obj.DIFF_DELETE:
            left_content.append("""<font style=\"background:#ceceff;\">%s</font>""" % text)
            #left_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_INSERT:
            right_content.append("""<font style=\"background:#e6ffe6;\">%s</font>""" % text)
            #right_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_EQUAL:
            left_content.append("%s" % text)
            right_content.append("%s" % text)

    return json.jsonify(status = "ok",
                leftname = fname1,
                rightname = fname2,
                leftcontent = "".join(left_content),
                rightcontent = "".join(right_content))
Beispiel #6
0
    def ResLogCompare(self,
                      logName,
                      leftName,
                      left,
                      rightName,
                      right,
                      only_diff=True):
        try:
            with codecs.open(left + '/' + logName, encoding='utf-8',
                             mode='rb') as leftf:
                leftlog = leftf.readlines()
                leftf.close()
        except Exception as e:
            leftlog = ["No %s file found!" % logName]
        try:
            with codecs.open(right + '/' + logName,
                             encoding='utf-8',
                             mode='rb') as rightf:
                rightlog = rightf.readlines()
                rightf.close()
        except Exception as e:
            rightlog = ["No %s file found!" % logName]
        errorWords = logdiffutil.getErrorWords('./data/rules/errorwords')
        packageDict = logdiffutil.buildPackageDict(
            './data/rules/LinuxPackageList')

        lefttext = ""
        for line in leftlog:
            text = (line.replace("&",
                                 "&amp;").replace("<",
                                                  "&lt;").replace(">", "&gt;"))
            text = logdiffutil.renderline(text, errorWords, packageDict)
            lefttext = lefttext + text

        righttext = ""
        for line in rightlog:
            text = (line.replace("&",
                                 "&amp;").replace("<",
                                                  "&lt;").replace(">", "&gt;"))
            text = logdiffutil.renderline(text, errorWords, packageDict)
            righttext = righttext + text

        diff_obj = diff_match_patch.diff_match_patch()
        diffs = diff_obj.diff_main(lefttext, righttext)
        diff_obj.diff_cleanupSemantic(diffs)

        left_content = []
        right_content = []
        for (flag, data) in diffs:
            text = data.replace("\n", "<br>")

            if flag == diff_obj.DIFF_DELETE:
                # left_content.append("""<font style=\"background:#aaaaff;\">%s</font>""" % text)
                left_content.append("""%s""" % text)
            elif flag == diff_obj.DIFF_INSERT:
                #right_content.append("""<font style=\"background:#e6ffe6;\">%s</font>""" % text)
                right_content.append("""%s""" % text)
            elif flag == diff_obj.DIFF_EQUAL:
                left_content.append("%s" % text)
                right_content.append("%s" % text)

        leftres = {}
        rightres = {}
        leftres['diff'] = "".join(left_content)
        rightres['diff'] = "".join(right_content)

        res = {
            "diff": {
                leftName: leftres["diff"],
                rightName: rightres["diff"]
            },
            "results": {}
        }
        return res
Beispiel #7
0
def getFileDiffResults():
    try:
        file1 = request.files['file1']
        file2 = request.files['file2']
    except KeyError:
        return json.jsonify(status="failure",
                            error="No File selected for upload"), 400

    path1 = os.path.dirname(os.path.abspath(__file__)) + "/uploads/file1"
    if not os.path.exists(path1):
        os.makedirs(path1)
    if file1 and allowed_file(file1.filename):
        fname1 = secure_filename(file1.filename)
        file1.save(os.path.join(path1, fname1))
    else:
        return json.jsonify(
            status="failure",
            error="Allowed file extensions are txt, log, cfg, arti, out"), 400

    path2 = os.path.dirname(os.path.abspath(__file__)) + "/uploads/file2"
    if not os.path.exists(path2):
        os.makedirs(path2)
    if file2 and allowed_file(file2.filename):
        fname2 = secure_filename(file2.filename)
        file2.save(os.path.join(path2, fname2))
    else:
        return json.jsonify(
            status="failure",
            error="Allowed file extensions are txt, log, cfg, arti,out"), 400

    leftf = codecs.open(path1 + '/' + fname1, encoding='utf-8', mode='rb')
    leftlog = leftf.readlines()
    leftf.close()

    rightf = codecs.open(path2 + '/' + fname2, encoding='utf-8', mode='rb')
    rightlog = rightf.readlines()
    rightf.close()

    errorWords = logdiffutil.getErrorWords('../data/rules/errorwords')
    packageDict = logdiffutil.buildPackageDict(
        '../data/rules/LinuxPackageList')

    lefttext = ""
    for line in leftlog:
        text = (line.replace("&",
                             "&amp;").replace("<",
                                              "&lt;").replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        lefttext = lefttext + text

    righttext = ""
    for line in rightlog:
        text = (line.replace("&",
                             "&amp;").replace("<",
                                              "&lt;").replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        righttext = righttext + text

    diff_obj = diff_match_patch.diff_match_patch()
    diffs = diff_obj.diff_main(lefttext, righttext)
    diff_obj.diff_cleanupSemantic(diffs)

    left_content = []
    right_content = []
    for (flag, data) in diffs:
        text = data.replace("\n", "<br>")

        if flag == diff_obj.DIFF_DELETE:
            left_content.append(
                """<font style=\"background:#ceceff;\">%s</font>""" % text)
            #left_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_INSERT:
            right_content.append(
                """<font style=\"background:#e6ffe6;\">%s</font>""" % text)
            #right_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_EQUAL:
            left_content.append("%s" % text)
            right_content.append("%s" % text)

    return json.jsonify(status="ok",
                        leftname=fname1,
                        rightname=fname2,
                        leftcontent="".join(left_content),
                        rightcontent="".join(right_content))
Beispiel #8
0
def getlogdiff():
    file1 = request.args.get('file1', '')
    file2 = request.args.get('file2', '')

    if len(file1) == 0 or not allowed_file(file1) or len(
            file2) == 0 or not allowed_file(file2):
        return render_template('fileerror.html')

    leftf = codecs.open(file1, encoding='utf-8', mode='rb')
    leftlog = leftf.readlines()
    leftf.close()

    rightf = codecs.open(file2, encoding='utf-8', mode='rb')
    rightlog = rightf.readlines()
    rightf.close()

    errorWords = logdiffutil.getErrorWords('../data/rules/errorwords')
    packageDict = logdiffutil.buildPackageDict(
        '../data/rules/LinuxPackageList')

    lefttext = ""
    for line in leftlog:
        text = (line.replace("&",
                             "&amp;").replace("<",
                                              "&lt;").replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        lefttext = lefttext + text

    righttext = ""
    for line in rightlog:
        text = (line.replace("&",
                             "&amp;").replace("<",
                                              "&lt;").replace(">", "&gt;"))
        text = logdiffutil.renderline(text, errorWords, packageDict)
        righttext = righttext + text

    diff_obj = diff_match_patch.diff_match_patch()
    diffs = diff_obj.diff_main(lefttext, righttext)
    diff_obj.diff_cleanupSemantic(diffs)

    left_content = []
    right_content = []
    for (flag, data) in diffs:
        text = data.replace("\n", "<br>")

        if flag == diff_obj.DIFF_DELETE:
            left_content.append(
                """<font style=\"background:#ceceff;\">%s</font>""" % text)
            #left_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_INSERT:
            right_content.append(
                """<font style=\"background:#e6ffe6;\">%s</font>""" % text)
            #right_content.append("""%s""" % text)
        elif flag == diff_obj.DIFF_EQUAL:
            left_content.append("%s" % text)
            right_content.append("%s" % text)

    return render_template('output.html',
                           leftname=file1,
                           rightname=file2,
                           left_content="".join(left_content),
                           right_content="".join(right_content))