Example #1
0
def add_or_update(**params):
    """Add a game to the PGA or update an existing one

    If an 'id' is provided in the parameters then it
    will try to match it, otherwise it will try matching
    by slug, creating one when possible.
    """
    slug = params.get("slug")
    if "id" in params and params["id"] is None:
        params.pop("id")
    game = None
    if params.get("id"):
        game = get_game_by_field(params["id"], "id")
    if not game:
        if not slug:
            slug = slugify(params["name"])
        game = get_game_by_field(slug, "slug")
    if game and (
            game["runner"] == params.get("runner")
            or not all([params.get("runner"), game["runner"]])
    ):
        sql.db_update(PGA_DB, "games", params, ("id", game["id"]))
        return game["id"]
    if game:
        logger.warning("Game found but not updated: %s", game)
    if params.get("id"):
        logger.warning("Removing id %s from parameters", params["id"])
        params.pop("id")
    return add_game(**params)
Example #2
0
File: pga.py Project: TRPB/lutris
def add_or_update(**params):
    """Add a game to the PGA or update an existing one

    If an 'id' is provided in the parameters then it
    will try to match it, otherwise it will try matching
    by slug, creating one when possible.
    """
    name = params.get("name")
    slug = params.get("slug")
    if "id" in params and params["id"] is None:
        params.pop("id")
    game_id = params.get("id")
    assert any([slug, name, game_id])
    game = None
    if game_id:
        game = get_game_by_field(params["id"], "id")
    if not game:
        if not slug:
            slug = slugify(name)
        game = get_game_by_field(slug, "slug")
    if game and (
            game["runner"] == params.get("runner")
            or not all([params.get("runner"), game["runner"]])
    ):
        sql.db_update(PGA_DB, "games", params, ("id", game["id"]))
        return game["id"]
    return add_game(**params)
Example #3
0
def fix_playtime(game):
    """Fix a temporary glitch that happened with the playtime implementation"""
    broken_playtime = game["playtime"]
    if not broken_playtime.endswith(" hrs"):
        return
    playtime = broken_playtime.split()[0]
    logger.warning("Fixing playtime %s => %s for %s", broken_playtime, playtime, game["name"])
    sql.db_update(PGA_DB, "games", {"playtime": playtime}, ("id", game["id"]))
Example #4
0
File: pga.py Project: TRPB/lutris
def unfuck_playtime(game):
    """Fix a temporary glitch that happened with the playtime implementation"""
    broken_playtime = game["playtime"]
    if not broken_playtime.endswith(" hrs"):
        logger.error("I don't know how to fix this playtime: %s", broken_playtime)
        return
    logger.warning("OMG, %s what have you done?! (%s)", game["name"], broken_playtime)
    playtime = broken_playtime.split()[0]
    sql.db_update(PGA_DB, "games", {"playtime": playtime}, ("id", game["id"]))
Example #5
0
def set_config_paths():
    for game in get_games():
        if game.get('configpath'):
            continue
        game_config_path = os.path.join(settings.CONFIG_DIR,
                                        "games/%s.yml" % game['slug'])
        if os.path.exists(game_config_path):
            logger.debug('Setting configpath to %s', game['slug'])
            sql.db_update(PGA_DB, 'games', {'configpath': game['slug']},
                          ('id', game['id']))
Example #6
0
def syncdb():
    """Update the database to the current version, making necessary changes
    for backwards compatibility,"""
    migrated = migrate_games()
    if 'installed' in migrated:
        set_installed_games()
    migrate_sources()

    # Rename runners
    sql.db_update(PGA_DB, 'games', {'runner': 'mame'}, ('runner', 'sdlmame'))
    sql.db_update(PGA_DB, 'games', {'runner': 'mess'}, ('runner', 'sdlmess'))
Example #7
0
def syncdb():
    """Update the database to the current version, making necessary changes
    for backwards compatibility,"""
    migrated = migrate_games()
    if 'installed' in migrated:
        set_installed_games()
    migrate_sources()

    # Rename runners
    sql.db_update(PGA_DB, 'games', {'runner': 'mame'}, ('runner', 'sdlmame'))
    sql.db_update(PGA_DB, 'games', {'runner': 'mess'}, ('runner', 'sdlmess'))
Example #8
0
def fix_playtime(game):
    """Fix a temporary glitch that happened with the playtime implementation"""
    broken_playtime = game["playtime"]
    if not broken_playtime.endswith(" hrs"):
        return
    playtime = broken_playtime.split()[0]
    logger.warning("Fixing playtime %s => %s for %s",
                   broken_playtime,
                   playtime,
                   game["name"])
    sql.db_update(PGA_DB, "games", {"playtime": playtime}, ("id", game["id"]))
