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): def set_dir(_source, result, _unused):
try: 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): def response(widget, response):
if response == "choose_folder": if response == "choose_folder":
@@ -62,7 +62,7 @@ class ImportPreferences:
else: else:
window.schema.set_string( window.schema.set_string(
install_key, install_key,
path, str(path),
) )
except GLib.GError: except GLib.GError:
pass pass
@@ -224,7 +224,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
else: else:
self.schema.set_string( self.schema.set_string(
"lutris-cache-location", "lutris-cache-location",
path, str(path),
) )
except GLib.GError: except GLib.GError:
pass pass

View File

@@ -18,6 +18,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from pathlib import Path from pathlib import Path
from shutil import copyfile
from sqlite3 import connect from sqlite3 import connect
from time import time 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 = parent_widget.cache_dir / "cartridges" / "lutris"
db_cache_dir.mkdir(parents=True, exist_ok=True) db_cache_dir.mkdir(parents=True, exist_ok=True)
database_link_path = db_cache_dir / "pga.db" database_tmp_path = db_cache_dir / "pga.db"
database_link_path.unlink(True) copyfile(database_path, database_tmp_path)
database_link_path.symlink_to(database_path)
db_request = """ db_request = """
SELECT 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) cursor = connection.execute(db_request)
rows = cursor.fetchall() rows = cursor.fetchall()
connection.close() connection.close()
database_tmp_path.unlink(missing_ok=True)
if schema.get_boolean("steam"): if schema.get_boolean("steam"):
rows = [row for row in rows if not row[3] == "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]: if "removed" in current_games[current_game]:
( (
self.data_dir / "cartridges" / "games" / f"{current_game}.json" self.data_dir / "cartridges" / "games" / f"{current_game}.json"
).remove() ).unlink(missing_ok=True)
try: try:
( (
self.data_dir / "cartridges" / "covers" / f"{current_game}.tiff" self.data_dir / "cartridges" / "covers" / f"{current_game}.tiff"
).remove() ).unlink(missing_ok=True)
except FileNotFoundError: except FileNotFoundError:
pass pass