def parseScope(data): global scopeCounter line = data.readline() lfile = None lline = None lid = None llocals = [] while line.startswith(">"): if line.startswith(">4"): parts = line.split("=") rawname = parts[0] rawtype = parts[1] lname = rawname[rawname.find("[") + 1:rawname.find("]")] ltype = rawtype[rawtype.find("[") + 1:rawtype.find("]")] llocals.append((lname, ltype)) else: value = line[line.find("[") + 1:line.find("]")] if line.startswith(">1"): lfile = value if line.startswith(">2"): lid = value line = data.readline() SQLiteSerializer.serializeScopeExecution(lfile, lid, llocals) scopeCounter = scopeCounter + 1 return line
def hydrateData(): # Hydrate data from GitHub API into Database if not SQLiteSerializer.isSetup: SQLiteSerializer.setup() skipped = [] for path, name in database_repos: data = Miner.getRepodataUrl(path) if data == False: logging.info("Skipping Repodata hydrating for " + name) skipped.append(name) elif type(data) == dict: logging.info("Hydrating " + name) SQLiteSerializer.serializeRepoData(name, data) logging.info("Skipped total hydration of " + str(len(skipped)) + " Repositories.") logging.info(str(skipped))
def transformCode(code, filename, reponame): try: tree = None try: tree = ast.parse(code) except: return code SQLiteSerializer.serializeFileTransformation(reponame, filename) relocator = RelocateLambdas(filename) result = relocator.visit(tree) functions = relocator.getMethods() function_setter = FunctionSetter(functions, relocator.getGlobalVars()) final_code = function_setter.visit(result) except: logging.warning("Could not transform file " + str(filename)) return code return to_source(final_code)
def parseLambda(data): line = data.readline() lfile = None lid = None lname = None ltype = None while line.startswith(">"): value = line[line.find("[") + 1:line.find("]")] if line.startswith(">1"): lfile = value if line.startswith(">2"): lid = value if line.startswith(">3"): lname = value if line.startswith(">4"): ltype = value line = data.readline() SQLiteSerializer.serializeLambdaExecution(lfile, lid, lname, ltype) return line
def execute(): SQLiteSerializer.setup() files = glob.glob(trace_folder + "/*.trace") for file in files: data = open(file, "r") init = data.readline().strip() if init != "Initialised": print("WRONG FILE START", init) else: line = data.readline() while line: if line.startswith("#L"): line = parseLambda(data) elif line.startswith("#S"): line = parseScope(data) else: print(line) line = data.readline() SQLiteSerializer.close()
def executeTests(): # Test Execution SQLiteSerializer.setup() for repo in repo_name_path: logging.info("Testing " + repo[0]) try: runner = testrunner.Runner(repo[0], repo[1], time_limit=60) except Exception as e: logging.warning("Error while building Runner:") logging.error(str(e)) try: result = runner.run() except Exception as e: logging.warning("Error while executing tests:") logging.error(str(e)) logging.debug(result[0]) try: result = runner.get_run_result(result[0]) logging.info(result) logging.error("Serializing Test Execution of " + str(repo[0])) SQLiteSerializer.serializeCoverage(repo[0], result.coverage) except Exception as e: logging.error("Error while getting test results:") logging.error(str(e)) SQLiteSerializer.close()
def visit_Lambda(self, node): try: logging.info("Transforming Lambda: " + to_source(node)) except: logging.info("Transforming Lambda: " + ast.dump(node)) method_name = "_lambda_" + str(self.id_counter) SQLiteSerializer.serializeLambdaTransformation(self.filename, self.id_counter, node.lineno) self.methods.append(getLocalsFunction(method_name)) self.methods.append(getLambdaMethod( method_name, node.body, node.args, self.filename, self.id_counter)) self.globalvars.append(getGlobalVariable(method_name)) self.id_counter += 1 return Call( func=Name( id=method_name, ctx=Load()), args=[ Call( func=Name(id='locals', ctx=Load()), args=[], keywords=[] ) ], keywords=[] )
def transformCode(): # Code Transformation SQLiteSerializer.setup() for repo in repo_name_path: try: logging.info("Transforming " + repo[0] + " ...") Instrumentator.transformRepo(repo[1], repo[0]) SQLiteSerializer.commit() except Exception as e: logging.error("Could not transform: " + str(repo[0]) + "\n" + str(e)) SQLiteSerializer.close()
def executeMining(): SQLiteSerializer.setup() projects = [] # Static analysis failed = [] for name, path in repo_name_path: try: project = Project.createProject(path, name) projects.append(project) logging.info("Serializing Project " + name) SQLiteSerializer.serializeProject(project) except: failed.append(name) logging.warning("Could not create Project for " + name + " in " + path) SQLiteSerializer.close() logging.info("Serialization of " + str(len(failed)) + " Repositories failed.") logging.info(str(failed))