Pathlib fixes

This commit is contained in:
kramo
2023-04-02 08:06:09 +02:00
parent 960eaa1949
commit 7e968a9ac7
3 changed files with 10 additions and 9 deletions

View File

@@ -41,7 +41,7 @@ class ImportPreferences:
):
def set_dir(_source, result, _unused):
try:
path = window.file_chooser.select_folder_finish(result).get_path()
path = Path(window.file_chooser.select_folder_finish(result).get_path())
def response(widget, response):
if response == "choose_folder":
@@ -62,7 +62,7 @@ class ImportPreferences:
else:
window.schema.set_string(
install_key,
path,
str(path),
)
except GLib.GError:
pass
@@ -224,7 +224,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
else:
self.schema.set_string(
"lutris-cache-location",
path,
str(path),
)
except GLib.GError:
pass

View File

@@ -18,6 +18,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from pathlib import Path
from shutil import copyfile
from sqlite3 import connect
from time import time
@@ -56,9 +57,8 @@ def lutris_parser(parent_widget):
db_cache_dir = parent_widget.cache_dir / "cartridges" / "lutris"
db_cache_dir.mkdir(parents=True, exist_ok=True)
database_link_path = db_cache_dir / "pga.db"
database_link_path.unlink(True)
database_link_path.symlink_to(database_path)
database_tmp_path = db_cache_dir / "pga.db"
copyfile(database_path, database_tmp_path)
db_request = """
SELECT
@@ -73,10 +73,11 @@ def lutris_parser(parent_widget):
;
"""
connection = connect(database_link_path)
connection = connect(database_tmp_path)
cursor = connection.execute(db_request)
rows = cursor.fetchall()
connection.close()
database_tmp_path.unlink(missing_ok=True)
if schema.get_boolean("steam"):
rows = [row for row in rows if not row[3] == "steam"]

View File

@@ -107,11 +107,11 @@ class CartridgesWindow(Adw.ApplicationWindow):
if "removed" in current_games[current_game]:
(
self.data_dir / "cartridges" / "games" / f"{current_game}.json"
).remove()
).unlink(missing_ok=True)
try:
(
self.data_dir / "cartridges" / "covers" / f"{current_game}.tiff"
).remove()
).unlink(missing_ok=True)
except FileNotFoundError:
pass