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)
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)
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"]))
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"]))
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']))
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'))
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)
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)
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)
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']) )
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)
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)
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)
def set_uninstalled(slug): sql.db_update(PGA_DB, 'games', {'installed': 0}, ('slug', slug))
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']))
def set_uninstalled(id): sql.db_update(PGA_DB, 'games', {'installed': 0, 'runner': ''}, ('id', id))
def set_uninstalled(game_id): sql.db_update(PGA_DB, "games", { "installed": 0, "runner": "" }, ("id", game_id))
def set_uninstalled(slug): sql.db_update(PGA_DB, 'games', { 'installed': 0, 'runner': '' }, ('slug', slug))