Rename id to service_id as id is a reserved keyword

This commit is contained in:
Mathieu Comandon 2023-09-06 21:51:55 -07:00
parent 5eb0d11dfa
commit e06508566e
13 changed files with 65 additions and 63 deletions

View file

@ -12,11 +12,11 @@ from lutris.util.downloader import Downloader
from lutris.util.extract import extract_archive
from lutris.util.linux import LINUX_SYSTEM
from lutris.util.log import logger
from lutris.util.wine.dxvk import DXVKManager
from lutris.util.wine.vkd3d import VKD3DManager
from lutris.util.wine.d3d_extras import D3DExtrasManager
from lutris.util.wine.dgvoodoo2 import dgvoodoo2Manager
from lutris.util.wine.dxvk import DXVKManager
from lutris.util.wine.dxvk_nvapi import DXVKNVAPIManager
from lutris.util.wine.vkd3d import VKD3DManager
RUNTIME_DISABLED = os.environ.get("LUTRIS_RUNTIME", "").lower() in ("0", "off")
DEFAULT_RUNTIME = "Ubuntu-18.04"
@ -29,6 +29,7 @@ DLL_MANAGERS = {
"dxvk_nvapi": DXVKNVAPIManager,
}
class Runtime:
"""Class for manipulating runtime folders"""

View file

