Commit 6eefb4ef authored by rgaudin's avatar rgaudin
Browse files

Windows-specific fixes:

- tempfile needs delete=False in catalogs download.
- windows is already in admin mode
- device path for etcher-cli is eventually identical to others
- build_zim_store() can't be called from within the thread (freezes UI forever)
parent 2c1e66f1
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
import os
import tempfile
import yaml
......@@ -24,12 +25,13 @@ def fetch_catalogs(logger):
logger.std("downloading catalogs...")
try:
for catalog in CATALOGS:
fpath = tempfile.NamedTemporaryFile(suffix=".yml")
dlf = download_file(catalog.get("url"), fpath.name, logger)
fpath.seek(0) # reset as we'll read it right away
tmpfile = tempfile.NamedTemporaryFile(suffix=".yml", delete=False)
dlf = download_file(catalog.get("url"), tmpfile.name, logger)
tmpfile.seek(0) # reset as we'll read it right away
if dlf.successful:
catalogs.append(yaml.load(fpath.read()))
fpath.close()
catalogs.append(yaml.load(tmpfile.read()))
tmpfile.close()
os.unlink(tmpfile.name)
else:
raise ValueError("Unable to download {}".format(catalog.get("url")))
except Exception as exp:
......
......@@ -6,13 +6,12 @@ import sys
import time
import signal
import ctypes
import random
import tempfile
import threading
import subprocess
import data
from util import CLILogger, ONE_MiB, human_readable_size
from util import CLILogger
# windows-only flags to prevent sleep on executing thread
......@@ -46,7 +45,8 @@ def startup_info_args():
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
cf = subprocess.CREATE_NEW_PROCESS_GROUP
else:
si = cf = None
si = None
cf = 0
return {"startupinfo": si, "creationflags": cf}
......@@ -176,21 +176,23 @@ class EtcherWriterThread(threading.Thread):
if log_to_file:
log_file = tempfile.NamedTemporaryFile(suffix=".log")
cmd = get_admin_command(
[
os.path.join(data.data_dir, "etcher-cli", "etcher"),
"-c",
"-y",
"-u",
"-d",
'"{}"'.format(device_fpath)
if sys.platform == "win32" # \\.\PHYSICALDRIVE1 string needs quotes
else device_fpath,
image_fpath,
],
from_gui=not from_cli,
log_to=log_file.name if log_to_file else None,
)
cmd = [
os.path.join(data.data_dir, "etcher-cli", "etcher"),
"-c",
"-y",
"-u",
"-d",
device_fpath,
image_fpath,
]
# handle sudo or GUI alternative for linux and macOS
if sys.platform in ("linux", "darwin"):
cmd = get_admin_command(
cmd,
from_gui=not from_cli,
log_to=log_file.name if log_to_file else None,
)
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **startup_info_args()
)
......
......@@ -507,8 +507,6 @@ class Application:
def download_catalogs(self):
self.catalogs = get_catalogs(CLILogger())
if self.catalogs is not None:
self.build_zim_store()
return self.catalogs is not None
def ensure_catalogs(self):
......@@ -523,6 +521,9 @@ class Application:
parent=self.component.window,
)
return False
# now that we have the catalogs, build the ZIM store if not already done
if not len(self.component.zim_list_store):
self.build_zim_store()
return True
def build_zim_store(self):
......
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