Unmount partitions before dding iso image.

Catch more exceptions.
Avoid using keyword 'type' for a variable name.
pull/376/head
shinji-s 6 years ago
parent 6f75388450
commit 354a8e6688

@ -21,13 +21,22 @@ from . import config
from . import iso
from . import osdriver
from . import progressbar
from . import udisks
from . import usb
if platform.system() == "Windows":
import win32com.client
def dd_iso_image(dd_progress_thread):
try:
_dd_iso_image(dd_progress_thread)
except:
o = io.StringIO()
traceback.print_exc(None, o)
log(o.getvalue())
dd_progress_thread.set_error(o.getvalue())
def _dd_iso_image(dd_progress_thread):
pbar = progressbar.ProgressBar(
maxval=100,
widgets=[
@ -42,17 +51,22 @@ def dd_iso_image(dd_progress_thread):
config.imager_percentage = percentage
pbar.update(percentage)
unmounted_contexts = [
(usb.UnmountedContext(p[0], config.update_usb_mount), p[0]) for p
in udisks.find_partitions_on(config.usb_disk)]
really_unmounted = []
try:
with usb.UnmountedContext(config.usb_disk, config.update_usb_mount):
error = osdriver.dd_iso_image(
config.image_path, config.usb_disk, gui_update)
if error:
dd_progress_thread.set_error(error)
except:
o = io.StringIO()
traceback.print_exc(None, o)
log(o.getvalue())
dd_progress_thread.set_error(o.getvalue())
for c, pname in unmounted_contexts:
c.__enter__()
really_unmounted.append((c, pname))
error = osdriver.dd_iso_image(
config.image_path, config.usb_disk, gui_update)
if error:
dd_progress_thread.set_error(error)
finally:
for c, pname in really_unmounted:
c.__exit__(None, None, None)
class Imager(QtWidgets.QMainWindow, Ui_MainWindow):

@ -15,18 +15,25 @@ import os
import re
def node_mountpoint(node):
def de_mangle_mountpoint(raw):
return raw.replace('\\040', ' ').replace('\\011', '\t') \
.replace('\\012', '\n').replace('\\0134', '\\')
def de_mangle(raw):
return raw.replace('\\040', ' ').replace('\\011', '\t').replace('\\012',
'\n').replace('\\0134', '\\')
def node_mountpoint(node):
for line in open('/proc/mounts').readlines():
line = line.split()
if line[0] == node:
return de_mangle(line[1])
return de_mangle_mountpoint(line[1])
return None
def find_partitions_on(disk):
assert not disk[-1:].isdigit()
with open('/proc/mounts') as f:
relevant_lines = [l.split(' ') for l in f.readlines()
if l.startswith(disk)]
return [ [v[0], de_mangle_mountpoint(v[1])] + v[2:] for v
in relevant_lines ]
class NoUDisks1(Exception):
pass

@ -476,7 +476,7 @@ class UnmountedContext:
gen.log("Unmounted %s" % self.usb_disk)
return self
def __exit__(self, type, value, traceback_):
def __exit__(self, type_, value, traceback_):
if not self.is_relevant:
return
os.sync() # This should not be strictly necessary

Loading…
Cancel
Save