From ea4ffe2c9330ffbd43ac1c671b9af7e659ab1ce6 Mon Sep 17 00:00:00 2001 From: anne Date: Fri, 1 Sep 2023 23:15:50 +0200 Subject: [PATCH] Fixed popping inside iteration & fixed themes folder not getting created --- ostools.py | 4 ++-- theme_repo_manager.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ostools.py b/ostools.py index fd63f32..83e198f 100644 --- a/ostools.py +++ b/ostools.py @@ -52,14 +52,14 @@ def validateDataDir(): errorlogs = os.path.join(datadir, "errorlogs") backup = os.path.join(datadir, "backup") themes = os.path.join(datadir, "themes") - # ~lisanne Datadir/themes for repository themes + # ~lisanne `datadir/themes` is for repository installed themes # Apparently everything checks this folder for themes already # So hopefully im not plugging into an existng system on accident js_pchum = os.path.join(datadir, "pesterchum.js") js_manifest = os.path.join(datadir, "manifest.js") - dirs = [datadir, profile, quirks, logs, errorlogs, backup] + dirs = [datadir, profile, quirks, logs, themes, errorlogs, backup] for d in dirs: if not os.path.isdir(d) or not os.path.exists(d): os.makedirs(d, exist_ok=True) diff --git a/theme_repo_manager.py b/theme_repo_manager.py index 512f4df..ce57a95 100644 --- a/theme_repo_manager.py +++ b/theme_repo_manager.py @@ -63,6 +63,9 @@ class ThemeManager(QtCore.QObject): self.manifest = json.load(f) PchumLog.debug("Manifest.js loaded with: %s", self.manifest) self.config = config + # TODO: maybe make seperate QNetworkAccessManagers for theme downloads, database fetches, and integrity checkfile + # OR figure out how to connect the signal to tasks instead of the whole object + # That way we dont have to figure out what got downloaded afterwards, and can just have a _on_reply_theme & _on_reply_database or something self.NAManager = QtNetwork.QNetworkAccessManager() self.NAManager.finished[QtNetwork.QNetworkReply].connect(self._on_reply) self.validate_manifest() @@ -99,6 +102,7 @@ class ThemeManager(QtCore.QObject): def validate_manifest(self): # Checks if the themes the manifest claims are installed actually exists # Removes them from the manifest if they dont + to_pop = set() all_themes = self.config.availableThemes() for theme_name in self.manifest: if not theme_name in all_themes: @@ -106,7 +110,11 @@ class ThemeManager(QtCore.QObject): "Supposedly installed theme %s from the manifest seems to have been deleted, removing from manifest now", theme_name, ) - self.manifest.pop(theme_name) + # Cannot be popped while iterating! + to_pop.add(theme_name) + + for theme_name in to_pop: + self.manifest.pop(theme_name) def download_theme(self, theme_name): # Downloads the theme .zip