def fillWithDefects(self): """ Fetch defects that are global (not assigned to an ip) and fill the defect table with them. """ defects = Defect.fetchObjects({"ip":""}) d_list = {} end_defect = [] for defect in defects: if defect.index is None: end_defect.append(defect) elif str(defect.index) == "end": end_defect.append(defect) else: ind = int(defect.index) if ind not in d_list: d_list[ind] = defect else: new_ind = ind + 1 while new_ind in d_list: new_ind += 1 d_list[new_ind] = defect defect.index = new_ind defect.update({"index":str(new_ind)}) # Fix dict order to index between 0 and * keys_ordered = sorted(list(d_list.keys())) for i in range(len(keys_ordered)): self.addDefect(d_list[keys_ordered[i]]) for defect in end_defect: self.addDefect(defect)
def getDefectsAsDict(self): """ Returns a dictionnary with treeview defects stored inside Returns: The returned dict will be formed this way (shown as json): { "Risk level describer 1":{ "defect title 1": { "description":{ "title": "defect title 1", "risk": "Risk level 1", "ease": "Ease of exploitation 1", "impact": "Impact 1", "redactor": "Redactor name", "type": ['D', 'T', ...] }, "defects_ids":[ id 1, id 2... ] }, "defect title 2":{ ... } ... }, "Risk level describer 2":{ ... } ... } """ defects_dict = dict() defects_dict["Critique"] = dict() defects_dict["Majeur"] = dict() defects_dict["Important"] = dict() defects_dict["Mineur"] = dict() columnEase = self.treevw['columns'].index("ease") columnImpact = self.treevw['columns'].index("impact") columnType = self.treevw['columns'].index("type") columnRisk = self.treevw['columns'].index("risk") columnRedactor = self.treevw['columns'].index("redactor") for children_id in self.treevw.get_children(): children = self.treevw.item(children_id) title = children["text"] defect_recap = dict() defect_recap["title"] = title defect_recap["risk"] = children["values"][columnRisk] defect_recap["ease"] = children["values"][columnEase] defect_recap["impact"] = children["values"][columnImpact] defect_recap["redactor"] = children["values"][columnRedactor] types = children["values"][columnType].split(",") d_types = [] for d_type in types: d_types.append(d_type.strip()) defect_recap["type"] = d_types defects_dict[defect_recap["risk"]][title] = dict() defects_dict[defect_recap["risk"] ][title]["description"] = defect_recap defects_dict[defect_recap["risk"]][title]["defects_ids"] = [] defects = Defect.fetchObjects({"title": title}) for defect in defects: defects_dict[defect_recap["risk"] ][title]["defects_ids"].append(defect.getId()) return defects_dict
def _load(self): """ Load the treeview with database information """ mongoInstance = MongoCalendar.getInstance() dialog = ChildDialogProgress(self.appli, "Loading "+str( mongoInstance.calendarName), "Opening "+str(mongoInstance.calendarName) + ". Please wait for a few seconds.", 200, "determinate") step = 0 dialog.show(100) nbObjects = mongoInstance.find("waves").count() nbObjects += mongoInstance.find("scopes").count() nbObjects += mongoInstance.find("intervals").count() nbObjects += mongoInstance.find("scopes").count() nbObjects += mongoInstance.find("ips").count() nbObjects += mongoInstance.find("ports").count() nbObjects += mongoInstance.find("tools").count() onePercentNbObject = nbObjects//100 if nbObjects > 100 else 1 nbObjectTreated = 0 for child in self.get_children(): self.delete(child) self._hidden = [] self._detached = [] self.waves_node = self.insert("", "end", str( "waves"), text="Waves", image=WaveView.getClassIcon()) # Loading every category separatly is faster than recursivly. # This is due to cursor.next function calls in pymongo # Adding wave objects waves = Wave.fetchObjects({}) for wave in waves: wave_o = WaveController(wave) wave_vw = WaveView(self, self.appli.viewframe, self.appli, wave_o) wave_vw.addInTreeview(self.waves_node, False) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) scopes = Scope.fetchObjects({}) for scope in scopes: scope_o = ScopeController(scope) scope_vw = ScopeView(self, self.appli.viewframe, self.appli, scope_o) scope_vw.addInTreeview(None, False) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) intervals = Interval.fetchObjects({}) for interval in intervals: interval_o = IntervalController(interval) interval_vw = IntervalView(self, self.appli.viewframe, self.appli, interval_o) interval_vw.addInTreeview(None, False) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) # Adding ip objects self.ips_node = self.insert("", "end", str( "ips"), text="IPs", image=IpView.getClassIcon()) ips = Ip.fetchObjects({}) for ip in ips: ip_o = IpController(ip) ip_vw = IpView(self, self.appli.viewframe, self.appli, ip_o) ip_vw.addInTreeview(None, False) self.appli.statusbar.notify(ip_vw.controller.getTags()) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) # Adding port objects ports = Port.fetchObjects({}) for port in ports: port_o = PortController(port) port_vw = PortView(self, self.appli.viewframe, self.appli, port_o) port_vw.addInTreeview(None, False) self.appli.statusbar.notify(port_vw.controller.getTags()) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) # Adding defect objects defects = Defect.fetchObjects({"ip":{"$ne":""}}) for defect in defects: defect_o = DefectController(defect) defect_vw = DefectView( self, self.appli.viewframe, self.appli, defect_o) defect_vw.addInTreeview(None) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) # Adding tool objects tools = Tool.fetchObjects({}) for tool in tools: tool_o = ToolController(tool) tool_vw = ToolView(self, self.appli.viewframe, self.appli, tool_o) tool_vw.addInTreeview(None, False) self.appli.statusbar.notify(tool_vw.controller.getTags()) nbObjectTreated += 1 if nbObjectTreated % onePercentNbObject == 0: step += 1 dialog.update(step) self.sort(self.ips_node) self.appli.statusbar.update() dialog.destroy()