@ -74,7 +74,7 @@ class LutrisCoverartMedium(LutrisCoverart):
class BaseService(GObject.Object):
"""Base class for local services"""
type = NotImplemented # String identifier for this kind of service
id: str # Identifier of a single account created at this service
service_id: str # Identifier of a single account created at this service
_matcher = None
has_extras = False
name = NotImplemented
@ -96,15 +96,15 @@ class BaseService(GObject.Object):
"service-logout": (GObject.SIGNAL_RUN_FIRST, None, ()),
}
def __init__(self, id):
def __init__(self, service_id=None):
super().__init__()
self.id = id
self.service_id = service_id
@property
def matcher(self):
if self._matcher:
return self._matcher
return self.id
return self.service_id
def run(self):
"""Launch the game client"""
@ -176,8 +176,8 @@ class BaseService(GObject.Object):
service_media.render()
def wipe_game_cache(self):
logger.debug("Deleting games from service-games for %s", self.id)
sql.db_delete(PGA_DB, "service_games", "service", self.id)
logger.debug("Deleting games from service-games for %s", self.service_id)
sql.db_delete(PGA_DB, "service_games", "service", self.service_id)
def get_update_installers(self, db_game):
return []
@ -194,37 +194,38 @@ class BaseService(GObject.Object):
PGA_DB,
"service_games",
{"lutris_slug": api_game["slug"]},
conditions={"appid": service_game["appid"], "service": self.id}
conditions={"appid": service_game["appid"], "service": self.service_id}
)
unmatched_lutris_games = get_games(
searches={"installer_slug": self.matcher},
filters={"slug": api_game["slug"]},
excludes={"service": self.id}
excludes={"service": self.service_id}
)
for game in unmatched_lutris_games:
logger.debug("Updating unmatched game %s", game)
sql.db_update(
PGA_DB,
"games",
{"service": self.id, "service_id": service_game["appid"]},
{"service": self.service_id, "service_id": service_game["appid"]},
conditions={"id": game["id"]}
)
def match_games(self):
"""Matching of service games to lutris games"""
service_games = {
str(game["appid"]): game for game in ServiceGameCollection.get_for_service(self.id)
str(game["appid"]): game for game in ServiceGameCollection.get_for_service(self.service_id)
}
lutris_games = api.get_api_games(list(service_games.keys()), service=self.id)
lutris_games = api.get_api_games(list(service_games.keys()), service=self.service_id)
for lutris_game in lutris_games:
for provider_game in lutris_game["provider_games"]:
if provider_game["service"] != self.id:
if provider_game["service"] != self.service_id:
continue
self.match_game(service_games.get(provider_game["slug"]), lutris_game)
unmatched_service_games = get_games(searches={"installer_slug": self.matcher}, excludes={"service": self.id})
unmatched_service_games = get_games(searches={"installer_slug": self.matcher}, excludes={
"service": self.service_id})
for lutris_game in api.get_api_games(game_slugs=[g["slug"] for g in unmatched_service_games]):
for provider_game in lutris_game["provider_games"]:
if provider_game["service"] != self.id:
if provider_game["service"] != self.service_id:
continue
self.match_game(service_games.get(provider_game["slug"]), lutris_game)
@ -234,15 +235,15 @@ class BaseService(GObject.Object):
logger.debug("Matching %s with existing install: %s", appid, _game)
game = Game(_game["id"])
game.appid = appid
game.service = self.id
game.service = self.service_id
game.save()
service_game = ServiceGameCollection.get_game(self.id, appid)
service_game = ServiceGameCollection.get_game(self.service_id, appid)
sql.db_update(PGA_DB, "service_games", {"lutris_slug": game.slug}, {"id": service_game["id"]})
return game
def get_installers_from_api(self, appid):
"""Query the lutris API for an appid and get existing installers for the service"""
lutris_games = api.get_api_games([appid], service=self.id)
lutris_games = api.get_api_games([appid], service=self.service_id)
service_installers = []
if lutris_games:
lutris_game = lutris_games[0]
@ -265,7 +266,7 @@ class BaseService(GObject.Object):
they return None.
"""
appid = db_game["appid"]
logger.debug("Installing %s from service %s", appid, self.id)
logger.debug("Installing %s from service %s", appid, self.service_id)
# Local services (aka game libraries that don't require any type of online interaction) can
# be added without going through an install dialog.
@ -311,7 +312,7 @@ class BaseService(GObject.Object):
installed=1,
installer_slug=installer["slug"],
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=db_game["appid"],
)
return game_id
@ -371,7 +372,7 @@ class OnlineService(BaseService):
def wipe_game_cache(self):
"""Wipe the game cache, allowing it to be reloaded"""
if self.cache_path:
logger.debug("Deleting %s cache %s", self.id, self.cache_path)
logger.debug("Deleting %s cache %s", self.service_id, self.cache_path)
if os.path.isdir(self.cache_path):
shutil.rmtree(self.cache_path)
elif system.path_exists(self.cache_path):
@ -386,7 +387,7 @@ class OnlineService(BaseService):
os.remove(auth_file)
except OSError:
logger.warning("Unable to remove %s", auth_file)
logger.debug("logged out from %s", self.id)
logger.debug("logged out from %s", self.service_id)
self.emit("service-logout")
def load_cookies(self):

View file

@ -127,7 +127,7 @@ class BattleNetService(BaseService):
if not service_game:
logger.error("Aborting install, %s is not present in the game library.", app_id)
return
lutris_game_id = service_game["slug"] + "-" + self.id
lutris_game_id = service_game["slug"] + "-" + self.service_id
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
if existing_game:
return
@ -142,7 +142,7 @@ class BattleNetService(BaseService):
installed=1,
installer_slug=lutris_game_id,
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=app_id,
platform="Windows"
)
@ -156,7 +156,7 @@ class BattleNetService(BaseService):
return {
"name": db_game["name"],
"version": self.name,
"slug": db_game["slug"] + "-" + self.id,
"slug": db_game["slug"] + "-" + self.service_id,
"game_slug": db_game["slug"],
"runner": self.runner,
"appid": db_game["appid"],

View file

@ -159,8 +159,8 @@ class EAAppService(OnlineService):
) % origin_redirect_uri
login_user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0 QtWebEngine/5.8.0"
def __init__(self, id):
super().__init__(id=id)
def __init__(self, service_id):
super().__init__(service_id=service_id)
self.session = requests.session()
self.session.mount("https://", LegacyRenegotiationHTTPAdapter())
@ -327,7 +327,7 @@ class EAAppService(OnlineService):
if not service_game:
logger.error("Aborting install, %s is not present in the game library.", offer_id)
return
lutris_game_id = slugify(service_game["name"]) + "-" + self.id
lutris_game_id = slugify(service_game["name"]) + "-" + self.service_id
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
if existing_game:
return
@ -342,7 +342,7 @@ class EAAppService(OnlineService):
installed=1,
installer_slug=lutris_game_id,
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=offer_id,
)
return game_id
@ -355,7 +355,7 @@ class EAAppService(OnlineService):
return {
"name": db_game["name"],
"version": self.name,
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"game_slug": slugify(db_game["name"]),
"runner": self.runner,
"appid": db_game["appid"],

View file

@ -170,8 +170,8 @@ class EpicGamesStoreService(OnlineService):
'Chrome/84.0.4147.38 Safari/537.36'
)
def __init__(self, id):
super().__init__(id)
def __init__(self, service_id):
super().__init__(service_id)
self.session = requests.session()
self.session.headers['User-Agent'] = self.user_agent
if os.path.exists(self.token_path):
@ -325,7 +325,7 @@ class EpicGamesStoreService(OnlineService):
if not service_game:
logger.error("Aborting install, %s is not present in the game library.", app_name)
return
lutris_game_id = slugify(service_game["name"]) + "-" + self.id
lutris_game_id = slugify(service_game["name"]) + "-" + self.service_id
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
if existing_game:
return
@ -340,7 +340,7 @@ class EpicGamesStoreService(OnlineService):
installed=1,
installer_slug=lutris_game_id,
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=app_name,
)
return game_id
@ -370,7 +370,7 @@ class EpicGamesStoreService(OnlineService):
return {
"name": db_game["name"],
"version": self.name,
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"game_slug": slugify(db_game["name"]),
"runner": self.runner,
"appid": db_game["appid"],

View file

@ -77,7 +77,7 @@ class FlathubService(BaseService):
def wipe_game_cache(self):
"""Wipe the game cache, allowing it to be reloaded"""
if system.path_exists(self.cache_path):
logger.debug("Deleting %s cache %s", self.id, self.cache_path)
logger.debug("Deleting %s cache %s", self.service_id, self.cache_path)
os.remove(self.cache_path)
super().wipe_game_cache()
@ -104,7 +104,7 @@ class FlathubService(BaseService):
def install(self, db_game):
"""Install a Flathub game"""
app_id = db_game["appid"]
logger.debug("Installing %s from service %s", app_id, self.id)
logger.debug("Installing %s from service %s", app_id, self.service_id)
# Check if Flathub repo is active on the system
if not self.is_flathub_remote_active():
logger.error("Flathub is not configured on the system. Visit https://flatpak.org/setup/ for instructions.")
@ -163,7 +163,7 @@ class FlathubService(BaseService):
return {
"appid": db_game["appid"],
"game_slug": slugify(db_game["name"]),
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"name": db_game["name"],
"version": "Flathub",
"runner": self.runner,

View file

@ -89,8 +89,8 @@ class GOGService(OnlineService):
token_path = os.path.join(settings.CACHE_DIR, ".gog.token")
cache_path = os.path.join(settings.CACHE_DIR, "gog-library.json")
def __init__(self, id):
super().__init__(id)
def __init__(self, service_id):
super().__init__(service_id)
gog_locales = {
"en": "en-US",

View file

@ -370,7 +370,7 @@ class ItchIoService(OnlineService):
if stamp:
dbg = games_db.get_games_where(
installed_at__lessthan=stamp,
service=self.id,
service=self.service_id,
service_id=db_game["service_id"]
)
return len(dbg)
@ -494,7 +494,7 @@ class ItchIoService(OnlineService):
link = file.url
data = {
"service": self.id,
"service": self.service_id,
"appid": installer.service_appid,
"slug": installer.game_slug,
"runner": installer.runner,

View file

@ -60,7 +60,7 @@ class LutrisService(OnlineService):
def match_games(self):
"""Matching lutris games is much simpler... No API call needed."""
service_games = {
str(game["appid"]): game for game in ServiceGameCollection.get_for_service(self.id)
str(game["appid"]): game for game in ServiceGameCollection.get_for_service(self.service_id)
}
for lutris_game in get_games():
self.match_game(service_games.get(lutris_game["slug"]), lutris_game)

View file

@ -149,8 +149,8 @@ class OriginService(OnlineService):
) % redirect_uri
login_user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0 QtWebEngine/5.8.0"
def __init__(self, id):
super().__init__(id)
def __init__(self, service_id):
super().__init__(service_id)
self.session = requests.session()
self.session.mount("https://", LegacyRenegotiationHTTPAdapter())
@ -318,7 +318,7 @@ class OriginService(OnlineService):
if not service_game:
logger.error("Aborting install, %s is not present in the game library.", offer_id)
return
lutris_game_id = slugify(service_game["name"]) + "-" + self.id
lutris_game_id = slugify(service_game["name"]) + "-" + self.service_id
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
if existing_game:
return
@ -333,7 +333,7 @@ class OriginService(OnlineService):
installed=1,
installer_slug=lutris_game_id,
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=offer_id,
)
return game_id
@ -346,7 +346,7 @@ class OriginService(OnlineService):
return {
"name": db_game["name"],
"version": self.name,
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"game_slug": slugify(db_game["name"]),
"runner": self.runner,
"appid": db_game["appid"],

View file

@ -123,10 +123,10 @@ class SteamService(BaseService):
appid = manifest.steamid
if appid in self.excluded_appids:
return
service_game = ServiceGameCollection.get_game(self.id, appid)
service_game = ServiceGameCollection.get_game(self.service_id, appid)
if not service_game:
return
lutris_game_id = "%s-%s" % (self.id, appid)
lutris_game_id = "%s-%s" % (self.service_id, appid)
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
if existing_game:
return
@ -141,7 +141,7 @@ class SteamService(BaseService):
installer_slug=lutris_game_id,
configpath=configpath,
platform="Linux",
service=self.id,
service=self.service_id,
service_id=appid,
)
return game_id
@ -204,7 +204,7 @@ class SteamService(BaseService):
return {
"name": db_game["name"],
"version": self.name,
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"game_slug": slugify(db_game["name"]),
"runner": self.runner,
"appid": db_game["appid"],
@ -215,7 +215,7 @@ class SteamService(BaseService):
def install(self, db_game):
appid = db_game["appid"]
db_games = get_games(filters={"service_id": appid, "installed": "1", "service": self.id})
db_games = get_games(filters={"service_id": appid, "installed": "1", "service": self.service_id})
existing_game = self.match_existing_game(db_games, appid)
if existing_game:
logger.debug("Found steam game: %s", existing_game)

View file

@ -32,7 +32,7 @@ class SteamWindowsService(SteamService):
return {
"name": db_game["name"],
"version": self.name,
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"game_slug": slugify(db_game["name"]),
"runner": self.runner,
"appid": db_game["appid"],
@ -61,7 +61,7 @@ class SteamWindowsService(SteamService):
else:
installers = [self.generate_installer(db_game, steam_game)]
appid = db_game["appid"]
db_games = get_games(filters={"service_id": appid, "installed": "1", "service": self.id})
db_games = get_games(filters={"service_id": appid, "installed": "1", "service": self.service_id})
existing_game = self.match_existing_game(db_games, appid)
if existing_game:
logger.debug("Found steam game: %s", existing_game)

View file

@ -105,8 +105,8 @@ class UbisoftConnectService(OnlineService):
}
default_format = "cover"
def __init__(self, id):
super().__init__(id)
def __init__(self, service_id):
super().__init__(service_id)
self.client = UbisoftConnectClient(self)
def auth_lost(self):
@ -180,7 +180,7 @@ class UbisoftConnectService(OnlineService):
def install_from_ubisoft(self, ubisoft_connect, game):
app_name = game["name"]
lutris_game_id = slugify(game["name"]) + "-" + self.id
lutris_game_id = slugify(game["name"]) + "-" + self.service_id
existing_game = get_game_by_field(lutris_game_id, "installer_slug")
if existing_game and existing_game["installed"] == 1:
logger.debug("Ubisoft Connect game %s is already installed", app_name)
@ -201,7 +201,7 @@ class UbisoftConnectService(OnlineService):
installed=1,
installer_slug=lutris_game_id,
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=game["appid"],
)
return existing_game["id"]
@ -213,7 +213,7 @@ class UbisoftConnectService(OnlineService):
installed=1,
installer_slug=lutris_game_id,
configpath=configpath,
service=self.id,
service=self.service_id,
service_id=game["appid"],
)
return game_id
@ -225,7 +225,7 @@ class UbisoftConnectService(OnlineService):
return
prefix_path = ubisoft_connect["directory"].split("drive_c")[0]
prefix = WinePrefixManager(prefix_path)
for game in ServiceGameCollection.get_for_service(self.id):
for game in ServiceGameCollection.get_for_service(self.service_id):
details = json.loads(game["details"])
install_path = get_ubisoft_registry(prefix, details.get("registryPath"))
exe = get_ubisoft_registry(prefix, details.get("exe"))
@ -243,7 +243,7 @@ class UbisoftConnectService(OnlineService):
return {
"name": db_game["name"],
"version": self.name,
"slug": slugify(db_game["name"]) + "-" + self.id,
"slug": slugify(db_game["name"]) + "-" + self.service_id,
"game_slug": slugify(db_game["name"]),
"runner": self.runner,
"appid": db_game["appid"],