def get_files_from_database(self): ''' gets files from the database at startup ''' unwritten, modified = \ self.feescale_handler.non_existant_and_modified_local_files() for xml_file in unwritten: f = open(xml_file.filepath, "w") f.write(xml_file.data) f.close() self._checking_files = True for xml_file in modified: message = "%s '%s' %s<hr />%s" % ( _("Local Feescale"), xml_file.filepath, _("differs from the database version"), _("Do you wish to overwrite it with the stored data?")) mb = QtGui.QMessageBox(None) mb.setWindowTitle(_("Confirm")) mb.setText(message) mb.setIcon(mb.Question) mb.addButton(_("Show Diff"), mb.DestructiveRole) but = mb.addButton(mb.Cancel) but.setText(_("Keep Local File Unchanged")) but = mb.addButton(mb.Ok) but.setText(_("Overwrite Local File")) result = mb.exec_() if result not in (mb.Ok, mb.Cancel): # show diff f = open(xml_file.filepath, "r") local_data = f.read() f.close() dl = DiffDialog(xml_file.data, local_data) dl.apply_but.setText(_("Overwrite Local File")) dl.cancel_but.setText(_("Keep Local File Unchanged")) dl.enableApply() result = mb.Ok if dl.exec_() else mb.Cancel if result == mb.Ok: LOGGER.debug("saving file") f = open(xml_file.filepath, "w") f.write(xml_file.data) f.close() else: LOGGER.debug("not saving file") self._checking_files = False self._check_for_newer_local_files()
def get_files_from_database(self): ''' gets files from the database at startup ''' unwritten, modified = \ self.feescale_handler.non_existant_and_modified_local_files() for xml_file in unwritten: f = open(xml_file.filepath, "w") f.write(xml_file.data) f.close() self._checking_files = True for xml_file in modified: message = "%s '%s' %s<hr />%s"% ( _("Local Feescale"), xml_file.filepath, _("differs from the database version"), _("Do you wish to overwrite it with the stored data?")) mb = QtGui.QMessageBox(None) mb.setWindowTitle(_("Confirm")) mb.setText(message) mb.setIcon(mb.Question) mb.addButton(_("Show Diff"), mb.DestructiveRole) but = mb.addButton(mb.Cancel) but.setText(_("Keep Local File Unchanged")) but = mb.addButton(mb.Ok) but.setText(_("Overwrite Local File")) result = mb.exec_() if result not in (mb.Ok, mb.Cancel): #show diff f = open(xml_file.filepath, "r") local_data = f.read() f.close() dl = DiffDialog(xml_file.data, local_data) dl.apply_but.setText(_("Overwrite Local File")) dl.cancel_but.setText(_("Keep Local File Unchanged")) dl.enableApply() result = mb.Ok if dl.exec_() else mb.Cancel if result == mb.Ok: LOGGER.debug("saving file") f = open(xml_file.filepath, "w") f.write(xml_file.data) f.close() else: LOGGER.debug("not saving file") self._checking_files = False self._check_for_newer_local_files()
def compare_files(self): options = [] for i in range(self.tab_widget.count()): if i != self.tab_widget.currentIndex(): options.append(self.tab_widget.tabText(i)) if len(options) == 1: QtGui.QMessageBox.information( self, _("whoops"), _("you have no other files available for comparison")) return message = "%s<br /><b>%s (%s)</b><hr />%s" % ( _("Which feescale would you like to compare " "with the current feescale"), self.current_parser.ix, self.current_parser.description, _("Please make a choice")) dl = ChoiceDialog(message, options, self) if dl.exec_(): chosen = dl.chosen_index orig = unicode(self.text_edit.text().toUtf8()) new = unicode(self.text_editors[chosen].text().toUtf8()) dl = DiffDialog(orig, new) dl.exec_()
def show_database_diff(self): orig = self.feescale_handler.get_feescale_from_database( self.current_parser.ix) new = unicode(self.text_edit.text().toUtf8()) dl = DiffDialog(orig, new) dl.exec_()