Make import time global, fix sorting bug
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from time import time
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from gi.repository import Adw, Gio, GLib, Gtk
|
from gi.repository import Adw, Gio, GLib, Gtk
|
||||||
@@ -55,6 +56,8 @@ class Importer(ErrorProducer):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
shared.import_time = int(time())
|
||||||
|
|
||||||
# TODO: make this stateful
|
# TODO: make this stateful
|
||||||
shared.store.new_game_ids = set()
|
shared.store.new_game_ids = set()
|
||||||
shared.store.duplicate_game_ids = set()
|
shared.store.duplicate_game_ids = set()
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
# 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 time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
@@ -38,13 +37,12 @@ class BottlesSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
data = self.source.locations.data["library.yml"].read_text("utf-8")
|
data = self.source.locations.data["library.yml"].read_text("utf-8")
|
||||||
library: dict = yaml.safe_load(data)
|
library: dict = yaml.safe_load(data)
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
for entry in library.values():
|
for entry in library.values():
|
||||||
# Build game
|
# Build game
|
||||||
values = {
|
values = {
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"name": entry["name"],
|
"name": entry["name"],
|
||||||
"game_id": self.source.game_id_format.format(game_id=entry["id"]),
|
"game_id": self.source.game_id_format.format(game_id=entry["id"]),
|
||||||
"executable": self.source.make_executable(
|
"executable": self.source.make_executable(
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import os
|
|||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from gi.repository import GLib, Gtk
|
from gi.repository import GLib, Gtk
|
||||||
@@ -37,8 +36,6 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""Generator method producing games"""
|
"""Generator method producing games"""
|
||||||
|
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
icon_theme = Gtk.IconTheme.new()
|
icon_theme = Gtk.IconTheme.new()
|
||||||
|
|
||||||
search_paths = [
|
search_paths = [
|
||||||
@@ -125,7 +122,7 @@ class DesktopSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
values = {
|
values = {
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"name": name,
|
"name": name,
|
||||||
"game_id": f"desktop_{entry.stem}",
|
"game_id": f"desktop_{entry.stem}",
|
||||||
"executable": f"{launch_command} {launch_arg}",
|
"executable": f"{launch_command} {launch_arg}",
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
# 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 time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from gi.repository import GLib, Gtk
|
from gi.repository import GLib, Gtk
|
||||||
@@ -35,8 +34,6 @@ class FlatpakSourceIterable(SourceIterable):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""Generator method producing games"""
|
"""Generator method producing games"""
|
||||||
|
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
icon_theme = Gtk.IconTheme.new()
|
icon_theme = Gtk.IconTheme.new()
|
||||||
icon_theme.add_search_path(str(self.source.locations.data["icons"]))
|
icon_theme.add_search_path(str(self.source.locations.data["icons"]))
|
||||||
|
|
||||||
@@ -79,7 +76,7 @@ class FlatpakSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
values = {
|
values = {
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"name": name,
|
"name": name,
|
||||||
"game_id": self.source.game_id_format.format(game_id=flatpak_id),
|
"game_id": self.source.game_id_format.format(game_id=flatpak_id),
|
||||||
"executable": self.source.make_executable(flatpak_id=flatpak_id),
|
"executable": self.source.make_executable(flatpak_id=flatpak_id),
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ from functools import cached_property
|
|||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import time
|
|
||||||
from typing import Iterable, NamedTuple, Optional, TypedDict
|
from typing import Iterable, NamedTuple, Optional, TypedDict
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
@@ -91,9 +90,7 @@ class SubSourceIterable(Iterable):
|
|||||||
logging.debug("Using Heroic %s library.json path %s", self.name, path)
|
logging.debug("Using Heroic %s library.json path %s", self.name, path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def process_library_entry(
|
def process_library_entry(self, entry: HeroicLibraryEntry) -> SourceIterationResult:
|
||||||
self, entry: HeroicLibraryEntry, added_time: int
|
|
||||||
) -> SourceIterationResult:
|
|
||||||
"""Build a Game from a Heroic library entry"""
|
"""Build a Game from a Heroic library entry"""
|
||||||
|
|
||||||
app_name = entry["app_name"]
|
app_name = entry["app_name"]
|
||||||
@@ -102,7 +99,7 @@ class SubSourceIterable(Iterable):
|
|||||||
# Build game
|
# Build game
|
||||||
values = {
|
values = {
|
||||||
"source": f"{self.source.source_id}_{self.service}",
|
"source": f"{self.source.source_id}_{self.service}",
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"name": entry["title"],
|
"name": entry["title"],
|
||||||
"developer": entry.get("developer", None),
|
"developer": entry.get("developer", None),
|
||||||
"game_id": self.source.game_id_format.format(
|
"game_id": self.source.game_id_format.format(
|
||||||
@@ -127,7 +124,7 @@ class SubSourceIterable(Iterable):
|
|||||||
Iterate through the games with a generator
|
Iterate through the games with a generator
|
||||||
:raises InvalidLibraryFileError: on initial call if the library file is bad
|
:raises InvalidLibraryFileError: on initial call if the library file is bad
|
||||||
"""
|
"""
|
||||||
added_time = int(time())
|
|
||||||
try:
|
try:
|
||||||
iterator = iter(
|
iterator = iter(
|
||||||
path_json_load(self.library_path)[self.library_json_entries_key]
|
path_json_load(self.library_path)[self.library_json_entries_key]
|
||||||
@@ -138,7 +135,7 @@ class SubSourceIterable(Iterable):
|
|||||||
) from error
|
) from error
|
||||||
for entry in iterator:
|
for entry in iterator:
|
||||||
try:
|
try:
|
||||||
yield self.process_library_entry(entry, added_time)
|
yield self.process_library_entry(entry)
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"Skipped invalid %s game %s",
|
"Skipped invalid %s game %s",
|
||||||
@@ -176,7 +173,7 @@ class StoreSubSourceIterable(SubSourceIterable):
|
|||||||
def is_installed(self, app_name: str) -> bool:
|
def is_installed(self, app_name: str) -> bool:
|
||||||
return app_name in self.installed_app_names
|
return app_name in self.installed_app_names
|
||||||
|
|
||||||
def process_library_entry(self, entry, added_time):
|
def process_library_entry(self, entry):
|
||||||
# Skip games that are not installed
|
# Skip games that are not installed
|
||||||
app_name = entry["app_name"]
|
app_name = entry["app_name"]
|
||||||
if not self.is_installed(app_name):
|
if not self.is_installed(app_name):
|
||||||
@@ -188,7 +185,7 @@ class StoreSubSourceIterable(SubSourceIterable):
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
# Process entry as normal
|
# Process entry as normal
|
||||||
return super().process_library_entry(entry, added_time)
|
return super().process_library_entry(entry)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
from time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
@@ -56,12 +55,10 @@ class ItchSourceIterable(SourceIterable):
|
|||||||
connection = connect(db_path)
|
connection = connect(db_path)
|
||||||
cursor = connection.execute(db_request)
|
cursor = connection.execute(db_request)
|
||||||
|
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
# Create games from the db results
|
# Create games from the db results
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
values = {
|
values = {
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"name": row[1],
|
"name": row[1],
|
||||||
"game_id": self.source.game_id_format.format(game_id=row[0]),
|
"game_id": self.source.game_id_format.format(game_id=row[0]),
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
@@ -36,9 +35,7 @@ from src.importer.sources.source import (
|
|||||||
class LegendarySourceIterable(SourceIterable):
|
class LegendarySourceIterable(SourceIterable):
|
||||||
source: "LegendarySource"
|
source: "LegendarySource"
|
||||||
|
|
||||||
def game_from_library_entry(
|
def game_from_library_entry(self, entry: dict) -> SourceIterationResult:
|
||||||
self, entry: dict, added_time: int
|
|
||||||
) -> SourceIterationResult:
|
|
||||||
# Skip non-games
|
# Skip non-games
|
||||||
if entry["is_dlc"]:
|
if entry["is_dlc"]:
|
||||||
return None
|
return None
|
||||||
@@ -46,7 +43,7 @@ class LegendarySourceIterable(SourceIterable):
|
|||||||
# Build game
|
# Build game
|
||||||
app_name = entry["app_name"]
|
app_name = entry["app_name"]
|
||||||
values = {
|
values = {
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"name": entry["title"],
|
"name": entry["title"],
|
||||||
"game_id": self.source.game_id_format.format(game_id=app_name),
|
"game_id": self.source.game_id_format.format(game_id=app_name),
|
||||||
@@ -78,12 +75,10 @@ class LegendarySourceIterable(SourceIterable):
|
|||||||
logging.warning("Couldn't open Legendary file: %s", str(file))
|
logging.warning("Couldn't open Legendary file: %s", str(file))
|
||||||
return
|
return
|
||||||
|
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
# Generate games from library
|
# Generate games from library
|
||||||
for entry in library.values():
|
for entry in library.values():
|
||||||
try:
|
try:
|
||||||
result = self.game_from_library_entry(entry, added_time)
|
result = self.game_from_library_entry(entry)
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
# Skip invalid games
|
# Skip invalid games
|
||||||
logging.warning(
|
logging.warning(
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
from time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
@@ -56,13 +55,11 @@ class LutrisSourceIterable(SourceIterable):
|
|||||||
connection = connect(db_path)
|
connection = connect(db_path)
|
||||||
cursor = connection.execute(request, params)
|
cursor = connection.execute(request, params)
|
||||||
|
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
# Create games from the DB results
|
# Create games from the DB results
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
# Create game
|
# Create game
|
||||||
values = {
|
values = {
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"hidden": row[4],
|
"hidden": row[4],
|
||||||
"name": row[1],
|
"name": row[1],
|
||||||
"source": f"{self.source.source_id}_{row[3]}",
|
"source": f"{self.source.source_id}_{row[3]}",
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ from hashlib import md5
|
|||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shlex import quote as shell_quote
|
from shlex import quote as shell_quote
|
||||||
from time import time
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
from urllib.parse import quote as url_quote
|
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
from src.errors.friendly_error import FriendlyError
|
from src.errors.friendly_error import FriendlyError
|
||||||
@@ -54,7 +52,6 @@ class RetroarchSourceIterable(SourceIterable):
|
|||||||
raise KeyError(f"Key not found in RetroArch config: {key}")
|
raise KeyError(f"Key not found in RetroArch config: {key}")
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
added_time = int(time())
|
|
||||||
bad_playlists = set()
|
bad_playlists = set()
|
||||||
|
|
||||||
config_file = self.source.locations.config["retroarch.cfg"]
|
config_file = self.source.locations.config["retroarch.cfg"]
|
||||||
@@ -102,7 +99,7 @@ class RetroarchSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
values = {
|
values = {
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"name": item["label"],
|
"name": item["label"],
|
||||||
"game_id": self.source.game_id_format.format(game_id=game_id),
|
"game_id": self.source.game_id_format.format(game_id=game_id),
|
||||||
"executable": self.source.make_executable(
|
"executable": self.source.make_executable(
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import time
|
|
||||||
from typing import Iterable, NamedTuple
|
from typing import Iterable, NamedTuple
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
@@ -64,8 +63,6 @@ class SteamSourceIterable(SourceIterable):
|
|||||||
appid_cache = set()
|
appid_cache = set()
|
||||||
manifests = self.get_manifests()
|
manifests = self.get_manifests()
|
||||||
|
|
||||||
added_time = int(time())
|
|
||||||
|
|
||||||
for manifest in manifests:
|
for manifest in manifests:
|
||||||
# Get metadata from manifest
|
# Get metadata from manifest
|
||||||
steam = SteamFileHelper()
|
steam = SteamFileHelper()
|
||||||
@@ -90,7 +87,7 @@ class SteamSourceIterable(SourceIterable):
|
|||||||
|
|
||||||
# Build game from local data
|
# Build game from local data
|
||||||
values = {
|
values = {
|
||||||
"added": added_time,
|
"added": shared.import_time,
|
||||||
"name": local_data["name"],
|
"name": local_data["name"],
|
||||||
"source": self.source.source_id,
|
"source": self.source.source_id,
|
||||||
"game_id": self.source.game_id_format.format(game_id=appid),
|
"game_id": self.source.game_id_format.format(game_id=appid),
|
||||||
|
|||||||
@@ -52,5 +52,6 @@ image_size = (200 * scale_factor, 300 * scale_factor)
|
|||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
win = None
|
win = None
|
||||||
importer = None
|
importer = None
|
||||||
|
import_time = None
|
||||||
store = None
|
store = None
|
||||||
log_files = None
|
log_files = None
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
).lower()
|
).lower()
|
||||||
|
|
||||||
if var != "name" and get_value(0) == get_value(1):
|
if var != "name" and get_value(0) == get_value(1):
|
||||||
var, order = "name", True
|
var, order = "name", False
|
||||||
|
|
||||||
return ((get_value(0) > get_value(1)) ^ order) * 2 - 1
|
return ((get_value(0) > get_value(1)) ^ order) * 2 - 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user