Beispiel #1
0
 def test_game_with_same_slug_is_updated(self):
     pga.add_game(name="some game", runner="linux")
     game = pga.get_game_by_field("some-game", "slug")
     self.assertFalse(game['directory'])
     pga.add_or_update(name="some game", runner='linux', directory="/foo")
     game = pga.get_game_by_field("some-game", "slug")
     self.assertEqual(game['directory'], '/foo')
Beispiel #2
0
 def save(self):
     self.config.save()
     pga.add_or_update(name=self.name,
                       runner=self.runner_name,
                       slug=self.slug,
                       directory=self.directory,
                       installed=self.is_installed)
Beispiel #3
0
    def sync_steam_local(self):
        """Sync Steam games in library with Steam and Wine Steam"""
        steamrunner = steam()
        winesteamrunner = winesteam()
        installed = set()
        uninstalled = set()

        # Get installed steamapps
        installed_steamapps = self.get_installed_steamapps(steamrunner)
        installed_winesteamapps = self.get_installed_steamapps(winesteamrunner)

        for game_info in self.library:
            slug = game_info['slug']
            runner = game_info['runner']
            steamid = game_info['steamid']
            installed_in_steam = steamid in installed_steamapps
            installed_in_winesteam = steamid in installed_winesteamapps

            # Set installed
            if not game_info['installed']:
                if not installed_in_steam:  # (Linux Steam only)
                    continue
                logger.debug("Setting %s as installed" % game_info['name'])
                config_id = (game_info['configpath']
                             or config.make_game_config_id(slug))
                game_id = pga.add_or_update(
                    name=game_info['name'],
                    runner='steam',
                    slug=slug,
                    installed=1,
                    configpath=config_id,
                )
                game_config = config.LutrisConfig(
                    runner_slug='steam',
                    game_config_id=config_id,
                )
                game_config.raw_game_config.update({'appid': str(steamid)})
                game_config.save()
                installed.add(game_id)

            # Set uninstalled
            elif not (installed_in_steam or installed_in_winesteam):
                if runner not in ['steam', 'winesteam']:
                    continue
                if runner == 'steam' and not steamrunner.is_installed():
                    continue
                if runner == 'winesteam' and not winesteamrunner.is_installed():
                    continue
                logger.debug("Setting %(name)s (%(steamid)s) as uninstalled", game_info)

                game_id = pga.add_or_update(
                    name=game_info['name'],
                    runner='',
                    slug=game_info['slug'],
                    installed=0
                )
                uninstalled.add(game_id)
        return (installed, uninstalled)
Beispiel #4
0
 def save(self):
     self.config.save()
     pga.add_or_update(
         name=self.name,
         runner=self.runner_name,
         slug=self.slug,
         directory=self.directory,
         installed=self.is_installed
     )
Beispiel #5
0
    def sync_game_details(remote_library, caller):
        """Update local game details,

        :param caller: The LutrisWindow object
        :return: The slugs of the updated games.
        :rtype: set
        """
        if not remote_library:
            return set()
        updated = set()

        # Get remote games (TODO: use this when switched API to DRF)
        # remote_games = get_games(sorted(local_slugs))
        # if not remote_games:
        #     return set()

        for game in remote_library:
            slug = game['slug']
            sync = False
            sync_icons = True
            local_game = pga.get_game_by_slug(slug)
            if not local_game:
                continue

            # Sync updated
            if game['updated'] > local_game['updated']:
                sync = True
            # Sync new DB fields
            else:
                for key, value in local_game.iteritems():
                    if value or key not in game:
                        continue
                    if game[key]:
                        sync = True
                        sync_icons = False
            if not sync:
                continue

            logger.debug("Syncing details for %s" % slug)
            pga.add_or_update(
                local_game['name'], local_game['runner'], slug,
                year=game['year'], updated=game['updated'],
                steamid=game['steamid']
            )
            caller.view.update_row(game)

            # Sync icons (TODO: Only update if icon actually updated)
            if sync_icons:
                resources.download_icon(slug, 'banner', overwrite=True,
                                        callback=caller.on_image_downloaded)
                resources.download_icon(slug, 'icon', overwrite=True,
                                        callback=caller.on_image_downloaded)
                updated.add(slug)

        logger.debug("%d games updated", len(updated))
        return updated
Beispiel #6
0
    def _write_config(self):
        """Write the game configuration as a Lutris launcher."""
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % self.game_slug)
        runner_name = self.script['runner']
        config = {
            'game': {},
            'realname': self.script['name'],
            'runner': runner_name
        }
        pga.add_or_update(self.script['name'], runner_name,
                          slug=self.game_slug,
                          directory=self.target_path,
                          installed=1,
                          installer_slug=self.script.get('installer_slug'))
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if runner_name in self.script:
            config[runner_name] = self._substitute_config(
                self.script[runner_name]
            )
        if 'game' in self.script:
            config['game'] = self._substitute_config(self.script['game'])
        is_64bit = platform.machine() == "x86_64"
        exe = 'exe64' if 'exe64' in self.script and is_64bit else 'exe'
        for launcher in [exe, 'iso', 'rom', 'disk', 'main_file']:
            if launcher in self.script:
                if launcher == "exe64":
                    key = "exe"
                else:
                    key = launcher
                game_resource = self.script[launcher]
                if type(game_resource) == list:
                    resource_paths = []
                    for res in game_resource:
                        if res in self.game_files:
                            resource_paths.append(self.game_files[res])
                        else:
                            resource_paths.append(res)
                    config['game'][key] = resource_paths
                else:
                    if game_resource in self.game_files:
                        game_resource = self.game_files[game_resource]
                    elif os.path.exists(os.path.join(self.target_path,
                                                     game_resource)):
                        game_resource = os.path.join(self.target_path,
                                                     game_resource)
                    else:
                        game_resource = game_resource
                    config['game'][key] = game_resource

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        logger.debug(yaml_config)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #7
0
    def sync_game_details(remote_library):
        """Update local game details,

        :return: The slugs of the updated games.
        :rtype: set
        """
        if not remote_library:
            return set()
        updated = set()

        # Get remote games (TODO: use this when switched API to DRF)
        # remote_games = get_games(sorted(local_slugs))
        # if not remote_games:
        #     return set()

        for game in remote_library:
            slug = game["slug"]
            sync = False
            sync_icons = True
            local_game = pga.get_game_by_slug(slug)
            if not local_game:
                continue

            # Sync updated
            if game["updated"] > local_game["updated"]:
                sync = True
            # Sync new DB fields
            else:
                for key, value in local_game.iteritems():
                    if value or key not in game:
                        continue
                    if game[key]:
                        sync = True
                        sync_icons = False
            if not sync:
                continue

            logger.debug("Syncing details for %s" % slug)
            pga.add_or_update(
                local_game["name"],
                local_game["runner"],
                slug,
                year=game["year"],
                updated=game["updated"],
                steamid=game["steamid"],
            )

            # Sync icons (TODO: Only update if icon actually updated)
            if sync_icons:
                resources.download_icon(slug, "banner", overwrite=True)
                resources.download_icon(slug, "icon", overwrite=True)
                updated.add(slug)

        logger.debug("%d games updated", len(updated))
        return updated
