file('metric/MultiplyNestedContainer.csv', 'wb')) MultiplyNestedContainer.writerow( ['subject', 'tag', 'file', 'lineno', 'LEC', 'DNC', 'NCT']) for name in directory.keys(): sourcedir = subject_dir + name + '/' + name tag = directory[name] # tags = [] # with open(subject_dir+name+'/tags') as f: # for line in f: # tags.append(line.strip()) # tag = tags[-1] # print name,tag # util.changegittag(sourcedir,tag) # time.sleep(3) for currentFileName in util.walkDirectory(sourcedir): try: astContent = customast.parse_file(currentFileName) except: print name, tag, currentFileName continue myast = astChecker.MyAst() myast.fileName = currentFileName myast.visit(astContent) # res = util.execute(currentFileName) #5,2,3 # if len(res) > 0: # myast.result = myast.result + res for item in myast.result: if item[0] == 1: PAR.append(item[3]) LongParameter.writerow([name, tag, item[1], item[2], item[3]])
h = {1: LongParameterList, 2: LongMethod, 3: LongScopeChaining, 4: LongBaseClassList, 5: LargeClass, 6:MultiplyNestedContainer,7: UselessExceptionHandling, 8:UnusedImport, 9: ComplexLambdaExpression, 10: LongTernaryConditionalExpression, 11: ComplexContainerComprehension, 12: ViolatedMagicMethod, 13: LongMessageChain} name = {1: 'LongParameterList', 2: 'LongMethod', 3: 'LongScopeChaining', 4: 'LongBaseClassList', 5: 'LargeClass', 6:'MultiplyNestedContainer', 7: 'UselessExceptionHandling', 8:'UnusedImport', 9: 'ComplexLambdaExpression', 10: 'LongTernaryConditionalExpression', 11: 'ComplexContainerComprehension', 12: 'ViolatedMagicMethod', 13: 'LongMessageChain'} count = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0} myast = astChecker.MyAst() # time.sleep(3) util.changegittag(sourcedir,tag) time.sleep(3) filenum = 0 for currentFileName in util.walkDirectory(sourcedir): filenum = filenum + 1 try: astContent = customast.parse_file(currentFileName) except: logfile.write(currentFileName+"\n") continue myast.fileName = currentFileName myast.visit(astContent) res = util.execute(currentFileName) if len(res) > 0: myast.result = myast.result + res usedImports = util.usedImports(currentFileName,myast.imports) for defitem in myast.imports: for useitem in usedImports: if useitem == defitem[0]: