diff options
author | Papoteur <papoteur@mageia.org> | 2020-12-10 20:34:27 +0100 |
---|---|---|
committer | Papoteur <papoteur@mageia.org> | 2020-12-10 20:34:27 +0100 |
commit | aa582a3371dce09816aefc9285e9b4cbc0c827fe (patch) | |
tree | f54d8ce07ad9765642bee12702d3aba7c16c0c67 /lib/isodumper.py | |
parent | da1186bfe8b32d4b1f3a2d45dc5211cfee717aa5 (diff) | |
download | isodumper-aa582a3371dce09816aefc9285e9b4cbc0c827fe.tar isodumper-aa582a3371dce09816aefc9285e9b4cbc0c827fe.tar.gz isodumper-aa582a3371dce09816aefc9285e9b4cbc0c827fe.tar.bz2 isodumper-aa582a3371dce09816aefc9285e9b4cbc0c827fe.tar.xz isodumper-aa582a3371dce09816aefc9285e9b4cbc0c827fe.zip |
Log are directly registered.
Diffstat (limited to 'lib/isodumper.py')
-rwxr-xr-x | lib/isodumper.py | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 16e6804..71c318d 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -211,6 +211,7 @@ class IsoDumper(object): self.deviceSize = size self.device_name = name.rstrip().replace(' ', '') self.logger(_('Target Device: ') + self.dev) + logging.info(_('Target Device: {}').format(self.dev)) self.formatbt.setEnabled() self.ima.setEnabled() self.backup_select.setEnabled() @@ -244,17 +245,21 @@ class IsoDumper(object): if rc == 0: message = _('The device was formatted successfully.') self.logger(message) + logging.info(message) self.success() elif rc == 5: message = _("An error occurred while creating a partition.") self.logger(message) + logging.error(message) self.emergency(message) elif rc == 127: message = _('Authentication error.') self.logger(message) + logging.error(message) self.emergency(message) else: - message = _('An error occurred.') + message = _('An error occurred. Code {}'.format(rc)) + logging.error(message) self.emergency(message) def restore(self): @@ -274,11 +279,6 @@ class IsoDumper(object): self.cryptcb.setDisabled() self.cryptkey.setDisabled() - def onProgress(self, frac): - self.logger(_('Wrote: {}% '.format(frac))) - self.progress.setValue(frac) - self.dialog.pollEvent() - def raw_format(self, usb_path, fstype, label): self.u.do_unmount(usb_path) self.udev_wait(_("unmounting")) @@ -319,11 +319,14 @@ class IsoDumper(object): sizeM = str(self.deviceSize / (1024 * 1024)) message = _("The destination directory is too small to receive the backup (%s Mb needed)") % (sizeM) self.logger(message) + logging.warning(message) self.emergency(message) else: self.returncode = 0 source = self.dev.split('(')[1].split(')')[0] - self.logger(_('Backup to:') + ' ' + dest) + message = _('Backup to: {}').format(dest) + self.logger(message) + logging.info(message) bus = SystemBus() iface = bus.get("org.mageia.Magiback", "Isodumper") # Writing step @@ -335,12 +338,15 @@ class IsoDumper(object): time.sleep(.2) success, message = iface.end() if success: - self.logger( - _('{source} successfully written to {target}').format(source=source.split('/')[-1], target=dest)) + #: don't translate source or target + message = _('{source} successfully written to {target}').format(source=source.split('/')[-1], target=dest) + self.logger(message) + logging.info(message) self.progress.setEnabled() self.progress.setValue(100) self.dialog.pollEvent() self.logger(message) + logging.info(message) self.success() else: self.emergency(message) @@ -358,6 +364,7 @@ class IsoDumper(object): if b > (self.deviceSize): message = _('The device is too small to contain the ISO file.') self.logger(message) + logging.error(message) self.emergency(message) else: info = Info(_("Writing confirmation"), True, self.warning) @@ -371,9 +378,12 @@ class IsoDumper(object): return self.ima.setDisabled() self.writebt.setDisabled() + #: don't translate source or target self.progress.setLabel(_('Writing {source} to {target}').format(source=source.split('/')[-1], target=target.split('/')[-1])) - self.logger(_('Executing copy from ') + source + _(' to ') + target) + message = _('Executing copy from {source} to {target}').format(source=source, target=target) + self.logger(message) + logging.info(message) bus = SystemBus() iface = bus.get("org.mageia.Magiback", "Isodumper") success, message = self.u.do_unmount(target) @@ -390,10 +400,12 @@ class IsoDumper(object): time.sleep(.5) success, message = iface.end() if success: - self.logger( - _('Image {source} successfully written to {target}').format(source=source.split('/')[-1], - target=target)) - self.logger(_('Bytes written: ') + str(b)) + #: don't translate source or target + message = _('Image {source} successfully written to {target}').format(source=source.split('/')[-1], + target=target) + message += "\n" + _('Bytes written: {}').format(str(b)) + self.logger(message) + logging.info(message) self.progress.setLabel(_('Checking ') + target.split('/')[-1]) self.progress.setValue(0) self.dialog.pollEvent() @@ -408,14 +420,16 @@ class IsoDumper(object): success, message = iface.end() self.progress.setEnabled() self.logger(message) + logging.info(message) # Add persistent partition if asked if self.persistencecb.isChecked(): self.progress.setLabel(_("Adding persistent partition")) self.progress.setValue(0) if self.cryptcb.isChecked(): if self.cryptkey.value() == "": - self.logger( - _("No key for encrypted partition provided. Adding the partition aborted.")) + message = _("No key for encrypted partition provided. Adding the partition aborted.") + self.logger(message) + logging.warning(message) else: iface.do_persistence(target, "mgalive-persist", self.cryptkey.value()) while not iface.done: @@ -425,7 +439,9 @@ class IsoDumper(object): self.dialog.pollEvent() time.sleep(.5) if iface.state: - self.logger(_("Added encrypted persistent partition")) + message = _("Added encrypted persistent partition") + self.logger(message) + logging.warning(message) else: self.logger(iface.message) else: @@ -435,7 +451,9 @@ class IsoDumper(object): self.progress.setValue(progress) self.dialog.pollEvent() time.sleep(.5) - self.logger(_("Added persistent partition")) + message = _("Added persistent partition") + self.logger(message) + logging.warning(message) # Unmount if partitions are automatically mounted and then eject self.progress.setValue(100) self.dialog.pollEvent() @@ -460,8 +478,7 @@ class IsoDumper(object): self.final_unsensitive() info = Info(_("Success"), True, _("The operation completed successfully.\n\ You are free to unplug it now, a logfile \n\ -(/home/-user- or /root)/.isodumper/isodumper.log will be saved when\n\ - you close the application.")) +(/home/-user- or /root)/.isodumper/isodumper.log has be saved.")) if self.ask_OK(info): return @@ -502,26 +519,17 @@ class IsoDumper(object): self.persistencecb.setDisabled() def close(self): - self.write_logfile() self.dialog.destroy() self.dialog = None - def write_logfile(self): - logpath = os.path.join(os.path.expanduser('~'), '.isodumper') - if not (os.path.isdir(logpath)): - os.mkdir(logpath) - logfile = open(logpath + '/isodumper.log', "w", encoding="utf-8") - logfile.write(self.logview.logText()) - logfile.close() - - print((self.logview.logText())) - def logger(self, text): self.logview.appendLines(text + "\n") def activate_devicelist(self): self.devicelist.setEnabled() - self.logger(_('Image ') + ": " + self.img_name) + message = _('Image ') + ": " + self.img_name + self.logger(message) + logging.warning(message) # self.chooser.set_tooltip_text(self.img_name) @@ -580,7 +588,7 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog logpath = os.path.join(os.path.expanduser('~'), '.isodumper') if not (os.path.isdir(logpath)): os.mkdir(logpath) - logging.basicConfig(filename=os.path.join(logpath,"isodumper2.log"), + logging.basicConfig(filename=os.path.join(logpath,"isodumper.log"), format='%(asctime)s %(levelname)-8s %(message)s', level=level) @@ -685,6 +693,7 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog self.u = UDisks2() except: message = _('UDisks2 is not available on your system') + logging.error(message) self.logger(message) self.emergency(message) if not self.get_devices(): |