Beispiel #8
0
    def save_game(self, _button):
        """ OK button pressed in the Add Game Dialog """
        name = self.name_entry.get_text()
        self.lutris_config.config["realname"] = name
        self.lutris_config.config["runner"] = self.runner_name

        if self.runner_name and name:
            self.slug = self.lutris_config.save(config_type="game")
            runner_class = lutris.runners.import_runner(self.runner_name)
            runner = runner_class(self.lutris_config)
            pga.add_or_update(name, self.runner_name, slug=self.slug,
                              directory=runner.get_game_path(), installed=1)
            self.destroy()
Beispiel #9
0
 def sync(cls, games, full=False):
     """Import GOG games to the Lutris library"""
     gog_ids = [game.appid for game in games]
     if not gog_ids:
         return ([], [])
     lutris_games = api.get_api_games(gog_ids, query_type="gogid")
     added_games = []
     for game in lutris_games:
         lutris_data = pga.get_game_by_field(game["slug"],
                                             field="slug") or {}
         game_data = {
             "name": game["name"],
             "slug": game["slug"],
             "installed": lutris_data.get("installed"),
             "configpath": lutris_data.get("configpath"),
             "year": game["year"],
             "updated": game["updated"],
             "gogid": game.get(
                 "gogid"
             ),  # GOG IDs will be added at a later stage in the API
         }
         added_games.append(pga.add_or_update(**game_data))
     if not full:
         return added_games, games
     return added_games, []
Beispiel #10
0
def mark_as_installed(appid, runner_name, game_info):
    for key in ['name', 'slug']:
        assert game_info[key]
    logger.info("Setting %s as installed", game_info['name'])
    config_id = (game_info.get('config_path') or make_game_config_id(game_info['slug']))
    game_id = pga.add_or_update(
        name=game_info['name'],
        runner=runner_name,
        slug=game_info['slug'],
        installed=1,
        configpath=config_id,
        installer_slug=game_info['installer_slug']
    )

    config = LutrisConfig(
        runner_slug=runner_name,
        game_config_id=config_id,
    )
    config.raw_game_config.update({
        'appid': appid,
        'exe': game_info['exe'],
        'args': game_info['args']
    })
    config.raw_system_config.update({
        'disable_runtime': True
    })
    config.save()
    return game_id
Beispiel #11
0
 def save(self, metadata_only=False):
     """
     Save the game's config and metadata, if `metadata_only` is set to True,
     do not save the config. This is useful when exiting the game since the
     config might have changed and we don't want to override the changes.
     """
     logger.debug("Saving %s", self)
     if not metadata_only:
         self.config.save()
     self.set_platform_from_runner()
     self.id = pga.add_or_update(
         name=self.name,
         runner=self.runner_name,
         slug=self.slug,
         platform=self.platform,
         year=self.year,
         lastplayed=self.lastplayed,
         directory=self.directory,
         installed=self.is_installed,
         configpath=self.config.game_config_id,
         steamid=self.steamid,
         id=self.id,
         playtime=self.playtime,
     )
     self.emit("game-updated")
Beispiel #12
0
def mark_as_installed(appid, runner_name, game_info):
    for key in ['name', 'slug']:
        assert game_info[key]
    logger.info("Setting %s as installed" % game_info['name'])
    config_id = (game_info.get('config_path') or make_game_config_id(game_info['slug']))
    game_id = pga.add_or_update(
        name=game_info['name'],
        runner=runner_name,
        slug=game_info['slug'],
        installed=1,
        configpath=config_id,
        installer_slug=game_info['installer_slug']
    )

    config = LutrisConfig(
        runner_slug=runner_name,
        game_config_id=config_id,
    )
    config.raw_game_config.update({
        'appid': appid,
        'exe': game_info['exe'],
        'args': game_info['args']
    })
    config.raw_system_config.update({
        'disable_runtime': True
    })
    config.save()
    return game_id
Beispiel #13
0
def mark_as_uninstalled(game_info):
    for key in ('id', 'name'):
        if key not in game_info:
            raise ValueError("Missing %s field in %s" % (key, game_info))
    logger.info('Setting %s as uninstalled' % game_info['name'])
    game_id = pga.add_or_update(id=game_info['id'], runner='', installed=0)
    return game_id
Beispiel #14
0
 def save(self, metadata_only=False):
     """
     Save the game's config and metadata, if `metadata_only` is set to True,
     do not save the config. This is useful when exiting the game since the
     config might have changed and we don't want to override the changes.
     """
     logger.debug("Saving %s", self)
     if not metadata_only:
         self.config.save()
     self.set_platform_from_runner()
     self.id = pga.add_or_update(
         name=self.name,
         runner=self.runner_name,
         slug=self.slug,
         platform=self.platform,
         year=self.year,
         lastplayed=self.lastplayed,
         directory=self.directory,
         installed=self.is_installed,
         configpath=self.config.game_config_id,
         steamid=self.steamid,
         id=self.id,
         playtime=self.playtime,
     )
     self.emit("game-updated")
Beispiel #15
0
 def on_save(self, _button):
     """Save game info and destroy widget. Return True if success."""
     if not self.is_valid():
         return False
     name = self.name_entry.get_text()
     if not self.lutris_config.game:
         self.lutris_config.game = slugify(name)
     self.lutris_config.save()
     self.slug = self.lutris_config.game
     runner_class = lutris.runners.import_runner(self.runner_name)
     runner = runner_class(self.lutris_config)
     pga.add_or_update(name, self.runner_name, slug=self.slug,
                       directory=runner.game_path,
                       installed=1)
     self.destroy()
     logger.debug("Saved %s", name)
     return True
Beispiel #16
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game["slug"]
        sync_required = False
        local_game = pga.get_game_by_field(slug, "slug")
        if not local_game:
            continue
        if local_game[
                "updated"] and remote_game["updated"] > local_game["updated"]:
            # The remote game's info is more recent than the local game
            sync_required = True
        else:
            for key in remote_game.keys():
                if (key in local_game.keys() and remote_game[key]
                        and not local_game[key]):
                    # Remote game has data that is missing from the local game.
                    logger.info("Key %s is not present, forcing update", key)
                    sync_required = True
                    break

        if not sync_required:
            continue

        logger.debug("Syncing details for %s", slug)
        game_id = pga.add_or_update(
            id=local_game["id"],
            name=local_game["name"],
            runner=local_game["runner"],
            slug=slug,
            year=remote_game["year"],
            updated=remote_game["updated"],
            steamid=remote_game["steamid"],
        )
        updated.add(game_id)

        if not local_game.get(
                "has_custom_banner") and remote_game["banner_url"]:
            path = resources.get_icon_path(slug, resources.BANNER)
            resources.download_media(remote_game["banner_url"],
                                     path,
                                     overwrite=True)
        if not local_game.get("has_custom_icon") and remote_game["icon_url"]:
            path = resources.get_icon_path(slug, resources.ICON)
            resources.download_media(remote_game["icon_url"],
                                     path,
                                     overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #17
0
 def on_save(self, _button):
     """Save game info and destroy widget. Return True if success."""
     name = self.name_entry.get_text()
     if self.runner_name and name:
         self.lutris_config.config_type = 'game'
         if not self.lutris_config.game:
             self.lutris_config.game = slugify(name)
         self.lutris_config.save()
         self.slug = self.lutris_config.game
         runner_class = lutris.runners.import_runner(self.runner_name)
         runner = runner_class(self.lutris_config)
         pga.add_or_update(name,
                           self.runner_name,
                           slug=self.slug,
                           directory=runner.game_path,
                           installed=1)
         self.destroy()
         return True
Beispiel #18
0
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(
        id=game_info['id'],
        runner='',
        installed=0
    )
    return game_id
Beispiel #19
0
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(
        id=game_info['id'],
        runner='',
        installed=0
    )
    return game_id
Beispiel #20
0
 def on_save(self, _button):
     """Save game info and destroy widget. Return True if success."""
     if not self.is_valid():
         return False
     name = self.name_entry.get_text()
     if not self.lutris_config.game:
         self.lutris_config.game = slugify(name)
     self.lutris_config.save()
     self.slug = self.lutris_config.game
     runner_class = lutris.runners.import_runner(self.runner_name)
     runner = runner_class(self.lutris_config)
     pga.add_or_update(name,
                       self.runner_name,
                       slug=self.slug,
                       directory=runner.game_path,
                       installed=1)
     self.destroy()
     logger.debug("Saved %s", name)
     return True
Beispiel #21
0
 def save(self):
     self.config.save()
     self.id = pga.add_or_update(name=self.name,
                                 runner=self.runner_name,
                                 slug=self.slug,
                                 directory=self.directory,
                                 installed=self.is_installed,
                                 configpath=self.config.game_config_id,
                                 steamid=self.steamid,
                                 id=self.id)
Beispiel #22
0
    def sync_steam_local(self, caller):
        """Sync Steam games in library with Steam and Wine Steam"""
        logger.debug("Syncing local steam games")
        steamrunner = steam()
        winesteamrunner = winesteam()

        # Get installed steamapps
        installed_steamapps = self._get_installed_steamapps(steamrunner)
        installed_winesteamapps = self._get_installed_steamapps(winesteamrunner)

        for game_info in self.library:
            runner = game_info['runner']
            game = Game(game_info['slug'])
            steamid = game_info['steamid']
            installed_in_steam = steamid in installed_steamapps
            installed_in_winesteam = steamid in installed_winesteamapps

            # Set installed
            if not game_info['installed']:
                if not installed_in_steam:  # (Linux Steam only)
                    continue
                logger.debug("Setting %s as installed" % game_info['name'])
                pga.add_or_update(game_info['name'], 'steam',
                                  game_info['slug'],
                                  installed=1)
                game.config.game_config.update({'game':
                                                {'appid': str(steamid)}})
                game.config.save()
                caller.view.set_installed(Game(game_info['slug']))

            # Set uninstalled
            elif not (installed_in_steam or installed_in_winesteam):
                if runner not in ['steam', 'winesteam']:
                    continue
                if runner == 'steam' and not steamrunner.is_installed():
                    continue
                if runner == 'winesteam' and not winesteamrunner.is_installed():
                    continue
                logger.debug("Setting %s as uninstalled" % game_info['name'])
                pga.add_or_update(game_info['name'], '',
                                  game_info['slug'],
                                  installed=0)
                caller.view.set_uninstalled(game_info['slug'])
Beispiel #23
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game['slug']
        sync_required = False
        local_game = pga.get_game_by_field(slug, 'slug')
        if not local_game:
            continue

        if local_game[
                'updated'] and remote_game['updated'] > local_game['updated']:
            # The remote game's info is more recent than the local game
            sync_required = True
        else:
            for key in remote_game.keys():
                if key in local_game.keys(
                ) and remote_game[key] and not local_game[key]:
                    # Remote game has data that is missing from the local game.
                    sync_required = True
                    break

        if not sync_required:
            continue

        logger.debug("Syncing details for %s" % slug)
        game_id = pga.add_or_update(name=local_game['name'],
                                    runner=local_game['runner'],
                                    slug=slug,
                                    year=remote_game['year'],
                                    updated=remote_game['updated'],
                                    steamid=remote_game['steamid'])
        updated.add(game_id)

        if not local_game.get(
                'has_custom_banner') and remote_game['banner_url']:
            path = resources.get_icon_path(slug, resources.BANNER)
            resources.download_media(remote_game['banner_url'],
                                     path,
                                     overwrite=True)
        if not local_game.get('has_custom_icon') and remote_game['icon_url']:
            path = resources.get_icon_path(slug, resources.ICON)
            resources.download_media(remote_game['icon_url'],
                                     path,
                                     overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #24
0
    def sync_steam_local(self):
        """Sync Steam games in library with Steam and Wine Steam"""
        logger.debug("Syncing local steam games")
        steamrunner = steam()
        winesteamrunner = winesteam()
        installed = set()
        uninstalled = set()

        # Get installed steamapps
        installed_steamapps = self._get_installed_steamapps(steamrunner)
        installed_winesteamapps = self._get_installed_steamapps(winesteamrunner)

        for game_info in self.library:
            slug = game_info["slug"]
            runner = game_info["runner"]
            steamid = game_info["steamid"]
            installed_in_steam = steamid in installed_steamapps
            installed_in_winesteam = steamid in installed_winesteamapps

            # Set installed
            if not game_info["installed"]:
                if not installed_in_steam:  # (Linux Steam only)
                    continue
                logger.debug("Setting %s as installed" % game_info["name"])
                pga.add_or_update(game_info["name"], "steam", slug, installed=1)
                game_config = config.LutrisConfig(runner_slug="steam", game_slug=game_info["slug"])
                game_config.raw_game_config.update({"appid": str(steamid)})
                game_config.save()
                installed.add(slug)

            # Set uninstalled
            elif not (installed_in_steam or installed_in_winesteam):
                if runner not in ["steam", "winesteam"]:
                    continue
                if runner == "steam" and not steamrunner.is_installed():
                    continue
                if runner == "winesteam" and not winesteamrunner.is_installed():
                    continue
                logger.debug("Setting %s as uninstalled" % game_info["name"])
                pga.add_or_update(game_info["name"], "", game_info["slug"], installed=0)
                uninstalled.add(slug)
        return (installed, uninstalled)
Beispiel #25
0
def mark_as_uninstalled(game_info):
    for key in ('id', 'name'):
        if key not in game_info:
            raise ValueError("Missing %s field in %s" % (key, game_info))
    logger.info('Setting %s as uninstalled' % game_info['name'])
    game_id = pga.add_or_update(
        id=game_info['id'],
        runner='',
        installed=0
    )
    return game_id
def migrate():
    games = pga.get_games(filter_installed=True)
    for game_info in games:
        if game_info["runner"] != "steam" or game_info["configpath"]:
            continue
        slug = game_info["slug"]
        config_id = make_game_config_id(slug)

        # Add configpath to db
        pga.add_or_update(name=game_info["name"],
                          runner="steam",
                          slug=slug,
                          configpath=config_id)

        # Add appid to config
        game_config = LutrisConfig(runner_slug="steam",
                                   game_config_id=config_id)
        game_config.raw_game_config.update(
            {"appid": str(game_info["steamid"])})
        game_config.save()
Beispiel #27
0
 def save(self):
     self.config.save()
     self.id = pga.add_or_update(
         name=self.name,
         runner=self.runner_name,
         slug=self.slug,
         directory=self.directory,
         installed=self.is_installed,
         configpath=self.config.game_config_id,
         id=self.id
     )
Beispiel #28
0
 def install(self):
     """Add an installed game to the library"""
     self.game_id = pga.add_or_update(
         id=self.game_id,
         name=self.name,
         runner=self.runner,
         slug=self.slug,
         installed=1,
         configpath=self.config_id,
         installer_slug=self.installer_slug,
     )
     self.create_config()
     return self.game_id
Beispiel #29
0
 def install(self):
     """Add an installed game to the library"""
     self.game_id = pga.add_or_update(
         id=self.game_id,
         name=self.name,
         runner=self.runner,
         slug=self.slug,
         installed=1,
         configpath=self.config_id,
         installer_slug=self.installer_slug,
     )
     self.create_config()
     return self.game_id
Beispiel #30
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game['slug']
        sync_required = False
        local_game = pga.get_game_by_field(slug, 'slug')
        if not local_game:
            continue

        if local_game['updated'] and remote_game['updated'] > local_game['updated']:
            # The remote game's info is more recent than the local game
            sync_required = True
        else:
            for key in remote_game.keys():
                if key in local_game.keys() and remote_game[key] and not local_game[key]:
                    # Remote game has data that is missing from the local game.
                    sync_required = True
                    break

        if not sync_required:
            continue

        logger.debug("Syncing details for %s" % slug)
        game_id = pga.add_or_update(
            name=local_game['name'],
            runner=local_game['runner'],
            slug=slug,
            year=remote_game['year'],
            updated=remote_game['updated'],
            steamid=remote_game['steamid']
        )
        updated.add(game_id)

        if not local_game.get('has_custom_banner') and remote_game['banner_url']:
            path = resources.get_icon_path(slug, resources.BANNER)
            resources.download_media(remote_game['banner_url'], path, overwrite=True)
        if not local_game.get('has_custom_icon') and remote_game['icon_url']:
            path = resources.get_icon_path(slug, resources.ICON)
            resources.download_media(remote_game['icon_url'], path, overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #31
0
 def save(self):
     self.config.save()
     self.id = pga.add_or_update(
         name=self.name,
         runner=self.runner_name,
         slug=self.slug,
         platform=self.platform,
         year=self.year,
         lastplayed=self.lastplayed,
         directory=self.directory,
         installed=self.is_installed,
         configpath=self.config.game_config_id,
         steamid=self.steamid,
         id=self.id
     )
Beispiel #32
0
def sync_with_lutris():
    """Sync the ScummVM games to 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():
        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):
        return pga.add_or_update(id=scummvm_games[slug]["id"], installed=0)
Beispiel #33
0
def mark_as_installed(scummvm_id, name, path):
    """Add scummvm from the auto-import"""
    logger.info("Setting %s as installed" % name)
    slug = slugify(name)
    config_id = make_game_config_id(slug)
    game_id = pga.add_or_update(name=name,
                                runner='scummvm',
                                installer_slug=INSTALLER_SLUG,
                                slug=slug,
                                installed=1,
                                configpath=config_id,
                                directory=path)
    config = LutrisConfig(runner_slug='scummvm', game_config_id=config_id)
    config.raw_game_config.update({'game_id': scummvm_id, 'path': path})
    config.save()
    return game_id
Beispiel #34
0
def mark_as_installed(scummvm_id, name, path):
    """Add scummvm from the auto-import"""
    logger.info("Setting %s as installed", name)
    slug = slugify(name)
    config_id = make_game_config_id(slug)
    game_id = pga.add_or_update(
        name=name,
        runner="scummvm",
        installer_slug=INSTALLER_SLUG,
        slug=slug,
        installed=1,
        configpath=config_id,
        directory=path,
    )
    config = LutrisConfig(runner_slug="scummvm", game_config_id=config_id)
    config.raw_game_config.update({"game_id": scummvm_id, "path": path})
    config.save()
    return game_id
Beispiel #35
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game["slug"]
        sync_required = False
        local_game = pga.get_game_by_field(slug, "slug")
        if not local_game:
            continue
        if local_game["updated"] and remote_game["updated"] > local_game["updated"]:
            # The remote game's info is more recent than the local game
            sync_required = True

        if not sync_required:
            continue

        logger.debug("Syncing details for %s", slug)
        game_id = pga.add_or_update(
            id=local_game["id"],
            name=local_game["name"],
            runner=local_game["runner"],
            slug=slug,
            year=remote_game["year"],
            updated=remote_game["updated"],
            steamid=remote_game["steamid"],
        )
        updated.add(game_id)

        if not local_game.get("has_custom_banner") and remote_game["banner_url"]:
            path = resources.get_banner_path(slug)
            resources.download_media(remote_game["banner_url"], path, overwrite=True)
        if not local_game.get("has_custom_icon") and remote_game["icon_url"]:
            path = resources.get_icon_path(slug)
            resources.download_media(remote_game["icon_url"], path, overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #36
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game["slug"]
        sync_required = False
        local_game = pga.get_game_by_field(slug, "slug")
        if not local_game:
            continue
        if local_game["updated"] and remote_game["updated"] > local_game["updated"]:
            # The remote game's info is more recent than the local game
            sync_required = True

        if not sync_required:
            continue

        logger.debug("Syncing details for %s", slug)
        game_id = pga.add_or_update(
            id=local_game["id"],
            name=local_game["name"],
            runner=local_game["runner"],
            slug=slug,
            year=remote_game["year"],
            updated=remote_game["updated"],
            steamid=remote_game["steamid"],
        )
        updated.add(game_id)

        if not local_game.get("has_custom_banner") and remote_game["banner_url"]:
            path = resources.get_banner_path(slug)
            resources.download_media(remote_game["banner_url"], path, overwrite=True)
        if not local_game.get("has_custom_icon") and remote_game["icon_url"]:
            path = resources.get_icon_path(slug)
            resources.download_media(remote_game["icon_url"], path, overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #37
0
 def sync(cls, games, full=False):
     """Import GOG games to the Lutris library"""
     gog_ids = [game.appid for game in games]
     if not gog_ids:
         return ([], [])
     lutris_games = api.get_api_games(gog_ids, query_type="gogid")
     added_games = []
     for game in lutris_games:
         game_data = {
             "name": game["name"],
             "slug": game["slug"],
             "year": game["year"],
             "updated": game["updated"],
             "gogid": game.get("gogid"),  # GOG IDs will be added at a later stage in the API
         }
         added_games.append(pga.add_or_update(**game_data))
     if not full:
         return added_games
     return added_games, []
Beispiel #38
0
 def sync(cls, games, full=True):
     """Import Humble Bundle games to the library"""
     humbleids = [game.appid for game in games]
     if not humbleids:
         return ([], [])
     lutris_games = api.get_api_games(humbleids, query_type="humblestoreid")
     added_games = []
     for game in lutris_games:
         game_data = {
             "name": game["name"],
             "slug": game["slug"],
             "year": game["year"],
             "updated": game["updated"],
             "humblestoreid": game["humblestoreid"],
         }
         added_games.append(pga.add_or_update(**game_data))
     if not full:
         return added_games, games
     return added_games, []
Beispiel #39
0
def mark_as_installed(steamid, runner_name, game_info):
    for key in ['name', 'slug']:
        assert game_info[key]
    logger.info("Setting %s as installed" % game_info['name'])
    config_id = (game_info.get('config_path') or make_game_config_id(game_info['slug']))
    game_id = pga.add_or_update(
        steamid=int(steamid),
        name=game_info['name'],
        runner=runner_name,
        slug=game_info['slug'],
        installed=1,
        configpath=config_id,
    )

    game_config = LutrisConfig(
        runner_slug=runner_name,
        game_config_id=config_id,
    )
    game_config.raw_game_config.update({'appid': steamid})
    game_config.save()
    return game_id
Beispiel #40
0
def mark_as_installed(steamid, runner_name, game_info):
    for key in ['name', 'slug']:
        assert game_info[key]
    logger.info("Setting %s as installed" % game_info['name'])
    config_id = (game_info.get('config_path') or make_game_config_id(game_info['slug']))
    game_id = pga.add_or_update(
        steamid=int(steamid),
        name=game_info['name'],
        runner=runner_name,
        slug=game_info['slug'],
        installed=1,
        configpath=config_id,
    )

    game_config = LutrisConfig(
        runner_slug=runner_name,
        game_config_id=config_id,
    )
    game_config.raw_game_config.update({'appid': steamid})
    game_config.save()
    return game_id
Beispiel #41
0
    def install(self, updated_info=None):
        """Add an installed game to the library

        Params:
            updated_info (dict): Optional dictonary containing existing data not to overwrite
        """
        if updated_info:
            name = updated_info["name"]
            slug = updated_info["slug"]
        else:
            name = self.name
            slug = self.slug
        self.game_id = pga.add_or_update(
            id=self.game_id,
            name=name,
            runner=self.runner,
            slug=slug,
            steamid=self.steamid,
            installed=1,
            configpath=self.config_id,
            installer_slug=self.installer_slug,
        )
        self.create_config()
        return self.game_id
Beispiel #42
0
    def install(self, updated_info=None):
        """Add an installed game to the library

        Params:
            updated_info (dict): Optional dictonary containing existing data not to overwrite
        """
        if updated_info:
            name = updated_info["name"]
            slug = updated_info["slug"]
        else:
            name = self.name
            slug = self.slug
        self.game_id = pga.add_or_update(
            id=self.game_id,
            name=name,
            runner=self.runner,
            slug=slug,
            steamid=int(self.appid),
            installed=1,
            configpath=self.config_id,
            installer_slug=self.installer_slug,
        )
        self.create_config()
        return self.game_id
Beispiel #43
0
    def _write_config(self):
        """Write the game configuration as a Lutris launcher."""
        runner_name = self.script['runner']

        # Get existing config
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % self.game_slug)
        if self.requires and os.path.exists(config_filename):
            # The installer is patching an existing game, update its config
            # XXX Maybe drop the self.requires condition and always update
            #     the existing config?
            lutris_config = LutrisConfig(game=self.game_slug)
            config = lutris_config.game_config
        else:
            config = {
                'game': {},
            }

        # DB update
        pga.add_or_update(self.script['name'], runner_name,
                          slug=self.game_slug,
                          directory=self.target_path,
                          installed=1,
                          installer_slug=self.script.get('installer_slug'),
                          year=self.script.get('year'),
                          steamid=self.script.get('steamid'))

        # Config update
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if runner_name in self.script:
            config[runner_name] = self._substitute_config(
                self.script[runner_name]
            )
        if 'game' in self.script:
            config['game'].update(self._substitute_config(self.script['game']))

        is_64bit = platform.machine() == "x86_64"
        exe = 'exe64' if 'exe64' in self.script and is_64bit else 'exe'

        for launcher in [exe, 'iso', 'rom', 'disk', 'main_file']:
            if launcher in self.script:
                if launcher == "exe64":
                    key = "exe"
                else:
                    key = launcher
                game_resource = self.script[launcher]
                if type(game_resource) == list:
                    resource_paths = []
                    for res in game_resource:
                        if res in self.game_files:
                            resource_paths.append(self.game_files[res])
                        else:
                            resource_paths.append(res)
                    config['game'][key] = resource_paths
                else:
                    if game_resource in self.game_files:
                        game_resource = self.game_files[game_resource]
                    elif os.path.exists(os.path.join(self.target_path,
                                                     game_resource)):
                        game_resource = os.path.join(self.target_path,
                                                     game_resource)
                    else:
                        game_resource = game_resource
                    config['game'][key] = game_resource

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        logger.debug(yaml_config)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #44
0
    def _write_config(self):
        """Write the game configuration in the DB and config file."""

        configpath = make_game_config_id(self.script['slug'])
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % configpath)
        if self.requires:  # and os.path.exists(config_filename):
            # The installer is patching an existing game, update its config
            # XXX Maybe drop the self.requires condition and always update
            #     the existing config?
            # XXX Now it's not going to update configs ever again since we
            # create a unique config_id so how do we deal with that?

            # is that okay?
            required_game = pga.get_game_by_field(self.requires,
                                                  field='installer_slug')
            lutris_config = LutrisConfig(
                runner_slug=self.runner,
                game_config_id=required_game['configpath']
            )
            config = lutris_config.game_level
        else:
            config = {
                'game': {},
            }

        self.game_id = pga.add_or_update(
            name=self.script['name'],
            runner=self.runner,
            slug=self.game_slug,
            directory=self.target_path,
            installed=1,
            installer_slug=self.script['slug'],
            parent_slug=self.requires,
            year=self.script.get('year'),
            steamid=self.script.get('steamid'),
            configpath=configpath,
            id=self.game_id
        )
        logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)

        # Config update
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if self.runner in self.script:
            config[self.runner] = self._substitute_config(
                self.script[self.runner]
            )
        if 'game' in self.script:
            config['game'].update(self._substitute_config(self.script['game']))

        launcher, launcher_value = self._get_game_launcher()
        if type(launcher_value) == list:
            game_files = []
            for game_file in launcher_value:
                if game_file in self.game_files:
                    game_files.append(self.game_files[game_file])
                else:
                    game_files.append(game_file)
            config['game'][launcher] = game_files
        elif launcher_value:
            if launcher_value in self.game_files:
                launcher_value = (
                    self.game_files[launcher_value]
                )
            elif self.target_path and os.path.exists(
                os.path.join(self.target_path, launcher_value)
            ):
                launcher_value = os.path.join(self.target_path, launcher_value)
            config['game'][launcher] = launcher_value

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        logger.debug(yaml_config)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #45
0
    def _write_config(self):
        """Write the game configuration as a Lutris launcher."""
        runner_name = self.script["runner"]

        # Get existing config
        config_filename = os.path.join(settings.CONFIG_DIR, "games/%s.yml" % self.game_slug)
        if self.requires and os.path.exists(config_filename):
            # The installer is patching an existing game, update its config
            # XXX Maybe drop the self.requires condition and always update
            #     the existing config?
            lutris_config = LutrisConfig(runner_slug=runner_name, game_slug=self.game_slug)
            config = lutris_config.game_level
        else:
            config = {"game": {}}

        # DB update
        pga.add_or_update(
            self.script["name"],
            runner_name,
            slug=self.game_slug,
            directory=self.target_path,
            installed=1,
            installer_slug=self.script.get("slug"),
            year=self.script.get("year"),
            steamid=self.script.get("steamid"),
        )

        # Config update
        if "system" in self.script:
            config["system"] = self._substitute_config(self.script["system"])
        if runner_name in self.script:
            config[runner_name] = self._substitute_config(self.script[runner_name])
        if "game" in self.script:
            config["game"].update(self._substitute_config(self.script["game"]))

        is_64bit = platform.machine() == "x86_64"
        exe = "exe64" if "exe64" in self.script and is_64bit else "exe"

        for launcher in [exe, "iso", "rom", "disk", "main_file"]:
            if launcher not in self.script:
                continue
            launcher_description = self.script[launcher]
            if launcher == "exe64":
                launcher = "exe"
            if type(launcher_description) == list:
                game_files = []
                for game_file in launcher_description:
                    if game_file in self.game_files:
                        game_files.append(self.game_files[game_file])
                    else:
                        game_files.append(game_file)
                config["game"][launcher] = game_files
            else:
                if launcher_description in self.game_files:
                    launcher_description = self.game_files[launcher_description]
                elif os.path.exists(os.path.join(self.target_path, launcher_description)):
                    launcher_description = os.path.join(self.target_path, launcher_description)
                else:
                    launcher_description = launcher_description
                config["game"][launcher] = launcher_description

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        logger.debug(yaml_config)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #46
0
    def _write_config(self):
        """Write the game configuration as a Lutris launcher."""
        runner_name = self.script['runner']

        # Get existing config
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % self.game_slug)
        if self.requires and os.path.exists(config_filename):
            # The installer is patching an existing game, update its config
            # XXX Maybe drop the self.requires condition and always update
            #     the existing config?
            lutris_config = LutrisConfig(game=self.game_slug)
            config = lutris_config.game_config
        else:
            config = {
                'game': {},
            }

        # DB update
        pga.add_or_update(self.script['name'], runner_name,
                          slug=self.game_slug,
                          directory=self.target_path,
                          installed=1,
                          installer_slug=self.script.get('installer_slug'),
                          year=self.script.get('year'),
                          steamid=self.script.get('steamid'))

        # Config update
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if runner_name in self.script:
            config[runner_name] = self._substitute_config(
                self.script[runner_name]
            )
        if 'game' in self.script:
            config['game'].update(self._substitute_config(self.script['game']))

        is_64bit = platform.machine() == "x86_64"
        exe = 'exe64' if 'exe64' in self.script and is_64bit else 'exe'

        for launcher in [exe, 'iso', 'rom', 'disk', 'main_file']:
            if launcher in self.script:
                if launcher == "exe64":
                    key = "exe"
                else:
                    key = launcher
                game_resource = self.script[launcher]
                if type(game_resource) == list:
                    resource_paths = []
                    for res in game_resource:
                        if res in self.game_files:
                            resource_paths.append(self.game_files[res])
                        else:
                            resource_paths.append(res)
                    config['game'][key] = resource_paths
                else:
                    if game_resource in self.game_files:
                        game_resource = self.game_files[game_resource]
                    elif os.path.exists(os.path.join(self.target_path,
                                                     game_resource)):
                        game_resource = os.path.join(self.target_path,
                                                     game_resource)
                    else:
                        game_resource = game_resource
                    config['game'][key] = game_resource

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        logger.debug(yaml_config)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #47
0
    def _write_config(self):
        """Write the game configuration in the DB and config file.

        This needs to be unfucked
        """
        if self.extends:
            logger.info(
                "This is an extension to %s, not creating a new game entry",
                self.extends,
            )
            return
        configpath = make_game_config_id(self.slug)
        config_filename = os.path.join(settings.CONFIG_DIR, "games/%s.yml" % configpath)

        if self.requires:
            # Load the base game config
            required_game = pga.get_game_by_field(self.requires, field="installer_slug")
            base_config = LutrisConfig(
                runner_slug=self.runner, game_config_id=required_game["configpath"]
            )
            config = base_config.game_level
        else:
            config = {"game": {}}

        self.game_id = pga.add_or_update(
            name=self.game_name,
            runner=self.runner,
            slug=self.game_slug,
            directory=self.target_path,
            installed=1,
            installer_slug=self.slug,
            parent_slug=self.requires,
            year=self.year,
            steamid=self.steamid,
            configpath=configpath,
            id=self.game_id,
        )

        game = Game(self.game_id)
        game.save()

        logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)

        # Config update
        if "system" in self.script:
            config["system"] = self._substitute_config(self.script["system"])
        if self.runner in self.script and self.script[self.runner]:
            config[self.runner] = self._substitute_config(self.script[self.runner])

        # Game options such as exe or main_file can be added at the root of the
        # script as a shortcut, this integrates them into the game config
        # properly
        launcher, launcher_value = _get_game_launcher(self.script)
        if isinstance(launcher_value, list):
            game_files = []
            for game_file in launcher_value:
                if game_file in self.game_files:
                    game_files.append(self.game_files[game_file])
                else:
                    game_files.append(game_file)
            config["game"][launcher] = game_files
        elif launcher_value:
            if launcher_value in self.game_files:
                launcher_value = self.game_files[launcher_value]
            elif self.target_path and os.path.exists(
                    os.path.join(self.target_path, launcher_value)
            ):
                launcher_value = os.path.join(self.target_path, launcher_value)
            config["game"][launcher] = launcher_value

        if "game" in self.script:
            try:
                config["game"].update(self.script["game"])
            except ValueError:
                raise ScriptingError("Invalid 'game' section", self.script["game"])
            config["game"] = self._substitute_config(config["game"])

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #48
0
    def _write_config(self):
        """Write the game configuration in the DB and config file."""
        runner_name = self.script['runner']

        configpath = "{}-{}".format(self.script['slug'], int(time.time()))
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % configpath)
        if self.requires:  # and os.path.exists(config_filename):
            # The installer is patching an existing game, update its config
            # XXX Maybe drop the self.requires condition and always update
            #     the existing config?
            # XXX Now it's not going to update configs ever again since we
            # create a unique config_id so how do we deal with that?

            # is that okay?
            required_game = pga.get_game_by_field(self.requires,
                                                  field='installer_slug')
            lutris_config = LutrisConfig(
                runner_slug=runner_name,
                game_config_id=required_game['configpath']
            )
            config = lutris_config.game_level
        else:
            config = {
                'game': {},
            }

        self.game_id = pga.add_or_update(
            name=self.script['name'],
            runner=runner_name,
            slug=self.game_slug,
            directory=self.target_path,
            installed=1,
            installer_slug=self.script['slug'],
            parent_slug=self.requires,
            year=self.script.get('year'),
            steamid=self.script.get('steamid'),
            configpath=configpath,
            id=self.game_id
        )

        # Config update
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if runner_name in self.script:
            config[runner_name] = self._substitute_config(
                self.script[runner_name]
            )
        if 'game' in self.script:
            config['game'].update(self._substitute_config(self.script['game']))

        is_64bit = platform.machine() == "x86_64"
        exe = 'exe64' if 'exe64' in self.script and is_64bit else 'exe'

        for launcher in [exe, 'iso', 'rom', 'disk', 'main_file']:
            if launcher not in self.script:
                continue
            launcher_description = self.script[launcher]
            if launcher == "exe64":
                launcher = "exe"
            if type(launcher_description) == list:
                game_files = []
                for game_file in launcher_description:
                    if game_file in self.game_files:
                        game_files.append(self.game_files[game_file])
                    else:
                        game_files.append(game_file)
                config['game'][launcher] = game_files
            else:
                if launcher_description in self.game_files:
                    launcher_description = (
                        self.game_files[launcher_description]
                    )
                elif os.path.exists(os.path.join(self.target_path,
                                                 launcher_description)):
                    launcher_description = os.path.join(self.target_path,
                                                        launcher_description)
                else:
                    launcher_description = launcher_description
                config['game'][launcher] = launcher_description

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        logger.debug(yaml_config)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #49
0
    def write_config(self):
        """Write the game configuration in the DB and config file"""
        if self.extends:
            logger.info(
                "This is an extension to %s, not creating a new game entry",
                self.extends,
            )
            return
        configpath = make_game_config_id(self.slug)
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % configpath)

        if self.requires:
            # Load the base game config
            required_game = pga.get_game_by_field(self.requires,
                                                  field="installer_slug")
            base_config = LutrisConfig(
                runner_slug=self.runner,
                game_config_id=required_game["configpath"])
            config = base_config.game_level
        else:
            config = {"game": {}}

        self.game_id = pga.add_or_update(
            name=self.game_name,
            runner=self.runner,
            slug=self.game_slug,
            directory=self.interpreter.target_path,
            installed=1,
            installer_slug=self.slug,
            parent_slug=self.requires,
            year=self.year,
            steamid=self.steamid,
            configpath=configpath,
            id=self.game_id,
        )

        game = Game(self.game_id)
        game.save()

        logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)

        # Config update
        if "system" in self.script:
            config["system"] = self._substitute_config(self.script["system"])
        if self.runner in self.script and self.script[self.runner]:
            config[self.runner] = self._substitute_config(
                self.script[self.runner])
        launcher, launcher_config = self.get_game_launcher_config(
            self.interpreter.game_files)
        if launcher:
            config["game"][launcher] = launcher_config

        if "game" in self.script:
            try:
                config["game"].update(self.script["game"])
            except ValueError:
                raise ScriptingError("Invalid 'game' section",
                                     self.script["game"])
            config["game"] = self._substitute_config(config["game"])

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #50
0
def mark_as_uninstalled(game_info):
    logger.info("Uninstalling %s", game_info["name"])
    return pga.add_or_update(id=game_info["id"], installed=0)
Beispiel #51
0
    def _write_config(self):
        """Write the game configuration in the DB and config file.

        This needs to be unfucked
        """
        if self.extends:
            logger.info(
                "This is an extension to %s, not creating a new game entry",
                self.extends,
            )
            return
        configpath = make_game_config_id(self.slug)
        config_filename = os.path.join(settings.CONFIG_DIR, "games/%s.yml" % configpath)

        if self.requires:
            # Load the base game config
            required_game = pga.get_game_by_field(self.requires, field="installer_slug")
            base_config = LutrisConfig(
                runner_slug=self.runner, game_config_id=required_game["configpath"]
            )
            config = base_config.game_level
        else:
            config = {"game": {}}

        self.game_id = pga.add_or_update(
            name=self.game_name,
            runner=self.runner,
            slug=self.game_slug,
            directory=self.target_path,
            installed=1,
            installer_slug=self.slug,
            parent_slug=self.requires,
            year=self.year,
            steamid=self.steamid,
            configpath=configpath,
            id=self.game_id,
        )

        game = Game(self.game_id)
        game.set_platform_from_runner()
        game.save()

        logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)

        # Config update
        if "system" in self.script:
            config["system"] = self._substitute_config(self.script["system"])
        if self.runner in self.script and self.script[self.runner]:
            config[self.runner] = self._substitute_config(self.script[self.runner])

        # Game options such as exe or main_file can be added at the root of the
        # script as a shortcut, this integrates them into the game config
        # properly
        launcher, launcher_value = _get_game_launcher(self.script)
        if isinstance(launcher_value, list):
            game_files = []
            for game_file in launcher_value:
                if game_file in self.game_files:
                    game_files.append(self.game_files[game_file])
                else:
                    game_files.append(game_file)
            config["game"][launcher] = game_files
        elif launcher_value:
            if launcher_value in self.game_files:
                launcher_value = self.game_files[launcher_value]
            elif self.target_path and os.path.exists(
                    os.path.join(self.target_path, launcher_value)
            ):
                launcher_value = os.path.join(self.target_path, launcher_value)
            config["game"][launcher] = launcher_value

        if "game" in self.script:
            try:
                config["game"].update(self.script["game"])
            except ValueError:
                raise ScriptingError("Invalid 'game' section", self.script["game"])
            config["game"] = self._substitute_config(config["game"])

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
        if not self.extends:
            game.emit("game-installed")
Beispiel #52
0
 def uninstall(self):
     """Uninstall a game from Lutris"""
     return pga.add_or_update(id=self.game_id, installed=0)
Beispiel #53
0
 def uninstall(self):
     """Uninstall a game from Lutris"""
     return pga.add_or_update(id=self.game_id, installed=0)
Beispiel #54
0
    def _write_config(self):
        """Write the game configuration in the DB and config file."""
        if self.extends:
            logger.info(
                'This is an extension to %s, not creating a new game entry',
                self.extends)
            return
        configpath = make_game_config_id(self.slug)
        config_filename = os.path.join(settings.CONFIG_DIR,
                                       "games/%s.yml" % configpath)

        if self.requires:
            # Load the base game config
            required_game = pga.get_game_by_field(self.requires,
                                                  field='installer_slug')
            base_config = LutrisConfig(
                runner_slug=self.runner,
                game_config_id=required_game['configpath'])
            config = base_config.game_level
        else:
            config = {
                'game': {},
            }

        self.game_id = pga.add_or_update(name=self.name,
                                         runner=self.runner,
                                         slug=self.game_slug,
                                         directory=self.target_path,
                                         installed=1,
                                         installer_slug=self.slug,
                                         parent_slug=self.requires,
                                         year=self.year,
                                         steamid=self.steamid,
                                         configpath=configpath,
                                         id=self.game_id)

        game = Game(self.game_id)
        game.set_platform_from_runner()
        game.save()

        logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)

        # Config update
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if self.runner in self.script and self.script[self.runner]:
            config[self.runner] = self._substitute_config(
                self.script[self.runner])

        # Game options such as exe or main_file can be added at the root of the
        # script as a shortcut, this integrates them into the game config
        # properly
        launcher, launcher_value = self._get_game_launcher()
        if type(launcher_value) == list:
            game_files = []
            for game_file in launcher_value:
                if game_file in self.game_files:
                    game_files.append(self.game_files[game_file])
                else:
                    game_files.append(game_file)
            config['game'][launcher] = game_files
        elif launcher_value:
            if launcher_value in self.game_files:
                launcher_value = (self.game_files[launcher_value])
            elif self.target_path and os.path.exists(
                    os.path.join(self.target_path, launcher_value)):
                launcher_value = os.path.join(self.target_path, launcher_value)
            config['game'][launcher] = launcher_value

        if 'game' in self.script:
            config['game'].update(self.script['game'])
            config['game'] = self._substitute_config(config['game'])

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)
Beispiel #55
0
def mark_as_uninstalled(game_info):
    logger.info('Uninstalling %s' % game_info['name'])
    return pga.add_or_update(
        id=game_info['id'],
        installed=0
    )
Beispiel #56
0
def mark_as_uninstalled(game_info):
    logger.info("Uninstalling %s", game_info['name'])
    return pga.add_or_update(id=game_info['id'], installed=0)
Beispiel #57
0
    def _write_config(self):
        """Write the game configuration in the DB and config file."""
        if self.extends:
            logger.info('This is an extension to %s, not creating a new game entry',
                        self.extends)
            return
        configpath = make_game_config_id(self.script['slug'])
        config_filename = os.path.join(settings.CONFIG_DIR, "games/%s.yml" % configpath)

        if self.requires:
            # Load the base game config
            required_game = pga.get_game_by_field(self.requires, field='installer_slug')
            base_config = LutrisConfig(
                runner_slug=self.runner,
                game_config_id=required_game['configpath']
            )
            config = base_config.game_level
        else:
            config = {
                'game': {},
            }

        self.game_id = pga.add_or_update(
            name=self.script['name'],
            runner=self.runner,
            slug=self.game_slug,
            directory=self.target_path,
            installed=1,
            installer_slug=self.script['slug'],
            parent_slug=self.requires,
            year=self.script.get('year'),
            steamid=self.script.get('steamid'),
            configpath=configpath,
            id=self.game_id
        )
        logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)

        # Config update
        if 'system' in self.script:
            config['system'] = self._substitute_config(self.script['system'])
        if self.runner in self.script and self.script[self.runner]:
            config[self.runner] = self._substitute_config(
                self.script[self.runner]
            )

        # Game options such as exe or main_file can be added at the root of the
        # script as a shortcut, this integrates them into the game config
        # properly
        launcher, launcher_value = self._get_game_launcher()
        if type(launcher_value) == list:
            game_files = []
            for game_file in launcher_value:
                if game_file in self.game_files:
                    game_files.append(self.game_files[game_file])
                else:
                    game_files.append(game_file)
            config['game'][launcher] = game_files
        elif launcher_value:
            if launcher_value in self.game_files:
                launcher_value = (
                    self.game_files[launcher_value]
                )
            elif self.target_path and os.path.exists(
                os.path.join(self.target_path, launcher_value)
            ):
                launcher_value = os.path.join(self.target_path, launcher_value)
            config['game'][launcher] = launcher_value

        if 'game' in self.script:
            config['game'].update(self.script['game'])
            config['game'] = self._substitute_config(config['game'])

        yaml_config = yaml.safe_dump(config, default_flow_style=False)
        with open(config_filename, "w") as config_file:
            config_file.write(yaml_config)