mirror of
https://github.com/lutris/lutris
synced 2024-09-15 22:09:55 +00:00
Better sync for ScummVM games (Fixes #546)
This commit is contained in:
parent
616da740f9
commit
99073dc606
|
@ -166,7 +166,7 @@ def get_games_where(**conditions):
|
|||
list: Rows matching the query
|
||||
|
||||
"""
|
||||
query = "select * from games where "
|
||||
query = "select * from games"
|
||||
condition_fields = []
|
||||
condition_values = []
|
||||
for field, value in conditions.items():
|
||||
|
@ -181,14 +181,22 @@ def get_games_where(**conditions):
|
|||
if extra_condition == 'in':
|
||||
if not hasattr(value, '__iter__'):
|
||||
raise ValueError("Value should be an iterable (%s given)" % value)
|
||||
condition_fields.append('{{}} in ({})'.format(
|
||||
', '.join('?' * len(value))
|
||||
))
|
||||
condition_values = list(chain(condition_values, value))
|
||||
if value:
|
||||
condition = "{}" + " in ({})".format(
|
||||
', '.join('?' * len(value))
|
||||
)
|
||||
condition_fields.append(condition)
|
||||
condition_values = list(chain(condition_values, value))
|
||||
else:
|
||||
condition_fields.append("{} = ?".format(field))
|
||||
condition_values.append(value)
|
||||
query += " AND ".join(condition_fields)
|
||||
condition = " AND ".join(condition_fields)
|
||||
if condition:
|
||||
query = " WHERE ".join((query, condition))
|
||||
else:
|
||||
# FIXME: Inspect and document why we should return an empty list when
|
||||
# no condition is present.
|
||||
return []
|
||||
return sql.db_query(PGA_DB, query, tuple(condition_values))
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ def mark_as_installed(scummvm_id, name, path):
|
|||
game_id = pga.add_or_update(
|
||||
name=name,
|
||||
runner='scummvm',
|
||||
installer_slug=INSTALLER_SLUG,
|
||||
slug=slug,
|
||||
installed=1,
|
||||
configpath=config_id,
|
||||
|
@ -36,6 +37,14 @@ def mark_as_installed(scummvm_id, name, path):
|
|||
return game_id
|
||||
|
||||
|
||||
def mark_as_uninstalled(game_info):
|
||||
logger.info("Uninstalling %s", game_info['name'])
|
||||
return pga.add_or_update(
|
||||
id=game_info['id'],
|
||||
installed=0
|
||||
)
|
||||
|
||||
|
||||
def get_scummvm_games():
|
||||
if not os.path.exists(SCUMMVM_CONFIG_FILE):
|
||||
logger.info("No ScummVM config found")
|
||||
|
@ -53,5 +62,18 @@ def get_scummvm_games():
|
|||
|
||||
|
||||
def sync_with_lutris():
|
||||
scummvm_games = {
|
||||
game['slug']: game
|
||||
for game in pga.get_games_where(runner='scummvm',
|
||||
installer_slug=INSTALLER_SLUG,
|
||||
installed=1)
|
||||
}
|
||||
seen = set()
|
||||
|
||||
for scummvm_id, name, path in get_scummvm_games():
|
||||
mark_as_installed(scummvm_id, name, path)
|
||||
slug = slugify(name)
|
||||
seen.add(slug)
|
||||
if slug not in scummvm_games.keys():
|
||||
mark_as_installed(scummvm_id, name, path)
|
||||
for slug in set(scummvm_games.keys()).difference(seen):
|
||||
mark_as_uninstalled(scummvm_games[slug])
|
||||
|
|
|
@ -69,21 +69,19 @@ def mark_as_installed(appid, runner_name, game_info):
|
|||
|
||||
|
||||
def mark_as_uninstalled(game_info):
|
||||
assert 'id' in game_info
|
||||
assert 'name' in game_info
|
||||
logger.info('Setting %s as uninstalled' % game_info['name'])
|
||||
game_id = pga.add_or_update(
|
||||
logger.info('Uninstalling %s' % game_info['name'])
|
||||
return pga.add_or_update(
|
||||
id=game_info['id'],
|
||||
runner='',
|
||||
installed=0
|
||||
)
|
||||
return game_id
|
||||
|
||||
|
||||
def sync_with_lutris():
|
||||
desktop_games_map = {
|
||||
desktop_games = {
|
||||
game['slug']: game
|
||||
for game in pga.get_games_where(runner='linux', installer_slug=INSTALLER_SLUG)
|
||||
for game in pga.get_games_where(runner='linux',
|
||||
installer_slug=INSTALLER_SLUG,
|
||||
installed=1)
|
||||
}
|
||||
seen = set()
|
||||
|
||||
|
@ -96,7 +94,7 @@ def sync_with_lutris():
|
|||
logger.info("Found desktop game \"{}\" (app: {}, slug: {})".format(name, appid, slug))
|
||||
seen.add(slug)
|
||||
|
||||
if slug not in desktop_games_map.keys():
|
||||
if slug not in desktop_games.keys():
|
||||
game_info = {
|
||||
'name': name,
|
||||
'slug': slug,
|
||||
|
@ -107,8 +105,8 @@ def sync_with_lutris():
|
|||
}
|
||||
mark_as_installed(appid, 'linux', game_info)
|
||||
|
||||
for slug in set(desktop_games_map.keys()).difference(seen):
|
||||
mark_as_uninstalled(desktop_games_map[slug])
|
||||
for slug in set(desktop_games.keys()).difference(seen):
|
||||
mark_as_uninstalled(desktop_games[slug])
|
||||
|
||||
|
||||
def iter_xdg_apps():
|
||||
|
|
Loading…
Reference in a new issue