diff --git a/lutris/api.py b/lutris/api.py index 219687762..2c5535d53 100644 --- a/lutris/api.py +++ b/lutris/api.py @@ -183,3 +183,39 @@ def search_games(query): game["installed_at"] = None game["playtime"] = None return api_games + + +def parse_installer_url(url): + """ + Parses `lutris:` urls, extracting any info necessary to install or run a game. + """ + action = None + try: + parsed_url = urllib.parse.urlparse(url, scheme="lutris") + except Exception: # pylint: disable=broad-except + logger.warning("Unable to parse url %s", url) + return False + if parsed_url.scheme != "lutris": + return False + url_path = parsed_url.path + if not url_path: + return False + # urlparse can't parse if the path only contain numbers + # workaround to remove the scheme manually: + if url_path.startswith("lutris:"): + url_path = url_path[7:] + + url_parts = url_path.split("/") + if len(url_parts) == 2: + action = url_parts[0] + game_slug = url_parts[1] + elif len(url_parts) == 1: + game_slug = url_parts[0] + else: + raise ValueError("Invalid lutris url %s" % url) + + revision = None + if parsed_url.query: + query = dict(urllib.parse.parse_qsl(parsed_url.query)) + revision = query.get("revision") + return {"game_slug": game_slug, "revision": revision, "action": action} diff --git a/lutris/gui/application.py b/lutris/gui/application.py index d3e39acfa..8ecae6b4b 100644 --- a/lutris/gui/application.py +++ b/lutris/gui/application.py @@ -43,7 +43,7 @@ from lutris.util import datapath from lutris.util import log from lutris.util.jobs import AsyncCall from lutris.util.log import logger -from lutris.util.resources import parse_installer_url +from lutris.api import parse_installer_url from lutris.startup import run_all_checks from lutris.util.wine.dxvk import init_dxvk_versions diff --git a/lutris/gui/config/common.py b/lutris/gui/config/common.py index 338157e09..e8a36db0a 100644 --- a/lutris/gui/config/common.py +++ b/lutris/gui/config/common.py @@ -477,7 +477,7 @@ class GameDialogCommon: self._set_image(image_type) if image_type == "icon": - resources.udpate_desktop_icons() + resources.update_desktop_icons() dialog.destroy() diff --git a/lutris/runners/residualvm.py b/lutris/runners/residualvm.py index 6e9fff03a..89020da71 100644 --- a/lutris/runners/residualvm.py +++ b/lutris/runners/residualvm.py @@ -109,7 +109,7 @@ class residualvm(Runner): dir_limit = None if dir_limit is not None: game_dir = game[0:dir_limit] - game_name = game[dir_limit + 1 : len(game)].strip() + game_name = game[dir_limit + 1: len(game)].strip() game_array.append([game_dir, game_name]) # The actual list is below a separator if game.startswith("-----"): diff --git a/lutris/util/resources.py b/lutris/util/resources.py index 00c7f995a..56df8ee61 100644 --- a/lutris/util/resources.py +++ b/lutris/util/resources.py @@ -1,7 +1,6 @@ """Utility module to handle media resources""" import os import concurrent.futures -from urllib.parse import urlparse, parse_qsl from gi.repository import GLib from lutris import settings @@ -20,7 +19,7 @@ def get_icon_path(game_slug, icon_type=ICON): return os.path.join(settings.BANNER_PATH, "%s.jpg" % game_slug) if icon_type == ICON: return os.path.join(settings.ICON_PATH, "lutris_%s.png" % game_slug) - return None + raise ValueError("Invalid icon type %s" % icon_type) def get_banner_path(game_slug): @@ -55,10 +54,10 @@ def fetch_icons(lutris_media, callback): GLib.idle_add(callback, slug, priority=GLib.PRIORITY_LOW) if bool(available_icons): - udpate_desktop_icons() + update_desktop_icons() -def udpate_desktop_icons(): +def update_desktop_icons(): """Update Icon for GTK+ desktop manager""" gtk_update_icon_cache = system.find_executable("gtk-update-icon-cache") if gtk_update_icon_cache: @@ -80,39 +79,3 @@ def download_media(url, dest, overwrite=False): request = Request(url).get() request.write_to_file(dest) return dest - - -def parse_installer_url(url): - """ - Parses `lutris:` urls, extracting any info necessary to install or run a game. - """ - action = None - try: - parsed_url = urlparse(url, scheme="lutris") - except Exception: # pylint: disable=broad-except - logger.warning("Unable to parse url %s", url) - return False - if parsed_url.scheme != "lutris": - return False - url_path = parsed_url.path - if not url_path: - return False - # urlparse can't parse if the path only contain numbers - # workaround to remove the scheme manually: - if url_path.startswith("lutris:"): - url_path = url_path[7:] - - url_parts = url_path.split("/") - if len(url_parts) == 2: - action = url_parts[0] - game_slug = url_parts[1] - elif len(url_parts) == 1: - game_slug = url_parts[0] - else: - raise ValueError("Invalid lutris url %s" % url) - - revision = None - if parsed_url.query: - query = dict(parse_qsl(parsed_url.query)) - revision = query.get("revision") - return {"game_slug": game_slug, "revision": revision, "action": action} diff --git a/tests/test_resources.py b/tests/test_resources.py index cbcce122a..457f69ad5 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1,6 +1,6 @@ from unittest import TestCase -from lutris.util.resources import parse_installer_url +from lutris.api import parse_installer_url class TestInstallerUrls(TestCase):