def save(self, onlytemp=False, force=False, imageX=None): """Save the data to a temporary file, close it and then ask if the original file should be replaced by it. If onlytemp is True, stop after saving the data to the temporary file, leaving the source file open, and fail if that didn't work first time. Otherwise the possibility of entering an alternative save path will be given. If force is True, don't ask, just do everything. If imageX is a directory path, get the images from there instead of from the source file """ if not self.baseFolder: return cfgFile = os.path.join(self.baseFolder, self.source.cfgName + '.zip') tmpsave = cfgFile + '_' backup = cfgFile + '~' while True: try: if os.path.exists(tmpsave): os.remove(tmpsave) self.saveData(tmpsave, imageX) if onlytemp: messageDialog(_("Information"), _("Saved as '%s'") % tmpsave) return self.source.close() break except: traceback.print_exc() warning(_("Could not save data to '%s'") % tmpsave) if onlytemp: return tmpsave = getFile(_("Save file to"), startDir=os.path.dirname(tmpsave), defaultSuffix="zip", filter=(_("zip Files"), ("*.zip",)), create=True) if isinstance(tmpsave, unicode): tmpsave = tmpsave.encode('utf8') if not tmpsave: return if (not force) and (not confirmationDialog(_("Replace existing file?"), _("The changes have been saved to '%s'.\n" "Should this now replace the previous data?") % tmpsave)): return try: if os.path.exists(backup): os.remove(backup) if os.path.exists(cfgFile): os.rename(cfgFile, backup) os.rename(tmpsave, cfgFile) if imageX: self.baseFolder = None self.slot_openConfig(False) else: # For the control panel, to indicate that the file has # been saved: self.sourcePath = cfgFile self.validationObject.validateAll() self.errorCount = self.validationObject.errorCount except: traceback.print_exc() warning(_("Couldn't update configuration file '%s'") % cfgFile)
def message(text, args=[]): messageDialog(_("Information"), argSub(text, args))