Example #9
0
def add_or_update(name, runner, slug=None, **kwargs):
    if not slug:
        slug = slugify(name)
    game = get_game_by_slug(slug)
    kwargs['name'] = name
    kwargs['runner'] = runner
    kwargs['slug'] = slug
    if game:
        sql.db_update(PGA_DB, "games", kwargs, ('slug', slug))
    else:
        add_game(**kwargs)
Example #10
0
def add_or_update(name, runner, slug=None, **kwargs):
    if not slug:
        slug = slugify(name)
    game = get_game_by_slug(slug)
    kwargs['name'] = name
    kwargs['runner'] = runner
    kwargs['slug'] = slug
    if game:
        game_id = game['id']
        sql.db_update(PGA_DB, "games", kwargs, ('id', game_id))
    else:
        add_game(**kwargs)
Example #11
0
def add_or_update(**params):
    """Add a game to the PGA or update an existing one

    If an 'id' is provided in the parameters then it
    will try to match it, otherwise it will try matching
    by slug, creating one when possible.
    """
    game_id = get_matching_game(params)
    if game_id:
        params["id"] = game_id
        sql.db_update(PGA_DB, "games", params, ("id", game_id))
        return game_id
    return add_game(**params)
Example #12
0
def set_config_paths():
    for game in get_games():
        if game.get('configpath'):
            continue
        game_config_path = os.path.join(settings.CONFIG_DIR,
                                        "games/%s.yml" % game['slug'])
        if os.path.exists(game_config_path):
            logger.debug('Setting configpath to %s', game['slug'])
            sql.db_update(
                PGA_DB,
                'games',
                {'configpath': game['slug']},
                ('id', game['id'])
            )
Example #13
0
def add_or_update(**params):
    slug = params.get('slug')
    name = params.get('name')
    id = params.get('id')
    assert any([slug, name, id])
    if 'id' in params:
        game = get_game_by_field(params['id'], 'id')
    else:
        if not slug:
            slug = slugify(name)
        game = get_game_by_field(slug, 'slug')
    if game and game['runner'] == params.get('runner'):
        game_id = game['id']
        sql.db_update(PGA_DB, "games", params, ('id', game_id))
        return game_id
    return add_game(**params)
Example #14
0
def add_or_update(**params):
    slug = params.get('slug')
    name = params.get('name')
    id = params.get('id')
    assert any([slug, name, id])
    if 'id' in params:
        game = get_game_by_field(params['id'], 'id')
    else:
        if not slug:
            slug = slugify(name)
        game = get_game_by_field(slug, 'slug')
    if game:
        game_id = game['id']
        sql.db_update(PGA_DB, "games", params, ('id', game_id))
        return game_id
    else:
        return add_game(**params)
Example #15
0
File: pga.py Project: dacp17/lutris
def add_or_update(name, runner, slug=None, **kwargs):
    """
    FIXME probably not the desired behavior since it disallows multiple games
    with the same slug
    """
    if not slug:
        slug = slugify(name)
    if 'id' in kwargs:
        game = get_game_by_field(kwargs['id'], 'id')
    else:
        game = get_game_by_field(slug, 'slug')
    kwargs['name'] = name
    kwargs['runner'] = runner
    kwargs['slug'] = slug
    if game:
        game_id = game['id']
        sql.db_update(PGA_DB, "games", kwargs, ('id', game_id))
        return game_id
    else:
        return add_game(**kwargs)
Example #16
0
def set_uninstalled(slug):
    sql.db_update(PGA_DB, 'games', {'installed': 0}, ('slug', slug))
Example #17
0
def set_installed_games():
    games = get_games()
    for game in games:
        if game['directory'] and os.path.exists(game['directory']):
            sql.db_update(PGA_DB, 'games',
                          {'installed': 1}, ('slug', game['slug']))
Example #18
0
def set_uninstalled(id):
    sql.db_update(PGA_DB, 'games', {'installed': 0, 'runner': ''}, ('id', id))
Example #19
0
def set_uninstalled(game_id):
    sql.db_update(PGA_DB, "games", {
        "installed": 0,
        "runner": ""
    }, ("id", game_id))
Example #20
0
def set_installed_games():
    games = get_games()
    for game in games:
        if game['directory'] and os.path.exists(game['directory']):
            sql.db_update(PGA_DB, 'games', {'installed': 1},
                          ('slug', game['slug']))
Example #21
0
def set_uninstalled(slug):
    sql.db_update(PGA_DB, 'games', {
        'installed': 0,
        'runner': ''
    }, ('slug', slug))