diff options
author | Papoteur <papoteur@mageia.org> | 2018-03-07 18:22:51 +0100 |
---|---|---|
committer | Papoteur <papoteur@mageia.org> | 2018-03-16 11:17:42 +0100 |
commit | 0481b62e786c6b615a4ad3ed9ddd648a18e7805c (patch) | |
tree | 11b8df4b4add85209b46f1a9141b8012ec40bd4e /lib | |
parent | 6f3e123eab4deefbfa6ade7b268b19ab1e4309b4 (diff) | |
download | isodumper-0481b62e786c6b615a4ad3ed9ddd648a18e7805c.tar isodumper-0481b62e786c6b615a4ad3ed9ddd648a18e7805c.tar.gz isodumper-0481b62e786c6b615a4ad3ed9ddd648a18e7805c.tar.bz2 isodumper-0481b62e786c6b615a4ad3ed9ddd648a18e7805c.tar.xz isodumper-0481b62e786c6b615a4ad3ed9ddd648a18e7805c.zip |
Use pydbus also for udisk2
Use gettext.install
Suppress usage of user on command line
Adjust writing the logfile
Enable call as module with a run function
Cleaning
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/isodumper.py | 80 |
1 files changed, 30 insertions, 50 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 8a1525c..c84baf5 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -44,15 +44,13 @@ import time # set the locale to de/utf-8 #locale.setlocale(locale.LC_ALL, "") #log = yui.YUILog.instance() -#log.setLogFileName("debug.log") +#log.setLogFileName("isodumper.log") #log.enableDebugLogging( True ) import os, re import io import gettext -from gettext import gettext as _ from subprocess import call, Popen, PIPE -import dbus from pydbus import SystemBus from gi.repository import GLib @@ -67,19 +65,14 @@ class UDisks2(object): DRIVE = 'org.freedesktop.UDisks2.Drive' def __init__(self): - self.bus = dbus.SystemBus() + self.bus = SystemBus() try: - self.bus.get_object('org.freedesktop.UDisks2', - '/org/freedesktop/UDisks2') - except dbus.exceptions.DBusException as e: - if getattr(e, '_dbus_error_name', None) == 'org.freedesktop.DBus.Error.ServiceUnknown': - raise NoUDisks2() - raise + self.iface = self.bus.get('org.freedesktop.UDisks2') + except : + raise NoUDisks2() def find_devices(self): - proxy = self.bus.get_object("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2") - iface = dbus.Interface(proxy, "org.freedesktop.UDisks2") - _udisks2_obj_manager = dbus.Interface(iface, "org.freedesktop.DBus.ObjectManager") + _udisks2_obj_manager = self.iface["org.freedesktop.DBus.ObjectManager"] objects=_udisks2_obj_manager.GetManagedObjects() re_drive = re.compile('(?P<path>.*?/drives/(?P<id>.*))') re_block = re.compile('(?P<path>.*?/block_devices/(?P<id>.*))') @@ -164,7 +157,7 @@ class IsoDumper(object): def backup_sel(self): if self.backup_bname.get_current_folder_uri() == None : - self.backup_bname.set_current_folder_uri('file:///home/'+self.user) + self.backup_bname.set_current_folder_uri('file://'+os.path.expanduser('~')) self.backup_bname.set_current_name(self.device_name+".img") self.choose.run() @@ -288,10 +281,8 @@ class IsoDumper(object): return self.ima.setDisabled() self.writebt.setDisabled() - # TODO Appel via DBus self.progress.setLabel(_('Writing {source} to {target}').format(source=source.split('/')[-1],target=target.split('/')[-1])) self.logger(_('Executing copy from ')+source+_(' to ')+target) - print(_('Writing {source} to {target}').format(source=source.split('/')[-1],target=target.split('/')[-1])) bus = SystemBus() iface = bus.get("org.mageia.Magiback","Isodumper") success, message = iface.do_unmount(target) @@ -305,7 +296,7 @@ class IsoDumper(object): time.sleep(1) success, message = iface.end() if success: - self.logger(_('Image {source} successfully written to {target}').format( source=source.split('/')[-1], target=target) + self.logger(_('Image {source} successfully written to {target}').format( source=source.split('/')[-1], target=target)) self.logger(_('Bytes written: ')+str(b)) self.check_write(target, b) self.success() @@ -403,18 +394,9 @@ class IsoDumper(object): #exit(0) def write_logfile(self): - import pwd - pw = pwd.getpwnam(self.user) - uid = pw.pw_uid - gid=pw.pw_gid - if (self.user != 'root') and (self.user !=''): - logpath='/home/'+self.user+'/.isodumper' - os.setgid(gid) - os.setuid(uid) - if not(os.path.isdir(logpath)): + logpath = os.path.join(os.path.expanduser('~'),'/.isodumper') + if not(os.path.isdir(logpath)): os.mkdir(logpath) - else: - logpath='/root' logfile=open(logpath+'/isodumper.log',"w", encoding="utf-8") logfile.write(self.logview.logText()) logfile.close() @@ -459,19 +441,16 @@ NTFS or ext. You can specify a volume name and the format in a new dialog box.<B if self.ask_OK(info) : return - def __init__(self,user): + def __init__(self): APP="isodumper" DIR="/usr/share/locale" self.RELEASE="v0.90" + # Call translation catalog + gettext.install(APP, localedir=DIR, names=('ngettext',)) - gettext.install('isodumper', localedir='/usr/share/locale', names=('ngettext',)) - #gettext.bindtextdomain(APP, DIR) - #gettext.textdomain(APP) - - # for the localisation of log file - self.user = user - - # define size of the selected device + #TODO Read log level from command line + + # define size of the selected device self.deviceSize=0 # Operation running @@ -677,7 +656,8 @@ NTFS or ext. You can specify a volume name and the format in a new dialog box.<B self.close() break if event.widget() == self.ima: - self.img_name=yui.YUI.app().askForExistingFile('file:///home/'+self.user,"*.iso *.img",self.ChooseImage) + default = 'file://'+os.path.expanduser('~') + self.img_name=yui.YUI.app().askForExistingFile(default,"*.iso *.img",self.ChooseImage) self.ima.setLabel(os.path.basename(self.img_name)) self.dialog.recalcLayout() self.writebt.setEnabled() @@ -720,17 +700,17 @@ NTFS or ext. You can specify a volume name and the format in a new dialog box.<B if event.widget() == self.aboutbt: self.aboutDialog() -if __name__ == "__main__": - import sys - user=sys.argv[1] - app = IsoDumper(user) - try: - app.handleevent() - except: - yui.YDialog.deleteAllDialogs() - finally: - # next line seems to be a workaround to prevent the qt-app from crashing - # see https://github.com/libyui/libyui-qt/issues/41 - yui.YUILoader.deleteUI() + def run(self): + try: + self.handleevent() + except: + yui.YDialog.deleteAllDialogs() + finally: + # next line seems to be a workaround to prevent the qt-app from crashing + # see https://github.com/libyui/libyui-qt/issues/41 + yui.YUILoader.deleteUI() +if __name__ == "__main__": + app = IsoDumper() + app.run() |