mirror of
https://github.com/lutris/lutris
synced 2024-10-14 11:42:36 +00:00
Move parse_installer_url to api module
This commit is contained in:
parent
a59d8bd20c
commit
dd382a06ba
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue