def __init__(self, parent): """ Constructor for settings dialog :param parent: parent controller instance :return: """ self._parent = parent self._parentUi = parent._parent.ui ReportSelectorDialogBase.__init__( self, self._parentUi, QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinMaxButtonsHint | QtCore.Qt.WindowCloseButtonHint) self.setupUi(self) self.setWindowIcon(self._parentUi.windowIcon()) print("\tgui/ReportSelectorDialog parent: ", self._parent, " -> self: ", self) if oPB.PRINTHIER else None print("\tgui/ReportSelectorDialog parentUi: ", self._parentUi, " -> self: ", self) if oPB.PRINTHIER else None self.splash = Splash(self, translate("MainWindow", "Please wait...")) self.viewer = HtmlDialog(self) self.model_left = None self.model_right = None self.assign_model(self._parent.model_report, self._parent.model_report) self.connect_signals()
def compare(self, data_left: list, data_right: list, tablefill: str = "--", nocomp: bool = False): """ Compare two lists and combine them side by side. :param data_left: left list :param data_right: right list :param tablefill: fill empty values with ``tablefill`` :param nocomp: only add data: left side = depot content, right side = repo content, no comparison at all :return: combined list """ if not nocomp: self.logger.debug("Comparing sides") uniqueLeft = [item for item in data_left if item not in data_right] uniqueRight = [ item for item in data_right if item not in data_left ] else: self.logger.debug("Listing content") uniqueLeft = [item for item in data_left] uniqueRight = [item for item in data_right] try: maxLeft = max(len(s) for s in uniqueLeft) except: maxLeft = 0 try: maxRight = max(len(s) for s in uniqueRight) except: maxRight = 0 fillvalue = [] if maxLeft >= maxRight: fillvalue.extend([tablefill] * maxLeft) else: fillvalue.extend([tablefill] * maxRight) zipped = zip_longest(uniqueLeft, uniqueRight, fillvalue=fillvalue) ret = [] for row in zipped: row_zip = [] for part in row: row_zip += part if part else [''] ret.append(row_zip) if len(ret) == 0: ret.append([ translate("depotmanagerController", "(no differences found)"), "" ]) return ret
def retranslateMsg(self): self.logger.debug("Retranslating further messages...") self.splash.msg = translate("MainWindow", "Please wait...")
def generate_report(self): """ Generate HTML comparison report :return: """ self.logger.debug("Generate HTML report") left = "" time = "" html = "" if self.rdDepot.isChecked(): modus = "depot" else: modus = "repo" try: self.logger.debug("Getting reference server from left tableview") server_left = self.tblSrvLeft.selectionModel().model().item( self.tblSrvLeft.selectionModel().selectedRows()[0].row(), 0).text() except: self.logger.debug("No reference server selected.") return self.logger.debug( "Getting list of server to compare to from right tableview") slave = self.tblSrvRight.selectionModel().selectedRows() if not slave: self.logger.debug("Nothing to compare to selected.") return steps = 1 + len(slave) step = 100 / steps self.splash.incProgress(step) if modus == "depot": self.logger.debug("Depot comparison modus") html = HtmlTools.HTMLHeader( translate("depotManagerController", "Compare depots:") + " " + server_left + " / " + str(datetime.now()), "#ffffff", "#F0F9FF", "#007EE5", "#000000", "#ffffff") data_left = self.get_prodlist_to_server( server_left, self._parent.productsondepotslist) else: self.logger.debug("Repository comparison modus") html = HtmlTools.HTMLHeader( translate("depotManagerController", "Compare repositories:") + " " + server_left + " / " + str(datetime.now()), "#ffffff", "#F0F9FF", "#007EE5", "#000000", "#ffffff") data_left = self.get_repolist_to_server( self._parent.do_getrepocontent(dest=server_left)) self.logger.debug("Processing server list...") for row in slave: self.splash.incProgress(step) server_right = self.tblSrvRight.selectionModel().model().item( row.row(), 0).text() self.logger.debug("Processing server: " + server_right) if modus == "depot": data_right = self.get_prodlist_to_server( server_right, self._parent.productsondepotslist) else: data_right = self.get_repolist_to_server( self._parent.do_getrepocontent(dest=server_right)) tmp = self.compare(data_left, data_right, tablefill="") if tmp: colspan = len(tmp[0]) / 2 else: tmp = [] colspan = 1 tmp.insert(0, [ translate("depotManagerController", "Reference:") + " " + server_left, "Depot: " + server_right ]) if tmp: html += HtmlTools.Array2HTMLTable(element_list=tmp, colspan=colspan, title='', bodybgcolor="#ffffff", hightlightbgcolor="#F0F9FF", headerbgcolor="#007EE5", bodytxtcolor="#000000", headertxtcolor="#ffffff", headers_on=True, only_table=True) html += HtmlTools.HTMLFooter() self.splash.close() self.viewer.showHtml(html)