aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbackend/magiback37
-rw-r--r--backend/org.mageia.Magiback.conf4
-rwxr-xr-xbackend/raw_write.py10
-rwxr-xr-xlib/isodumper.py139
4 files changed, 108 insertions, 82 deletions
diff --git a/backend/magiback b/backend/magiback
index e16e1dc..d46ee9a 100755
--- a/backend/magiback
+++ b/backend/magiback
@@ -222,11 +222,46 @@ class ConfFile(object):
return True
+class Logging(object):
+ """
+ <node>
+ <interface name='org.mageia.Magiback.Logging'>
+ <method name='debug'>
+ <arg type='s' name='message' direction='in'/>
+ </method>
+ <method name='info'>
+ <arg type='s' name='message' direction='in'/>
+ </method>
+ <method name='warning'>
+ <arg type='s' name='message' direction='in'/>
+ </method>
+ <method name='error'>
+ <arg type='s' name='message' direction='in'/>
+ </method>
+ </interface>
+ </node>
+ """
+ def __init__(self):
+ super().__init__()
+
+ def debug(self, message):
+ logging.debug(message)
+
+ def info(self, message):
+ logging.info(message)
+
+ def warning(self, message):
+ logging.warning(message)
+
+ def error(self, message):
+ logging.error(message)
+
if __name__ == '__main__':
print("Running Magiback service.")
bus = SystemBus()
conf_file = ConfFile()
- bus.publish(DEAMON_ORG, conf_file, ("Isodumper", Isodumper()))
+ log = Logging()
+ bus.publish(DEAMON_ORG, conf_file, ("Isodumper", Isodumper()), ('Logging', Logging()))
loop = GLib.MainLoop()
loop.run()
logging.shutdown()
diff --git a/backend/org.mageia.Magiback.conf b/backend/org.mageia.Magiback.conf
index af00707..4632805 100644
--- a/backend/org.mageia.Magiback.conf
+++ b/backend/org.mageia.Magiback.conf
@@ -19,4 +19,8 @@
<allow send_destination="org.mageia.Magiback.Isodumper"/>
<allow send_interface="org.mageia.Magiback.Isodumper"/>
</policy>
+ <policy context="default">
+ <allow send_destination="org.mageia.Magiback.Logging"/>
+ <allow send_interface="org.mageia.Magiback.Logging"/>
+ </policy>
</busconfig>
diff --git a/backend/raw_write.py b/backend/raw_write.py
index b30f759..d46fe1e 100755
--- a/backend/raw_write.py
+++ b/backend/raw_write.py
@@ -131,6 +131,7 @@ class Dumper(object):
def _check_write(self, target, source):
logging.debug("Start checking")
self.return_message = ""
+ messages = []
b = os.path.getsize(source)
# Compute the sum from the written device
steps = list(range(0, b + 1, int(b / 100)))
@@ -165,17 +166,18 @@ class Dumper(object):
self.sum_file = False
self.return_state = True
if self.sum_check == "": # Can't get stored sum
- self.return_message += _("SHA3 sum: {}").format(sha512sumcalc)
+ messages.append(_("SHA3 sum: {}").format(sha512sumcalc))
# compare the sums
elif sha512sumcalc == self.sum_check:
# , keep the bracket, this is the place for sum type
- self.return_message += "\n" + _("The {} sum check is OK").format(sum_type)
+ messages.append(_("The {} sum check is OK").format(sum_type))
else:
- self.return_message += "\n" + _(
- "/!\\The computed and stored sums don't match"
+ messages.append(
+ _("/!\\The computed and stored sums don't match")
)
self.return_state = False
self._progress = 100
+ self.return_message = "\n".join(messages)
logging.info(self.return_message)
self.finished.set()
diff --git a/lib/isodumper.py b/lib/isodumper.py
index 75ac4e7..cc624b5 100755
--- a/lib/isodumper.py
+++ b/lib/isodumper.py
@@ -49,7 +49,6 @@ from pydbus import SystemBus
import gnupg
import datetime
-import logging
import threading
from gi.repository import GLib
from queue import SimpleQueue
@@ -163,13 +162,11 @@ class UDisks2(object):
iface = self.bus.get(self.SERVICE, block["path"])
fs = iface[self.SERVICE + ".Encrypted"]
fs.Lock({})
- logging.debug(f"Unmounting encryted {block['path']}")
else:
iface = self.bus.get(self.SERVICE, block["path"])
if self.SERVICE + ".Filesystem" in objects[block["path"]]:
fs = iface[self.SERVICE + ".Filesystem"]
if fs.MountPoints: # partition is mounted
- logging.debug(f"Unmounting {block['path']}")
try:
fs.Unmount({})
except GLib.GError as e:
@@ -179,8 +176,6 @@ class UDisks2(object):
)
except:
raise Exception(str(e))
- else:
- logging.debug(f"Not mounted {block['path']}")
return True, ""
def get_partitions(self, target):
@@ -239,6 +234,30 @@ class ParseCLI(args.AppArgs):
def __init(self, command):
super().__init__(command)
+class Logging():
+ def __init__(self, debug, logger):
+ # Init logging in Magiback
+ self.bus = SystemBus()
+ self.logremote = self.bus.get("org.mageia.Magiback", "Logging")
+ self.logger = logger
+ self.debug_level = debug
+
+ def debug(self, message):
+ if self.debug_level:
+ self.logremote.debug(message)
+
+ def info(self, message):
+ self.logger.appendLines(message + "\n")
+ self.logremote.info(message)
+
+ def warning(self, message):
+ self.logger.appendLines(message + "\n")
+ self.logremote.warning(message)
+
+ def error(self, message):
+ self.logger.appendLines(message + "\n")
+ self.logremote.error(message)
+
class IsoDumper(basedialog.BaseDialog):
def get_devices(self, selected=None):
@@ -300,26 +319,24 @@ class IsoDumper(basedialog.BaseDialog):
def device_selected(self):
selitem = self.devicelist.selectedItem()
- logging.debug(f"Selected a device")
if selitem is not None:
self.dev = selitem.label()
- logging.debug(f"Selected {self.dev}")
+ self.logger.debug(f"Selected {self.dev}")
if self.dev != "":
for name, path, size in self.list:
if self.dev == self.device_label(name, path, size):
self.deviceSize = size
self.device_name = name.rstrip().replace(" ", "")
message = _("Target Device: {}").format(self.dev)
- self.logger(message)
- logging.info(message)
+ self.logger.info(message)
partitions = self.u.get_partitions(
self.dev.split("(")[1].split(")")[0]
)
# I18N: verb in singular 3rd person
- self.logger(_("Contains this/these partition(s)"))
+ self.logger.info(_("Contains this/these partition(s)"))
# I18N: don't translate keywords inside braces {}
for partition in partitions:
- self.logger(
+ self.logger.info(
_("{device}: Type={type}, Label={label}").format(
device=partition["device"],
type=partition["type"],
@@ -328,7 +345,7 @@ class IsoDumper(basedialog.BaseDialog):
)
if len(partitions) == 0:
# I18N: None refers to partition (no partitions on the selected device)
- self.logger(_("None"))
+ self.logger.info(_("None"))
self.partition_cbox.setEnabled()
self.partition_cbox.setChecked(False)
self.backup_cbox.setEnabled()
@@ -375,7 +392,6 @@ class IsoDumper(basedialog.BaseDialog):
def get_sum(self, source):
self.return_state = False
self.signature_checked = False
- logging.debug("Starting getting sum")
# Check if the sum file has a valid signature
gpg = gnupg.GPG()
gpg.encoding = "utf-8"
@@ -388,8 +404,8 @@ class IsoDumper(basedialog.BaseDialog):
keys_list = gpg.list_keys()
except Exception as e:
self.signature_found = False
- logging.error(str(e))
- logging.info(_("GPG signatures database can not be read"))
+ self.logger.warning(str(e))
+ self.logger.warning(_("GPG signatures database can not be read"))
return
key_present = False
for entry in keys_list:
@@ -397,9 +413,9 @@ class IsoDumper(basedialog.BaseDialog):
if entry["expires"] and (
datetime.datetime.now().timestamp() > float(entry["expires"])
):
- logging.info("Mageia key expired, reloading")
+ self.logger.warning("Mageia key expired, reloading")
else:
- logging.info("Mageia key already present")
+ self.logger.debug("Mageia key already present")
key_present = True
break
try:
@@ -411,21 +427,21 @@ class IsoDumper(basedialog.BaseDialog):
verified = gpg.verify_file(g, close_file=False)
if verified:
self.signature_checked = True
- logging.debug("signature checked")
+ self.logger.debug("signature checked")
g.close()
else:
g.seek(0)
verified = gpg.verify_file(g, self.source_file)
if verified:
self.signature_checked = True
- logging.debug("Detached signature is OK")
+ self.logger.debug("Detached signature is OK")
else:
self.signature_checked = False
- logging.warning("Signature is false")
+ self.logger.warning("Signature is false")
except Exception as e:
self.signature_found = False
- logging.error(str(e))
- logging.info(
+ self.logger.warning(str(e))
+ self.logger.warning(
_("Signature file {} not found\n" + _("or key expired")).format(
sig_file
)
@@ -572,8 +588,7 @@ class IsoDumper(basedialog.BaseDialog):
message = _(
"The destination directory is too small to receive the backup (%s Mb needed)"
) % (sizeM)
- self.logger(message)
- logging.warning(message)
+ self.logger.warning(message)
self.emergency(message)
self.initial_state()
return False, message
@@ -582,8 +597,7 @@ class IsoDumper(basedialog.BaseDialog):
self.returncode = 0
source = self.dev.split("(")[1].split(")")[0]
message = _("Backup to: {}").format(dest)
- self.logger(message)
- logging.info(message)
+ self.logger.info(message)
# Writing step
# set flag and provide uid, gid of current user to set the owner of the backup file at end
self.iface.set_backup_mode(os.getuid(), os.getgid())
@@ -614,8 +628,7 @@ class IsoDumper(basedialog.BaseDialog):
b = os.path.getsize(source)
if b > (self.deviceSize):
message = _("The device is too small to contain the ISO file.")
- self.logger(message)
- logging.error(message)
+ self.logger.warning(message)
self.emergency(message)
else:
# I18N: don't translate source nor target
@@ -628,8 +641,7 @@ class IsoDumper(basedialog.BaseDialog):
source=source, target=target
)
self.operation = True
- self.logger(message)
- logging.info(message)
+ self.logger.info(message)
success, message = self.u.do_unmount(target)
self.udev_wait(_("unmounting"))
if success:
@@ -648,8 +660,7 @@ class IsoDumper(basedialog.BaseDialog):
source=source.split("/")[-1], target=target
)
message += "\n" + _("Bytes written: {}").format(str(b))
- self.logger(message)
- logging.info(message)
+ self.logger.info(message)
self.progress.setLabel(_("Checking ") + target.split("/")[-1])
self.progress.setValue(0)
self.dialog.pollEvent()
@@ -663,8 +674,6 @@ class IsoDumper(basedialog.BaseDialog):
progress = self.iface.progress
nowarning, message = self.iface.end()
self.progress.setEnabled()
- self.logger(message)
- logging.info(message)
# Add persistent partition if asked
if (
self.partition_cbox.isChecked()
@@ -677,8 +686,7 @@ class IsoDumper(basedialog.BaseDialog):
message = _(
"No key for encrypted partition provided. Adding the partition aborted."
)
- self.logger(message)
- logging.warning(message)
+ self.logger.warning(message)
else:
self.iface.do_persistence(
target,
@@ -695,15 +703,14 @@ class IsoDumper(basedialog.BaseDialog):
message = _(
"Added encrypted persistent partition"
)
- self.logger(message)
- logging.warning(message)
+ self.logger.info(message)
else:
- self.logger(
+ self.logger.error(
_(
"Adding encrypted persistent partition failed"
)
)
- self.logger(self.iface.message)
+ self.logger.error(self.iface.message)
nowarning = False
else:
self.iface.do_persistence(
@@ -718,10 +725,9 @@ class IsoDumper(basedialog.BaseDialog):
message = _("Added persistent partition")
else:
message = _("Adding persistent partition failed")
- self.logger(self.iface.message)
+ self.logger.warning(self.iface.message)
nowarning = False
- self.logger(message)
- logging.warning(message)
+ self.logger.warning(message)
# Unmount if partitions are automatically mounted and then eject
self.progress.setValue(100)
self.dialog.pollEvent()
@@ -755,10 +761,8 @@ class IsoDumper(basedialog.BaseDialog):
+ "\n"
+ _(
"You are free to unplug it now, a logfile \n\
-/home/-user-/.isodumper/isodumper.log has been saved."
- )
- + "\n"
- + _("You may also consult /var/log/magiback.log"),
+/var/log/magiback.log has been saved."
+ ),
)
if self.ask_OK(info):
return
@@ -776,10 +780,8 @@ class IsoDumper(basedialog.BaseDialog):
+ "\n"
+ _(
"You are free to unplug it now, a logfile \n\
-/home/-user-/.isodumper/isodumper.log has been saved."
- )
- + "\n"
- + _("You may also consult /var/log/magiback.log"),
+/var/log/magiback.log has been saved."
+ ),
)
if self.ask_OK(info):
return
@@ -836,14 +838,13 @@ class IsoDumper(basedialog.BaseDialog):
# to exit from _handleEvents loop
self._running = False
- def logger(self, text):
- self.logview.appendLines(text + "\n")
+ #def logger(self, text):
+ #self.logview.appendLines(text + "\n")
def activate_devicelist(self):
self.devicelist.setEnabled()
message = _("ISO Image to copy: ") + self.img_name
- self.logger(message)
- logging.warning(message)
+ self.logger.info(message)
# self.chooser.set_tooltip_text(self.img_name)
@@ -940,17 +941,6 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog
self._running = False
return
- # TODO Read log level from command line
- level = logging.DEBUG if debug else logging.ERROR
- logpath = os.path.join(os.path.expanduser("~"), ".isodumper")
- if not (os.path.isdir(logpath)):
- os.mkdir(logpath)
- logging.basicConfig(
- filename=os.path.join(logpath, "isodumper.log"),
- format="%(asctime)s %(levelname)-8s %(message)s",
- level=level,
- )
-
# define size of the selected device
self.deviceSize = 0
@@ -1142,10 +1132,8 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog
loop.run()
def device_changed(self, a, b):
- logging.debug(f"Signal {a}")
if not self.operation:
if "drives" in a.split("/"):
- logging.debug("device-changed")
self.uEventQueue.put({"event": "device-changed", "value": True})
def ask_image(self):
@@ -1172,7 +1160,7 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog
self.img_name = ""
return
else:
- self.logger(_("The checksum file is signed"))
+ self.logger.info(_("The checksum file is signed"))
else:
info = Info(
_("Warning"),
@@ -1301,8 +1289,7 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog
# something went wrong, we stop
self.initial_state()
return
- self.logger(message)
- logging.info(message)
+ self.logger.info(message)
if self.write_cbox.isChecked() and self.image_is_selected:
self.do_write()
self.image_is_selected = False
@@ -1311,12 +1298,10 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog
# Create a partition without writing image, will use all the device space.
format_success, message = self.do_format()
if format_success:
- self.logger(message)
- logging.info(message)
+ self.logger.info(message)
self.success()
else:
- self.logger(message)
- logging.info(message)
+ self.logger.warning(message)
self.emergency(message)
elif backup_success:
# success message when no other operation after backup
@@ -1453,7 +1438,6 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog
self.initial_state()
try:
item = self.uEventQueue.get_nowait()
- logging.debug(f"Dealing with {item['event']}")
if item["event"] == "device-changed":
self.update_list_on_event()
except Exception as e:
@@ -1466,13 +1450,14 @@ 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.error(message)
self.emergency(message)
self._running = False
return
self._setupUI()
# setting to False will break the event loop
+ self.logger = Logging(debug, self.logview)
self._running = True
self._start = False
self.timeout = 100