def commandLineMain(args, targets, objectDir): distribution = eval(args.distribution) moduleConformanceSet = ModuleSetConformanceContainer() summary = args.summary average = args.average finegrain = args.finegrain if not (summary or average or finegrain): summary = True objectDirs = [objectDir] for i in range(len(targets)): module = Module(targets[i], objectDirs) prefix = module.getModuleName() path = module.getModulePath() tb = None try: moduleConformance = computeModuleConformance(module) if not moduleConformance.processModule(): print >> sys.stderr, "Skipping module " + str( prefix) + ": contains a `main` function" else: moduleConformanceSet.addConformanceContainer(moduleConformance) if summary: if args.output == "text": writeListToStream( moduleConformance.summaryText(distribution), sys.stdout) else: writeListToStream(moduleConformance.summaryCSV(), sys.stdout) if finegrain: if args.output == "text": writeListToStream( moduleConformance.totalText(distribution), sys.stdout) else: writeListToStream(moduleConformance.totalCSV(), sys.stdout) except Exception as e: tb = traceback.format_exc() print >> sys.stderr, "Error: can't analyze conformance of " + os.path.join( path, prefix) + ": " + str(e) finally: if tb != None and args.trace: print tb pass moduleConformanceSet.analyzeConformance() if average: if args.output == "text": writeListToStream(moduleConformanceSet.summaryText(distribution), sys.stdout) else: writeListToStream(moduleConformanceSet.summaryCSV(), sys.stdout)
def gradeAndPrint(targets, problemsOnly=False, printPrefix=""): if len(targets) < 1: print "No Files To Grade" return distribution = [99, 90] maxFileNameLength = max(max(map(lambda target: len(target), targets)), len("File Name")) moduleConformanceSet = ModuleSetConformanceContainer() headers = getConformanceHeaders() pformat = '{prefix}{:<{maxFileNameLength}}' nformat = pformat for header in headers: nformat = nformat + '{:>15}' print nformat.format('File Name', *headers, prefix=printPrefix, maxFileNameLength=maxFileNameLength) for target in targets: module = Module(target) if module.isTestSourceName(): continue fileNamePrefix = module.getModuleName() path = module.getModulePath() try: moduleConformance = computeModuleConformance(path, fileNamePrefix) if not moduleConformance.processModule(): pass else: moduleConformanceSet.addConformanceContainer(moduleConformance) scores = moduleConformance.getScores() minScore = 100.0 for key in scores: score = scores[key] if score < minScore: minScore = score scores[key] = '%3.1f'%score if problemsOnly and minScore == 100.0: continue printVals=[] for hval in headers: score = 'N/A' if hval in scores: score = scores[hval] printVals.append(score) line = nformat.format(target, *printVals, prefix=printPrefix, maxFileNameLength=maxFileNameLength) LongBow.scorePrinter(distribution, minScore, line) except NoObjectFileException as e: eformat = pformat + "Could Not Grade: No .o file found for file" line = eformat.format(target, prefix=printPrefix, maxFileNameLength=maxFileNameLength, msg=e) print LongBow.buildRed(line) pass except Exception as e: eformat = pformat + "Could Not Grade: {msg}" line = eformat.format(target, prefix=printPrefix, maxFileNameLength=maxFileNameLength, msg=e) print LongBow.buildRed(line) pass moduleConformanceSet.analyzeConformance()
def commandLineMain(args, targets, objectDir): distribution = eval(args.distribution) moduleConformanceSet = ModuleSetConformanceContainer() summary = args.summary average = args.average finegrain = args.finegrain if not (summary or average or finegrain): summary = True objectDirs = [objectDir] for i in range(len(targets)): module = Module(targets[i], objectDirs) prefix = module.getModuleName() path = module.getModulePath() tb = None try: moduleConformance = computeModuleConformance(module) if not moduleConformance.processModule(): print >> sys.stderr, "Skipping module " + str(prefix) + ": contains a `main` function" else: moduleConformanceSet.addConformanceContainer(moduleConformance) if summary: if args.output == "text": writeListToStream(moduleConformance.summaryText(distribution), sys.stdout) else: writeListToStream(moduleConformance.summaryCSV(), sys.stdout) if finegrain: if args.output == "text": writeListToStream(moduleConformance.totalText(distribution), sys.stdout) else: writeListToStream(moduleConformance.totalCSV(), sys.stdout) except Exception as e: tb = traceback.format_exc() print >> sys.stderr, "Error: can't analyze conformance of " + os.path.join(path, prefix) + ": " + str(e) finally: if tb != None and args.trace: print tb pass moduleConformanceSet.analyzeConformance() if average: if args.output == "text": writeListToStream(moduleConformanceSet.summaryText(distribution), sys.stdout) else: writeListToStream(moduleConformanceSet.summaryCSV(), sys.stdout)
def gradeAndPrint(targets, objectDirs, problemsOnly=False, printPrefix=""): if len(targets) < 1: print "No Files To Grade" return distribution = [99, 90] maxFileNameLength = max(max(map(lambda target: len(target), targets)), len("File Name")) moduleConformanceSet = ModuleSetConformanceContainer() headers = getConformanceHeaders() pformat = '{prefix}{:<{maxFileNameLength}}' nformat = pformat for header in headers: nformat = nformat + '{:>15}' print nformat.format('File Name', *headers, prefix=printPrefix, maxFileNameLength=maxFileNameLength) for target in targets: module = Module(target, objectDirs) if module.isTestSourceName(): continue fileNamePrefix = module.getModuleName() path = module.getModulePath() try: moduleConformance = computeModuleConformance(module) if not moduleConformance.processModule(): pass else: moduleConformanceSet.addConformanceContainer(moduleConformance) scores = moduleConformance.getScores() minScore = 100.0 for key in scores: score = scores[key] if score < minScore: minScore = score scores[key] = '%3.1f' % score if problemsOnly and minScore == 100.0: continue printVals = [] for hval in headers: score = 'N/A' if hval in scores: score = scores[hval] printVals.append(score) line = nformat.format(target, *printVals, prefix=printPrefix, maxFileNameLength=maxFileNameLength) LongBow.scorePrinter(distribution, minScore, line) except NoObjectFileException as e: eformat = pformat + "Could Not Grade: No .o file found for file" line = eformat.format(target, prefix=printPrefix, maxFileNameLength=maxFileNameLength, msg=e) print LongBow.buildRed(line) pass except Exception as e: eformat = pformat + "Could Not Grade: {msg}" line = eformat.format(target, prefix=printPrefix, maxFileNameLength=maxFileNameLength, msg=e) print LongBow.buildRed(line) pass moduleConformanceSet.analyzeConformance()