diff options
Diffstat (limited to 'lib/isodumper.py')
-rwxr-xr-x | lib/isodumper.py | 282 |
1 files changed, 139 insertions, 143 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 71c318d..d868cfb 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -51,6 +51,8 @@ from pydbus import SystemBus import psutil import manatools.args as args +import manatools.ui.common as common +import manatools.ui.basedialog as basedialog class NoUDisks2(Exception): @@ -160,7 +162,7 @@ class ParseCLI(args.AppArgs): super().__init__(command) -class IsoDumper(object): +class IsoDumper(basedialog.BaseDialog): def get_devices(self): self.list = self.u.find_devices() @@ -228,39 +230,40 @@ class IsoDumper(object): def backup_choosed(self): # Add .img if not specified - if not self.backup_img_name.lower().endswith('.img'): - self.backup_img_name = self.backup_img_name + ".img" - head, tail = os.path.split(self.backup_img_name) - self.backup_dest = self.backup_img_name - self.backup_select.setLabel(tail) - self.dialog.recalcLayout() - self.backupbt.setEnabled() - - def do_format(self, format_type, name): - target = self.dev.split('(')[1].split(')')[0] - info = Info(_("Formatting confirmation"), True, self.warning) - if self.ask_YesOrNo(info): - rc = self.raw_format(target, format_type, name) - self.operation = False - 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. Code {}'.format(rc)) - logging.error(message) - self.emergency(message) + self.backup_img_name = yui.YUI.app().askForSaveFileName("", "*.img", _("Backup to:")) + if self.backup_img_name != '': + if not self.backup_img_name.lower().endswith('.img'): + self.backup_img_name = self.backup_img_name + ".img" + head, tail = os.path.split(self.backup_img_name) + self.backup_dest = self.backup_img_name + self.backup_select.setLabel(tail) + self.dialog.recalcLayout() + self.backupbt.setEnabled() + + def do_format(self): + code, format_type, name = self.ask_format() + if code: + target = self.dev.split('(')[1].split(')')[0] + info = Info(_("Formatting confirmation"), True, self.warning) + if self.ask_YesOrNo(info): + rc = self.raw_format(target, format_type, name) + self.operation = False + if rc == 0: + message = _('The device was formatted successfully.') + self.logger(message) + self.success() + elif rc == 5: + message = _("An error occurred while creating a partition.") + self.logger(message) + self.emergency(message) + elif rc == 127: + message = _('Authentication error.') + self.logger(message) + self.emergency(message) + else: + message = _('An error occurred.') + self.emergency(message) + self.restore() def restore(self): self.backup_select.setDisabled() @@ -307,6 +310,7 @@ class IsoDumper(object): return rc def backup_go(self): + self.wip_unsensitive() dest = self.backup_img_name if os.path.exists(dest): info = Info(_("Backup confirmation"), True, _("Do you want to overwrite the file?")) @@ -348,10 +352,13 @@ class IsoDumper(object): self.logger(message) logging.info(message) self.success() + self.restore() else: self.emergency(message) + self.restore() def do_write(self): + self.wip_unsensitive() self.writebt.setDisabled() self.devicelist.setDisabled() self.formatbt.setDisabled() @@ -568,6 +575,7 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog return def __init__(self, debug=False): + #: placeholder for release number APP = "isodumper" DIR = "/usr/share/locale" # Call translation catalog @@ -606,10 +614,10 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog """ Init/Constructor for the 'widgets' """ - yui.YUI.app().setApplicationTitle(_("IsoDumper") + " " + version.RELEASE) + self.dialog = basedialog.BaseDialog.__init__(self, _("Isodumper {}").format(version.RELEASE), "", basedialog.DialogType.POPUP, 100, 20) yui.YUI.app().setApplicationIcon("/usr/share/icons/isodumper.png") - self.atelier = yui.YUI.widgetFactory() - self.dialog = self.atelier.createPopupDialog() + + def UIlayout(self, layout): # create the main gui # +---+-----------------+ # + banner + @@ -628,66 +636,79 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog # +---------------------+ # | refreshbt | aboutbt | helpbt | quitbt | # +---------------------+ - self.ancrage = self.atelier.createReplacePoint(self.dialog) - self.box = self.atelier.createVBox(self.ancrage) - self.bannerbox = self.atelier.createHBox(self.box) - self.banner = self.atelier.createImage(self.bannerbox, "/usr/share/isodumper/header.svg") - self.devicebox = self.atelier.createHBox(self.box) - self.devicelist = self.atelier.createComboBox(self.devicebox, _("Device to work on:"), False) + #self.ancrage = self.factory.createReplacePoint(self.dialog) + self.box = self.factory.createVBox(layout) + self.bannerbox = self.factory.createHBox(self.box) + self.banner = self.factory.createImage(self.bannerbox, "/usr/share/isodumper/header.svg") + self.devicebox = self.factory.createHBox(self.box) + self.devicelist = self.factory.createComboBox(self.devicebox, _("Device to work on:"), False) self.devicelist.setNotify() self.devicelist.setStretchable(0, True) - self.writebox = self.atelier.createHBox(self.box) - self.atelier.createLabel(self.writebox, _("Write Image:")) + self.writebox = self.factory.createHBox(self.box) + self.factory.createLabel(self.writebox, _("Write Image:")) # add file picker for image file - self.ima = self.atelier.createPushButton(self.writebox, self.ChooseImage) + self.ima = self.factory.createPushButton(self.writebox, self.ChooseImage) self.ima.setStretchable(0, True) self.ima.setDisabled() - self.atelier.createHStretch(self.writebox) - self.writebt = self.atelier.createPushButton(self.writebox, _("&Write to device")) + self.factory.createHStretch(self.writebox) + self.writebt = self.factory.createPushButton(self.writebox, _("&Write to device")) self.writebt.setDisabled() - self.persistencebox = self.atelier.createHBox(self.box) - self.persistencecol1 = self.atelier.createVBox(self.persistencebox) - self.persistencecol2 = self.atelier.createVBox(self.persistencebox) - self.persistencecb = self.atelier.createCheckBox(self.persistencecol1, + self.persistencebox = self.factory.createHBox(self.box) + self.persistencecol1 = self.factory.createVBox(self.persistencebox) + self.persistencecol2 = self.factory.createVBox(self.persistencebox) + self.persistencecb = self.factory.createCheckBox(self.persistencecol1, _("Add a persistent partition in the remaining space")) - self.persistencebox2 = self.atelier.createHBox(self.box) - self.cryptcb = self.atelier.createCheckBox(self.persistencecol1, _("Encrypt partition")) - self.cryptkey = self.atelier.createInputField(self.persistencecol2, _("Key:"), passwordMode=True) + self.persistencebox2 = self.factory.createHBox(self.box) + self.cryptcb = self.factory.createCheckBox(self.persistencecol1, _("Encrypt partition")) + self.cryptkey = self.factory.createInputField(self.persistencecol2, _("Key:"), passwordMode=True) self.persistencecb.setDisabled() self.persistencecb.setNotify() self.cryptcb.setDisabled() self.cryptcb.setNotify() self.cryptkey.setDisabled() - self.backupbox = self.atelier.createHBox(self.box) - self.atelier.createLabel(self.backupbox, _("Backup to:")) + self.backupbox = self.factory.createHBox(self.box) + self.factory.createLabel(self.backupbox, _("Backup to:")) # add file picker for backup file name - self.backup_select = self.atelier.createPushButton(self.backupbox, self.ChooseImage) + self.backup_select = self.factory.createPushButton(self.backupbox, self.ChooseImage) self.backup_select.setStretchable(0, True) self.backup_select.setDisabled() - self.atelier.createHStretch(self.backupbox) - self.backupbt = self.atelier.createPushButton(self.backupbox, _("Backup the device")) + self.factory.createHStretch(self.backupbox) + self.backupbt = self.factory.createPushButton(self.backupbox, _("Backup the device")) self.backupbt.setDisabled() - self.formatbox = self.atelier.createHBox(self.box) - self.atelier.createLabel(self.formatbox, _("Format the device in FAT, exFAT, NTFS or ext:")) - self.atelier.createHStretch(self.formatbox) - self.formatbt = self.atelier.createPushButton(self.formatbox, _("Format the device")) + self.formatbox = self.factory.createHBox(self.box) + self.factory.createLabel(self.formatbox, _("Format the device in FAT, exFAT, NTFS or ext:")) + self.factory.createHStretch(self.formatbox) + self.formatbt = self.factory.createPushButton(self.formatbox, _("Format the device")) self.formatbt.setDisabled() - self.progressbox = self.atelier.createHBox(self.box) - self.progress = self.atelier.createProgressBar(self.progressbox, _("Progress"), 100) + self.progressbox = self.factory.createHBox(self.box) + self.progress = self.factory.createProgressBar(self.progressbox, _("Progress"), 100) self.progress.setStretchable(0, True) - self.reportbox = self.atelier.createHBox(self.box) + self.reportbox = self.factory.createHBox(self.box) self.reportbox.setWeight(1, 30) - self.logview = self.atelier.createLogView(self.reportbox, _("Report"), 10) + self.logview = self.factory.createLogView(self.reportbox, _("Report"), 10) self.logview.setStretchable(0, True) - self.buttonsbox = self.atelier.createHBox(self.box) - self.refreshbt = self.atelier.createPushButton(self.devicebox, _("Refresh")) + self.buttonsbox = self.factory.createHBox(self.box) + self.refreshbt = self.factory.createPushButton(self.devicebox, _("Refresh")) self.refreshbt.setStretchable(0, True) - self.aboutbt = self.atelier.createPushButton(self.buttonsbox, _("About")) + self.aboutbt = self.factory.createPushButton(self.buttonsbox, _("About")) self.aboutbt.setStretchable(0, True) - self.helpbt = self.atelier.createPushButton(self.buttonsbox, _("Help")) + self.helpbt = self.factory.createPushButton(self.buttonsbox, _("Help")) self.helpbt.setStretchable(0, True) - self.quitbt = self.atelier.createPushButton(self.buttonsbox, _("Quit")) + self.quitbt = self.factory.createPushButton(self.buttonsbox, _("Quit")) self.quitbt.setStretchable(0, True) + # Connect events + self.eventManager.addWidgetEvent(self.quitbt, self.confirm_close) + self.eventManager.addWidgetEvent(self.ima, self.ask_image) + self.eventManager.addWidgetEvent(self.persistencecb, self.check_persistence) + self.eventManager.addWidgetEvent(self.writebt, self.do_write) + self.eventManager.addWidgetEvent(self.cryptcb, self.check_encryt) + self.eventManager.addWidgetEvent(self.backupbt, self.backup_go) + self.eventManager.addWidgetEvent(self.backup_select, self.backup_choosed) + self.eventManager.addWidgetEvent(self.formatbt, self.do_format) + self.eventManager.addWidgetEvent(self.devicelist, self.device_selected) + self.eventManager.addWidgetEvent(self.refreshbt, self.update_list) + self.eventManager.addWidgetEvent(self.helpbt, self.help_dialog) + self.eventManager.addWidgetEvent(self.aboutbt, self.aboutDialog) self.u = None try: self.u = UDisks2() @@ -702,7 +723,33 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog exit() self.device_selected() self.dialog.recalcLayout() - self.ancrage.showChild() + self.uEventQueue = SimpleQueue() + self.glib_loop = GLib.MainLoop() + self.glib_thread = threading.Thread(target=self.glib_mainloop, args=(self.glib_loop,)) + self.glib_thread.start() + + def ask_image(self): + self.img_name = yui.YUI.app().askForExistingFile("", "*.iso *.img", self.ChooseImage) + if self.img_name != "": + self.ima.setLabel(os.path.basename(self.img_name)) + self.dialog.recalcLayout() + self.writebt.setEnabled() + self.activate_devicelist() + self.persistencecb.setEnabled() + + def check_persistence(self): + if self.persistencecb.isChecked(): + self.cryptcb.setEnabled() + else: + self.cryptcb.setDisabled() + self.cryptkey.setDisabled() + self.cryptcb.setChecked(False) + + def check_encryt(self): + if self.cryptcb.isChecked(): + self.cryptkey.setEnabled() + else: + self.cryptkey.setDisabled() def ask_format(self): atelier = yui.YUI.widgetFactory() @@ -796,77 +843,26 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog dlg.setMinSize(60, 8) return dlg.show() == yui.YMGAMessageBox.B_ONE - def handleevent(self): + def doSomethingIntoLoop(self): self.traitement = None - while True: - event = self.dialog.waitForEvent() - if event.eventType() == yui.YEvent.CancelEvent: - self.close() - break - if event.widget() == self.quitbt: - self.close() - break - if event.widget() == self.ima: - self.img_name = yui.YUI.app().askForExistingFile("", "*.iso *.img", self.ChooseImage) - if self.img_name != "": - self.ima.setLabel(os.path.basename(self.img_name)) - self.dialog.recalcLayout() - self.writebt.setEnabled() - self.activate_devicelist() - self.persistencecb.setEnabled() - if event.widget() == self.persistencecb: - print(self.persistencecb.value) - if self.persistencecb.isChecked(): - self.cryptcb.setEnabled() - else: - self.cryptcb.setDisabled() - self.cryptkey.setDisabled() - self.cryptcb.setChecked(False) - if event.widget() == self.cryptcb: - if self.cryptcb.isChecked(): - self.cryptkey.setEnabled() - else: - self.cryptkey.setDisabled() - if event.widget() == self.writebt: - self.wip_unsensitive() - self.do_write() - self.restore() - if event.widget() == self.backupbt: - self.wip_unsensitive() - self.backup_go() - self.restore() - if event.widget() == self.backup_select: - self.backup_img_name = yui.YUI.app().askForSaveFileName("", "*.img", _("Backup to:")) - if self.backup_img_name != '': - self.backup_choosed() - if event.widget() == self.formatbt: - code, format_type, name = self.ask_format() - if code: - self.do_format(format_type, name) - self.restore() - if event.widget() == self.devicelist: - self.device_selected() - try: - if event.widget() == self.refreshbt: - self.update_list() - except: - pass - try: - if event.widget() == self.helpbt: - self.help_dialog() - except: - pass - try: - if event.widget() == self.quitbt: - self.confirm_close() - except: - pass - if event.widget() == self.aboutbt: - self.aboutDialog() - - def run(self): + #if event.eventType() == yui.YEvent.CancelEvent: + #self.confirm_close() + #break + try: + item = self.uEventQueue.get_nowait() + if item['event'] == "device-changed": + self.update_list_on_event() + except Exception as e: + pass + + def run(self, debug=False): + + self._setupUI() + + self._running = True + self.timeout = 100 try: - self.handleevent() + self._handleEvents() except Exception: import traceback traceback.print_exc() |