diff options
author | Papoteur <papoteur@mageia.org> | 2019-08-18 21:07:32 +0200 |
---|---|---|
committer | Papoteur <papoteur@mageia.org> | 2019-08-18 21:07:32 +0200 |
commit | 2fd705f8417f95d55e5cbd7b728b51dba0ac1162 (patch) | |
tree | ffca78b317eda5be4f0c522e7ab5df2e522a6552 | |
parent | 03b917c1fb49484f64f5a1352f2214979d06a40d (diff) | |
download | isodumper-2fd705f8417f95d55e5cbd7b728b51dba0ac1162.tar isodumper-2fd705f8417f95d55e5cbd7b728b51dba0ac1162.tar.gz isodumper-2fd705f8417f95d55e5cbd7b728b51dba0ac1162.tar.bz2 isodumper-2fd705f8417f95d55e5cbd7b728b51dba0ac1162.tar.xz isodumper-2fd705f8417f95d55e5cbd7b728b51dba0ac1162.zip |
Add more logging
-rwxr-xr-x | backend/magiback | 11 | ||||
-rwxr-xr-x | backend/raw_write.py | 19 |
2 files changed, 22 insertions, 8 deletions
diff --git a/backend/magiback b/backend/magiback index e1ec093..6bf0202 100755 --- a/backend/magiback +++ b/backend/magiback @@ -10,7 +10,8 @@ import logging DEAMON_ORG = 'org.mageia.Magiback' DEAMON_INTERFACE = DEAMON_ORG ISODUMPER_INTERFACE = DEAMON_ORG + ".Isodumper" -logging.basicConfig(filename="/var/log/magiback.log",level=logging.DEBUG) +logging.basicConfig(filename="/var/log/magiback.log",format='%(asctime)s %(levelname)-8s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S',level=logging.DEBUG) class Isodumper(raw_write.Dumper): """ @@ -61,6 +62,7 @@ class Isodumper(raw_write.Dumper): # Call translation catalog gettext.install(APP, localedir=DIR,) self.finished = threading.Event() + # finished is cleared at start of operation, and set at the end self.finished.clear() self._progress = 0 self.loop = GLib.MainLoop() @@ -84,7 +86,8 @@ class Isodumper(raw_write.Dumper): self.writing_perm = True self.writing_target = target else: - self.return_message = "Access denied" + self.return_message = "Writing: Access denied" + logging.debug(self.return_message) self.finished.set() def do_persistence(self, target, label): @@ -92,7 +95,7 @@ class Isodumper(raw_write.Dumper): if self.writing_perm and self.writing_target == target : self._do_persistence(target, label) else: - self.return_message = "Access denied" + self.return_message = "Persistence: Access denied" self.writing_perm = False self.writing_target = "" @@ -120,7 +123,6 @@ class Isodumper(raw_write.Dumper): return self._progress def do_unmount(self, device): - print("Unmounting") return self._do_unmount([device]) def get_sum(self, source): @@ -191,3 +193,4 @@ if __name__ == '__main__': ("Isodumper", Isodumper())) loop = GLib.MainLoop() loop.run() + logging.shutdown() diff --git a/backend/raw_write.py b/backend/raw_write.py index dbf8e19..d369d82 100755 --- a/backend/raw_write.py +++ b/backend/raw_write.py @@ -34,6 +34,7 @@ from subprocess import call, Popen, PIPE import hashlib import gnupg import time +import logging class Dumper(object): @@ -47,6 +48,7 @@ class Dumper(object): ifc=io.open(source, "rb",1) except: message = _('Reading error.')+ source + logging.debug(message) self.return_state = False self.return_message = message self.finished.set() @@ -85,6 +87,7 @@ class Dumper(object): ofc.write(buf) except: message = _("Writing error.") + logging.debug(message) self.return_state = False self.return_message = message self.finished.set() @@ -98,6 +101,7 @@ class Dumper(object): os.fsync(ofc) except: message = _("Writing error.") + logging.debug(message) self.return_state = False self.return_message = message self.finished.set() @@ -114,11 +118,13 @@ class Dumper(object): self._progress = 100 self.finished.set() self.return_state = True - self.return_message = _("Success") + self.return_message = _("Writing terminated") + logging.debug(self.return_message) return def _do_unmount(self, target): target = target[0] + logging.debug("Starting unmounting") message = _("No partition is mounted.") retcode = 0 try: @@ -144,12 +150,13 @@ class Dumper(object): message += _('Error, umount returned {}').format(str(retcode)) except OSError as e: message += _('Execution failed: {}').format(str(e)) - print(message) + logging.info(message) return not bool(retcode), message def _get_sum(self, source): self.return_state = False self.return_message = "" + logging.debug("Starting getting sum") # Check if the sum file has a valid signature gpg = gnupg.GPG() gpg.encoding = 'utf-8' @@ -178,8 +185,10 @@ class Dumper(object): except: self.return_message = _("Sum SHA512 file {} not found\n").format(source+'.sha512') self.sum_file = False + logging.info(self.return_message) def _check_write(self, target, source): + logging.debug("Start checking") self.return_state = False self.return_message = "" b = os.path.getsize(source) @@ -219,13 +228,15 @@ class Dumper(object): #pass self._progress = 100 + logging.info(self.return_message) self.return_state = True self.finished.set() def _do_persistence(self, target, label): + logging.debug("Start doing persistence partition") p = Popen(["fdisk",target], stdin = PIPE) p.communicate(input=b'n\np\n3\n\n\nw\n') - # exemple mkfs.ext4 -L mgalive-persist /dev/sdf3 + # example mkfs.ext4 -L mgalive-persist /dev/sdf3 process = Popen(['mkfs.ext4','-L', label, target+"3"]) working=True while working: @@ -237,7 +248,7 @@ class Dumper(object): else: process = None working= False - print(rc) + logging.debug("Persistence partition done") return rc |