From 438dc488e64d11f1767a3e35df72233ce2cae246 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Thu, 14 Sep 2023 16:35:44 -0700 Subject: [PATCH] More runtime simplification --- lutris/api.py | 2 +- lutris/runners/runner.py | 2 +- lutris/runtime.py | 31 +++++++++++-------------------- lutris/util/extract.py | 2 +- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lutris/api.py b/lutris/api.py index 0668889bc..046d34c7f 100644 --- a/lutris/api.py +++ b/lutris/api.py @@ -1,10 +1,10 @@ """Functions to interact with the Lutris REST API""" import functools -import time import json import os import re import socket +import time import urllib.error import urllib.parse import urllib.request diff --git a/lutris/runners/runner.py b/lutris/runners/runner.py index 436da3ab2..52bb9e06f 100644 --- a/lutris/runners/runner.py +++ b/lutris/runners/runner.py @@ -458,7 +458,7 @@ class Runner: # pylint: disable=too-many-public-methods self.extract(archive=runner_archive, dest=dest, merge_single=merge_single, callback=callback) def extract(self, archive=None, dest=None, merge_single=None, callback=None): - if not system.path_exists(archive): + if not system.path_exists(archive, exclude_empty=True): raise RunnerInstallationError(_("Failed to extract {}").format(archive)) try: extract_archive(archive, dest, merge_single=merge_single) diff --git a/lutris/runtime.py b/lutris/runtime.py index be15d4982..dc7357d5b 100644 --- a/lutris/runtime.py +++ b/lutris/runtime.py @@ -6,7 +6,7 @@ import time from gi.repository import GLib from lutris import settings -from lutris.api import download_runtime_versions, load_runtime_versions, get_time_from_api_date +from lutris.api import download_runtime_versions, get_time_from_api_date, load_runtime_versions from lutris.util import http, jobs, system, update_cache from lutris.util.downloader import Downloader from lutris.util.extract import extract_archive @@ -68,7 +68,7 @@ class Runtime: local_updated_at = self.get_updated_at() if not local_updated_at: - logger.warning("Runtime %s is not available locally", self.name) + logger.debug("Runtime %s is not available locally", self.name) return True if local_updated_at and local_updated_at >= remote_updated_at: @@ -211,7 +211,6 @@ class Runtime: class RuntimeUpdater: """Class handling the runtime updates""" - status_updater = None update_functions = [] downloaders = {} @@ -220,7 +219,10 @@ class RuntimeUpdater: self.force = force self.pci_ids = pci_ids or [] self.runtime_versions = {} - self.add_update("runtime", self._update_runtime_components, hours=12) + if RUNTIME_DISABLED: + logger.warning("Runtime disabled, not updating it.") + else: + self.add_update("runtime", self._update_runtime, hours=12) # self.add_update("runners", self._update_runners, hours=12) def add_update(self, key: str, update_function, hours): @@ -258,13 +260,12 @@ class RuntimeUpdater: return 0 return sum(downloader.progress_fraction for downloader in self.downloaders.values()) / len(self.downloaders) - def _update_runtime_components(self) -> int: + def _update_runtime(self) -> None: """Launch the update process""" - if RUNTIME_DISABLED: - logger.warning("Runtime disabled, not updating it.") - return 0 - - for remote_runtime in self._iter_remote_runtimes(): + for name, remote_runtime in self.runtime_versions.get("runtimes", {}).items(): + if remote_runtime["architecture"] == "x86_64" and not LINUX_SYSTEM.is_64_bit: + logger.debug("Skipping runtime %s for %s", name, remote_runtime["architecture"]) + continue runtime = Runtime(remote_runtime["name"], self) if remote_runtime["url"]: downloader = runtime.download(remote_runtime) @@ -273,16 +274,6 @@ class RuntimeUpdater: else: runtime.download_components() - return len(self.downloaders) - - def _iter_remote_runtimes(self): - for name, runtime in self.runtime_versions.get("runtimes", {}).items(): - # Skip 64bit runtimes on 32 bit systems - if runtime["architecture"] == "x86_64" and not LINUX_SYSTEM.is_64_bit: - logger.debug("Skipping runtime %s for %s", name, runtime["architecture"]) - continue - yield runtime - def get_env(version: str = None, prefer_system_libs: bool = False, wine_path: str = None) -> dict: """Return a dict containing LD_LIBRARY_PATH env var diff --git a/lutris/util/extract.py b/lutris/util/extract.py index f78360879..a2e955e62 100644 --- a/lutris/util/extract.py +++ b/lutris/util/extract.py @@ -122,7 +122,7 @@ def get_archive_opener(extractor): return opener, mode -def extract_archive(path, to_directory=".", merge_single=True, extractor=None): +def extract_archive(path: str, to_directory: str = ".", merge_single: bool = True, extractor=None): path = os.path.abspath(path) logger.debug("Extracting %s to %s", path, to_directory)