Commit 500beda9 authored by rgaudin's avatar rgaudin
Browse files

SD-card partition check enhancement

- Moved SD-card partition check back to button action
- SD-card partition check timesout after 10s to prevent some freezes
parent 47d0eb3f
2.0-rc18
* Moved SD-card partition check back to button action
* SD-card partition check timesout after 10s to prevent some freezes
2.0-rc17
* Fixed bug prevent non-sdcard builds via GUI
* Better SD-card partition check dialog
......
......@@ -111,6 +111,13 @@ def subprocess_pretty_check_call(cmd, logger, stdin=None, as_admin=False):
)
def subprocess_timed_output(cmd, logger, timeout=10):
logger.std("Getting output of " + str(cmd))
return subprocess.check_output(
cmd, universal_newlines=True, timeout=timeout
).splitlines()
def subprocess_external(cmd, logger):
""" spawn a new process without capturing nor watching it """
logger.std("Opening: " + str(cmd))
......@@ -370,9 +377,7 @@ def sd_has_single_partition(sd_card, logger):
try:
if sys.platform == "darwin":
disk_prefix = re.sub(r"\/dev\/disk([0-9]+)", r"disk\1s", sd_card)
lines = subprocess_pretty_call(
["diskutil", "list", sd_card], logger, check=True, decode=True
)
lines = subprocess_timed_output(["diskutil", "list", sd_card], logger)
nb_partitions = len(
[
line.strip().rsplit(" ", 1)[-1].replace(disk_prefix, "").strip()
......@@ -385,9 +390,7 @@ def sd_has_single_partition(sd_card, logger):
disk_prefix = re.sub(
r".+PHYSICALDRIVE([0-9+])", r"Disk #\1, Partition #", sd_card
)
lines = subprocess_pretty_call(
["wmic", "partition"], logger, check=True, decode=True
)
lines = subprocess_timed_output(["wmic", "partition"], logger)
nb_partitions = len(
[
re.sub(r".+" + disk_prefix + r"([0-9]+).+", r"\1", line)
......@@ -398,9 +401,7 @@ def sd_has_single_partition(sd_card, logger):
return nb_partitions == 1
elif sys.platform == "linux":
disk_prefix = re.sub(r"\/dev\/([a-z0-9]+)", r"─\1", sd_card)
lines = subprocess_pretty_call(
["/bin/lsblk", sd_card], logger, check=True, decode=True
)
lines = subprocess_timed_output(["/bin/lsblk", sd_card], logger)
nb_partitions = len(
[
line.strip().split(" ", 1)[0].replace(disk_prefix, "").strip()
......
......@@ -356,7 +356,7 @@ class Application:
"changed", lambda _: self.update_free_space()
)
self.component.sd_card_combobox.connect(
"changed", lambda w: self.activate_sd_clean_button(w)
"changed", lambda w: self.on_sdcard_selection_change(w)
)
self.component.sd_card_refresh_button.connect(
"clicked", self.sd_card_refresh_button_clicked
......@@ -1749,6 +1749,7 @@ class Application:
condition = sd_has_single_partition(sd_card, self.logger)
validate_label(self.component.sd_card_label, condition)
validate_label(self.component.sd_card_error_label, condition)
self.component.sd_card_error_label.set_visible(not condition)
all_valid = all_valid and condition
else:
condition = output_size > 0
......@@ -1850,20 +1851,14 @@ class Application:
self.component.run_window.show()
threading.Thread(target=target, daemon=True).start()
def activate_sd_clean_button(self, button):
def on_sdcard_selection_change(self, button):
has_card = self.component.sd_card_combobox.get_active() != -1
self.component.clean_sd_button.set_visible(has_card)
# update label for selected SD-card
sd_card = self.get_sd_card()
if sd_card:
# check that SD card has a single partition (clean state)
condition = sd_has_single_partition(sd_card, self.logger)
else:
condition = True
validate_label(self.component.sd_card_label, condition)
validate_label(self.component.sd_card_error_label, condition)
self.component.sd_card_error_label.set_visible(not condition)
# remove warnings on combo change
validate_label(self.component.sd_card_label, True)
validate_label(self.component.sd_card_error_label, True)
self.component.sd_card_error_label.set_visible(False)
def sd_card_refresh_button_clicked(self, button):
self.refresh_disk_list()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment