def get (self,project_name): project = Project.get_by_key_name('name='+project_name) source_files = SourceFile.all().filter('project =',project) path = [project_name] f = SolutionRenderer() templates = process_template_imems() process_template_path(templates, path) templates.update({ 'files': source_files, 'projects': projects, 'path': path, 'project': project_name }) return self.response.write(f.render('project',templates))
def get(self,project_name): print repr(project_name) project = Project.get_by_key_name('name='+project_name) source_files = SourceFile.all().filter('project =',project) for file in source_files: print file # print "source_files",source_files files = map(lambda x: {'name':x.name,'size':int(x.p*100)}, source_files) # print 'files',files files = make_nodes_hier(files, project_name) result = json.dumps(files) print "result",result # print 'node_arch',files self.response.headers['Content-Type'.encode()] = 'application/json'.encode() self.response.out.write(result)
def init_sources_for_extrapolation(self): sources = SourceFile.all() tab = [] tab_x = [] tab_f = [] for source in sources: if source.vulnerability is not None and \ source.potential is not None and \ source.p is not None: if int(source.vulnerability.vulnerability) >0 : tab.append((source.potential,source.p)) tab = list(frozenset(tab)) tab.sort() try: for i, item in enumerate(tab): if tab[i+1] == tab[i]: tab.pop(i) except IndexError: pass print tab self.tab_x = map(lambda x: x[0], tab) self.tab_f = map(lambda x: x[1], tab)
def init_sources_for_extrapolation(self): sources = SourceFile.all() tab = [] tab_x = [] tab_f = [] for source in sources: if source.vulnerability is not None and \ source.potential is not None and \ source.p is not None: if int(source.vulnerability.vulnerability) > 0: tab.append((source.potential, source.p)) tab = list(frozenset(tab)) tab.sort() try: for i, item in enumerate(tab): if tab[i + 1] == tab[i]: tab.pop(i) except IndexError: pass print tab self.tab_x = map(lambda x: x[0], tab) self.tab_f = map(lambda x: x[1], tab)
def process_sources(self): splitted_source = "" for file_name, file_source in self.project_files: ast_source = remove_Directives(file_source) # print "@file_source[%s]"%file_name #,file_source try: # ast = get_ast_from_text(file_source) ast = None except Exception, e: print e debuglines = 8 line = int(str(e).split(':')[1]) for i in range(debuglines): try: print "INFO file[%s] line[%s]: %s" % ( file_name, line + i - debuglines / 2 + 1, file_source.split('\n')[line + i - debuglines / 2]) except: pass ast = None if ast is not None: #ast.show() # print ast.ext pass holsted, mackkeib, jilb, sloc = (function( file_source, ast) for function in (get_holsted, get_mackkeib, get_jilb, get_sloc)) #BUF to fix if holsted != (-1, -1, -1): splitted_source += "\n" + file_source vulns = get_vulns_count(file_source, ast) metrix = Metrix(holsted=str(holsted), mackkeib=str(mackkeib), jilb=str(jilb), sloc=str(sloc)) metrix.put() vulnerability = Vulnerability(vulnerability=str(vulns)) vulnerability.put() potential = self.calc_potential(holsted[0], mackkeib, jilb, vulns) p = self.calc_p(potential) short = self.project.short + md5(file_name).hexdigest() # print ("filename & sloc & holsted & mackkeib & jilb & vulns & potential & p") print("{} & {} & {} & {} & {} & {} & {} & {}\\\\".format( file_name, sloc, holsted[0], mackkeib, jilb, vulns, potential, p)) source = Source(project=self.project, file_name=file_name, file_source=file_source, file_db_item=SourceFile( short=short, project=self.project, name=file_name, source=file_source, metrix=metrix, vulnerability=vulnerability, potential=potential, p=p), holsted=holsted, mackkeib=mackkeib, jilb=jilb, sloc=sloc, vulns=vulns, potential=potential, p=p) source.file_db_item.put() self.files.append(source)
def get (self,filehash): source_file = SourceFile.all().filter('short',filehash)[0] source_file.p = 1.0 source_file.put() recalc_p(source_file)
def get(self, filehash): print filehash code = SourceFile.all().filter('short',filehash)[0] #print code.source self.response.write(code.source) return