示例#1
0
    def process_clone(self):
        rep_output = RepertoireOutput()
        print self.repOutputPath
        rep_output.loadFromFile(self.repOutputPath, 1)

        for index, fileName in rep_output.getFileIter():
            if config.DEBUG == 2:
                print "fileName =" + fileName
            self.fileList.append(fileName)
            listItem = QtGui.QTreeWidgetItem(self.ui.fileList)
            listItem.setText(0, str(index))
            listItem.setText(1, fileName)

        for indx, (cl1, cl2, metric) in rep_output.getCloneIter():
            fidx1, start1, end1 = cl1
            fidx2, start2, end2 = cl2
            metric = int(metric)
            #            metric = max(end1 - start1, end2 - start2)

            if (config.DEBUG == 2):
                print line
                print indx + " " + cl1 + " " + cl2
                print metric

            if metric:
                listItem = QtGui.QTreeWidgetItem(self.ui.cloneList)
                listItem.setText(0, str(indx))
                listItem.setText(
                    1,
                    "{0}.{1}-{2}\t{3}.{4}-{5}".format(fidx1, start1, end1,
                                                      fidx2, start2, end2))
                listItem.setText(2, str(metric))
示例#2
0
def convert_ccfx_output(pb, proj, lang, is_new):
    metaDB = CCFXMetaMapping()
    # maps from ccfx input paths to meta objects representing the files
    #for proj in [PathBuilder.PROJ0, PathBuilder.PROJ1]:
    filter_path = pb.getFilterOutputPath(proj, lang)
    conv_path = pb.getLineMapPath(proj, lang, is_new)
    ccfx_i_path = pb.getCCFXInputPath(proj, lang, is_new)
    ccfx_p_path = pb.getCCXFPrepPath(proj, lang, is_new)
    print "filter_path = " + filter_path
    print "conv_path = " + conv_path
    print "ccfx_i_path = " + ccfx_i_path
    print "ccfx_p_path = " + ccfx_p_path
    for name in os.listdir(filter_path):
        meta = CCFXMetaData(
            ccfx_i_path + name,
            ccfx_p_path + pb.findPrepFileFor(ccfx_p_path, name),
            conv_path + pb.makeLineMapFileName(name), filter_path + name)
        metaDB.addFile(meta)

    print metaDB
    # we have our files, now map line numbers in the prep files to input files
    for meta in metaDB.getMetas():

        if config.DEBUG is False:
            print "prep file = " + meta.ccfxPrep
            print "conv file = " + meta.filterConv

        prepHandler = open(meta.ccfxPrep, 'r')
        prep = prepHandler.readlines()
        prepHandler.close()

        convHandler = open(meta.filterConv, 'r')
        conv = convHandler.readlines()
        convHandler.close()

        input2orig = {}
        pidx2orig = {}
        origline2op = {}
        # build a map of line numbers in ccfx_input to filtered diff line
        for i, cline in enumerate(conv):
            if i < 2:
                continue
            if cline.rstrip().startswith('"'):  #filename-->skip the line
                continue

            dstIdx, srcIdx, op, changId = cline.split(',')
            input2orig[int(dstIdx)] = int(srcIdx)
            origline2op[int(srcIdx)] = op
        for pidx, pline in enumerate(prep):
            inputIdx = int(pline.partition(".")[0], 16)
            # ccfx numbers from 1, but pidx is from 0
            pidx2orig[pidx + 1] = input2orig.get(inputIdx, -1)
        meta.prepIdx2OrigIdx = pidx2orig
        meta.line2op = origline2op

    ccfx_out_path = pb.getCCFXOutputPath() + pb.getCCFXOutputFileName(
        lang, is_new, is_tmp=False)
    ccfx_out = RepertoireOutput()
    ccfx_out.loadFromFile(ccfx_out_path)

    files = {}
    for fileIdx, path in ccfx_out.getFileIter():
        print fileIdx
        print path
        if not metaDB.hasInputPath(path):
            raise Exception(
                "Couldn't find meta information for file: {0}".format(path))
        print ">>>>>>> " + path
        meta = metaDB.getMetaForPath(path)
        files[fileIdx] = meta.filterOutput

    clones = {}

    for cloneIdx, (clone1, clone2) in ccfx_out.getCloneIter():
        op1 = []
        op2 = []
        fidx1, start1, end1 = clone1
        fidx2, start2, end2 = clone2
        meta1 = metaDB.getMetaForPath(ccfx_out.getFilePath(fidx1))
        meta2 = metaDB.getMetaForPath(ccfx_out.getFilePath(fidx2))

        start1 = meta1.prepIdx2OrigIdx.get(start1 + 1, -1)
        end1 = meta1.prepIdx2OrigIdx.get(end1, -1)
        start2 = meta2.prepIdx2OrigIdx.get(start2 + 1, -1)
        end2 = end2 = meta2.prepIdx2OrigIdx.get(end2, -1)

        for i in range(start1, end1 + 1):
            op = meta1.line2op.get(i, "X")
            op1.append((i, op))

        for i in range(start2, end2 + 1):
            op = meta2.line2op.get(i, "X")
            op2.append((i, op))

        clone1 = (fidx1, start1, end1, op1)
        clone2 = (fidx2, start2, end2, op2)
        if clone1[0] < clone2[0]:
            clone = (clone1, clone2)
        else:
            clone = (clone2, clone1)
        clones[cloneIdx] = clone

    rep_out = RepertoireOutput()
    rep_out.loadFromData(files, clones)
    return rep_out
示例#3
0
        # ccfx numbers from 1, but pidx is from 0
        pidx2orig[pidx + 1] = input2orig.get(inputIdx, -1)
    meta.prepIdx2OrigIdx = pidx2orig
    meta.line2op = origline2op

print 'map line number finished'
# write all keys in metaDB to a new file
metaDB_key_file = 'metaDB_key_file.txt'
with open(metaDB_key_file, 'w') as f:
    for key in metaDB.name2meta.keys():
        f.write(key+'\n')
print 'write key finished'


ccfx_out_path = 'cross_file.txt'
ccfx_out = RepertoireOutput()
print 'load clone data from file starts...'
ccfx_out.loadFromFile(ccfx_out_path)
print 'load clone data from file ends...'
print 'parsed files: ', len(ccfx_out.files)
print 'parsed clones: ', len(ccfx_out.clones)


files = {}
for fileIdx, path in ccfx_out.getFileIter():
#    print fileIdx
#    print path
    if not metaDB.hasInputPath(path):
        print "Couldn't find meta information for file: ", path
	sys.exit(-1)
    meta = metaDB.getMetaForPath(path)