예제 #1
0
def create_game(gog_game):
    """Creates a Lutris game from a GOG game"""
    name = clean_name(gog_game["title"])
    try:
        game = Game.objects.create(name=name,
                                   slug=slugify(name),
                                   gogid=gog_game["id"],
                                   gogslug=gog_game["slug"],
                                   is_public=True)
    except IntegrityError:
        LOGGER.warning("Game %s is already in Lutris!", slugify(name))
        game = Game.objects.get(slug=slugify(name))
        game.gogid = gog_game["id"]
        game.gogslug = gog_game["slug"]
    game.set_logo_from_gog(gog_game)
    if gog_game["worksOn"]["Linux"]:
        platform = Platform.objects.get(slug='linux')
    else:
        platform = Platform.objects.get(slug='windows')
    game.platforms.add(platform)
    for gog_genre in gog_game["genres"]:
        genre, created = Genre.objects.get_or_create(slug=slugify(gog_genre))
        if created:
            genre.name = gog_genre
            LOGGER.info("Created genre %s", genre.name)
            genre.save()
        game.genres.add(genre)

    if gog_game["releaseDate"]:
        release_date = datetime.fromtimestamp(gog_game["releaseDate"])
        game.year = release_date.year

    game.save()
    return game
예제 #2
0
파일: tests.py 프로젝트: dmiller309/website
 def test_slugify(self):
     self.assertEqual(slugify(None), "")
     self.assertEqual(slugify("Foo bar"), "foo-bar")
     self.assertEqual(slugify("わがままアリスと百日戦争"), "wagamamaarisuto")
     self.assertEqual(
         slugify("关于我被小学女生绑架这件事"),
         "guan-yu-wo-bei-xiao-xue-nv-sheng-bang-jia-zhe-jian"
     )
예제 #3
0
파일: tests.py 프로젝트: lutris/website
 def test_slugify(self):
     self.assertEqual(slugify(None), "")
     self.assertEqual(slugify("Foo bar"), "foo-bar")
     self.assertEqual(slugify("わがままアリスと百日戦争"), "wagamamaarisuto")
     self.assertEqual(
         slugify("关于我被小学女生绑架这件事"),
         "guan-yu-wo-bei-xiao-xue-nv-sheng-bang-jia-zhe-jian"
     )
def run():
    response = requests.get(
        "https://raw.githubusercontent.com/SteamDatabase/SteamLinux/master/GAMES.json"
    )
    linux_games = response.json()
    for game_id in linux_games:
        if linux_games[game_id] is not True:
            LOGGER.debug(
                "Game %s likely has problems, skipping. "
                "This game should be added manually if appropriate.", game_id)
            continue
        if Game.objects.filter(steamid=game_id).count():
            # LOGGER.debug("Game %s is already in Lutris", game_id)
            continue
        store_info = get_store_info(game_id)
        if not store_info:
            LOGGER.warning("No store info for game %s", game_id)
            continue

        if store_info["type"] != "game":
            LOGGER.warning("%s: %s is not a game (type: %s)", game_id,
                           store_info["name"], store_info["type"])
            continue
        slug = slugify(store_info["name"])
        if Game.objects.filter(slug=slug).count():
            LOGGER.warning(
                "Game %s already in Lutris but does not have a Steam ID",
                game_id)
            continue

        game = Game.objects.create(
            name=store_info["name"],
            slug=slug,
            steamid=game_id,
            description=store_info["short_description"],
            website=store_info["website"] or "",
            is_public=True,
        )
        game.set_logo_from_steam()
        LOGGER.debug("%s created", game)
        if store_info["platforms"]["linux"]:
            platform = Platform.objects.get(slug='linux')
            LOGGER.info("Creating installer for %s", game)
            create_steam_installer(game)
        else:
            platform = Platform.objects.get(slug='windows')
        game.platforms.add(platform)
        for steam_genre in store_info["genres"]:
            genre, created = Genre.objects.get_or_create(
                slug=slugify(steam_genre["description"]))
            if created:
                genre.name = steam_genre["description"]
                LOGGER.info("Created genre %s", genre.name)
                genre.save()
            game.genres.add(genre)
        game.save()
예제 #5
0
def run():
    response = requests.get(
        "https://raw.githubusercontent.com/SteamDatabase/SteamLinux/master/GAMES.json"
    )
    linux_games = response.json()
    for game_id in linux_games:
        if linux_games[game_id] is not True:
            LOGGER.debug(
                "Game %s likely has problems, skipping. "
                "This game should be added manually if appropriate.",
                game_id
            )
            continue
        if Game.objects.filter(steamid=game_id).count():
            # LOGGER.debug("Game %s is already in Lutris", game_id)
            continue
        store_info = get_store_info(game_id)
        if not store_info:
            LOGGER.warning("No store info for game %s", game_id)
            continue

        if store_info["type"] != "game":
            LOGGER.warning("%s: %s is not a game (type: %s)",
                           game_id, store_info["name"], store_info["type"])
            continue
        slug = slugify(store_info["name"])
        if Game.objects.filter(slug=slug).count():
            LOGGER.warning("Game %s already in Lutris but does not have a Steam ID", game_id)
            continue

        game = Game.objects.create(
            name=store_info["name"],
            slug=slug,
            steamid=game_id,
            description=store_info["short_description"],
            website=store_info["website"] or "",
            is_public=True,
        )
        game.set_logo_from_steam()
        LOGGER.debug("%s created", game)
        if store_info["platforms"]["linux"]:
            platform = Platform.objects.get(slug='linux')
            LOGGER.info("Creating installer for %s", game)
            create_steam_installer(game)
        else:
            platform = Platform.objects.get(slug='windows')
        game.platforms.add(platform)
        for steam_genre in store_info["genres"]:
            genre, created = Genre.objects.get_or_create(slug=slugify(steam_genre["description"]))
            if created:
                genre.name = steam_genre["description"]
                LOGGER.info("Created genre %s", genre.name)
                genre.save()
            game.genres.add(genre)
        game.save()
예제 #6
0
 def save(self,
          force_insert=False,
          force_update=False,
          using=None,
          update_fields=None):
     # Only create slug etc. if this is a game submission, no change submission
     if not self.change_for:
         if not self.slug:
             self.slug = slugify(self.name)[:50]
         if not self.slug:
             raise ValueError("Can't generate a slug for name %s" %
                              self.name)
         self.set_logo_from_steam()
         self.check_for_submission()
     super(Game, self).save(
         force_insert=force_insert,
         force_update=force_update,
         using=using,
         update_fields=update_fields,
     )
     # Not ideal to have this here since this can generate disk IO activity
     # Not a problem though, we want to discourage mass updates for games
     # since that would DDOS the site.
     try:
         self.precache_media()
     except Exception as ex:  # pylint: disable=broad-except
         LOGGER.error("Failed to precache media for %s: %s", self, ex)
예제 #7
0
 def handle(self, *args, **options):
     arcade_platform = Platform.objects.get(slug="arcade")
     for game in models.ProviderGame.objects.filter(provider__name="MAME"):
         match = self.find_matches(game)
         if not match and options.get("create_missing"):
             mame_year = int(
                 game.metadata["year"]) if game.metadata["year"] else None
             publisher_slug = slugify(game.metadata.get("publisher", ""))
             if publisher_slug:
                 publisher, created = Company.objects.get_or_create(
                     slug=publisher_slug)
                 if created:
                     publisher.name = game.metadata["publisher"]
                     publisher.save()
             else:
                 publisher = None
             lutris_game = Game.objects.create(name=game.name,
                                               slug=get_auto_increment_slug(
                                                   Game, None, game.name),
                                               year=mame_year,
                                               publisher=publisher,
                                               is_public=True)
             lutris_game.platforms.add(arcade_platform)
             lutris_game.provider_games.add(game)
             print("Created %s" % lutris_game)
예제 #8
0
파일: tasks.py 프로젝트: lutris/website
def sync_steam_library(user_id):
    user = User.objects.get(pk=user_id)
    steamid = user.steamid
    library = games.models.GameLibrary.objects.get(user=user)
    steam_games = games.util.steam.steam_sync(steamid)
    if not steam_games:
        LOGGER.info("Steam user %s has no steam games", user.username)
        return
    for game in steam_games:
        LOGGER.info("Adding %s to %s's library", game['name'], user.username)
        if not game['img_icon_url']:
            LOGGER.info("Game %s has no icon", game['name'])
            continue
        try:
            steam_game = games.models.Game.objects.get(steamid=game['appid'])
        except games.models.Game.MultipleObjectsReturned:
            LOGGER.error("Multiple games with appid '%s'", game['appid'])
            continue
        except games.models.Game.DoesNotExist:
            LOGGER.info("No game with steam id %s", game['appid'])
            try:
                steam_game = games.models.Game.objects.get(
                    slug=slugify(game['name'])[:50]
                )
                if not steam_game.steamid:
                    steam_game.steamid = game['appid']
                    steam_game.save()
            except games.models.Game.DoesNotExist:
                steam_game = create_game(game)
                LOGGER.info("Creating game %s", steam_game.slug)
        try:
            library.games.add(steam_game)
        except IntegrityError:
            # Game somehow already added.
            pass
예제 #9
0
def sync_steam_library(user_id):
    """Launch a Steam to Lutris library sync"""
    user = User.objects.get(pk=user_id)
    steamid = user.steamid
    library = games.models.GameLibrary.objects.get(user=user)
    steam_games = games.util.steam.steam_sync(steamid)
    if not steam_games:
        LOGGER.info("Steam user %s has no steam games", user.username)
        return
    for game in steam_games:
        LOGGER.info("Adding %s to %s's library", game['name'], user.username)
        if not game['img_icon_url']:
            LOGGER.info("Game %s has no icon", game['name'])
            continue
        try:
            steam_game = games.models.Game.objects.get(steamid=game['appid'])
        except games.models.Game.MultipleObjectsReturned:
            LOGGER.error("Multiple games with appid '%s'", game['appid'])
            continue
        except games.models.Game.DoesNotExist:
            LOGGER.info("No game with steam id %s", game['appid'])
            try:
                steam_game = games.models.Game.objects.get(
                    slug=slugify(game['name'])[:50])
                if not steam_game.steamid:
                    steam_game.steamid = game['appid']
                    steam_game.save()
            except games.models.Game.DoesNotExist:
                steam_game = create_game(game)
                LOGGER.info("Creating game %s", steam_game.slug)
        try:
            library.games.add(steam_game)
        except IntegrityError:
            # Game somehow already added.
            pass
예제 #10
0
파일: api.py 프로젝트: shrey2801/website-3
def get_or_create_company(name):
    if not name:
        return
    slug = slugify(name)[:50]
    try:
        company = Company.objects.get(slug=slug)
    except Company.DoesNotExist:
        company = Company.objects.create(slug=slug, name=name)
    return company
예제 #11
0
 def get_existing_matches(self, game):
     """Return Lutris games matching GOG games"""
     game_name = self.clean_name(game.name)
     return Game.objects.filter(
         Q(name=game_name)
         | Q(gogid=game.slug)
         | Q(slug=slugify(game_name))
         | Q(aliases__name=game_name)).exclude(
             change_for__isnull=False).order_by('id').distinct('id')
예제 #12
0
파일: models.py 프로젝트: rinpatch/website
 def save(self,
          force_insert=False,
          force_update=False,
          using=False,
          update_fields=False):
     self.slug = slugify(self.title)
     return super(News, self).save(force_insert=force_insert,
                                   force_update=force_insert,
                                   using=using,
                                   update_fields=update_fields)
예제 #13
0
파일: models.py 프로젝트: lutris/website
 def save(
         self, force_insert=False, force_update=False, using=None, update_fields=None
 ):
     if not self.slug:
         self.slug = slugify(self.name)
     return super(Genre, self).save(
         force_insert=force_insert,
         force_update=force_update,
         using=using,
         update_fields=update_fields,
     )
예제 #14
0
 def save(self,
          force_insert=False,
          force_update=False,
          using=None,
          update_fields=None):
     if not self.slug:
         self.slug = slugify(str(self.name))
     return super(Platform, self).save(force_insert=force_insert,
                                       force_update=force_update,
                                       using=using,
                                       update_fields=update_fields)
예제 #15
0
 def save(
         self, force_insert=False, force_update=False, using=None, update_fields=None
 ):
     self.slug = slugify(self.name)
     if not self.slug:
         raise ValueError("Tried to save Company without a slug: %s" % self)
     return super(Company, self).save(
         force_insert=force_insert,
         force_update=force_update,
         using=using,
         update_fields=update_fields,
     )
예제 #16
0
파일: api.py 프로젝트: lutris/website
def get_or_create_company(name):
    if not name:
        return
    slug = slugify(name)[:50]
    try:
        company = Company.objects.get(slug=slug)
    except Company.DoesNotExist:
        company = Company.objects.create(
            slug=slug,
            name=name
        )
    return company
예제 #17
0
def create_game(gog_game):
    """Creates a Lutris game from a GOG game"""
    name = clean_name(gog_game["title"])
    try:
        game = Game.objects.create(
            name=name,
            slug=slugify(name),
            gogid=gog_game["id"],
            gogslug=gog_game["slug"],
            is_public=True
        )
    except IntegrityError:
        LOGGER.warning("Game %s is already in Lutris!", slugify(name))
        game = Game.objects.get(slug=slugify(name))
        game.gogid = gog_game["id"]
        game.gogslug = gog_game["slug"]
    game.set_logo_from_gog(gog_game)
    if gog_game["worksOn"]["Linux"]:
        platform = Platform.objects.get(slug='linux')
    else:
        platform = Platform.objects.get(slug='windows')
    game.platforms.add(platform)
    for gog_genre in gog_game["genres"]:
        genre, created = Genre.objects.get_or_create(slug=slugify(gog_genre))
        if created:
            genre.name = gog_genre
            LOGGER.info("Created genre %s", genre.name)
            genre.save()
        game.genres.add(genre)

    if gog_game["releaseDate"]:
        release_date = datetime.fromtimestamp(gog_game["releaseDate"])
        game.year = release_date.year

    game.save()
    return game
예제 #18
0
    def clean_name(self):
        name = self.cleaned_data["name"]
        slug = slugify(name)[:50]

        try:
            game = models.Game.objects.get(slug=slug)
        except models.Game.DoesNotExist:
            return name
        else:
            if game.is_public:
                msg = ("This game is <a href='games/%s'>already in our "
                       "database</a>.") % slug
            else:
                msg = ("This game has <a href='games/%s'>already been "
                       "submitted</a>, you're welcome to nag us so we "
                       "publish it faster.") % slug
            raise forms.ValidationError(mark_safe(msg))
예제 #19
0
 def save(
         self, force_insert=False, force_update=False, using=None, update_fields=None
 ):
     # Only create slug etc. if this is a game submission, no change submission
     if not self.change_for:
         if not self.slug:
             self.slug = slugify(self.name)[:50]
         if not self.slug:
             raise ValueError("Can't generate a slug for name %s" % self.name)
         self.set_logo_from_steam()
         self.check_for_submission()
     return super(Game, self).save(
         force_insert=force_insert,
         force_update=force_update,
         using=using,
         update_fields=update_fields,
     )
예제 #20
0
파일: steam.py 프로젝트: yuhan963/website
def create_game(game):
    """ Create game object from Steam API call """
    from games.models import Game
    slug = slugify(game['name'])[:50]
    LOGGER.info("Adding %s to library" % game['name'])
    steam_game = Game(
        name=game['name'],
        steamid=game['appid'],
        slug=slug,
    )
    if game['img_logo_url']:
        steam_game.get_steam_logo(game['img_logo_url'])
    steam_game.get_steam_icon(game['img_icon_url'])
    try:
        steam_game.save()
    except Exception as ex:
        LOGGER.error("Error while saving game %s: %s", game, ex)
        raise
    return steam_game
예제 #21
0
파일: forms.py 프로젝트: lutris/website
    def clean_name(self):
        name = self.cleaned_data["name"]
        slug = slugify(name)[:50]

        try:
            game = models.Game.objects.get(slug=slug)
        except models.Game.DoesNotExist:
            return name
        else:
            if game.is_public:
                msg = (
                    "This game is <a href='games/%s'>already in our " "database</a>."
                ) % slug
            else:
                msg = (
                    "This game has <a href='games/%s'>already been "
                    "submitted</a>, you're welcome to nag us so we "
                    "publish it faster."
                ) % slug
            raise forms.ValidationError(mark_safe(msg))
예제 #22
0
 def handle(self, *args, **options):
     platform_slugs = ['linux', 'windows']
     platforms = {
         slug: Platform.objects.get(slug=slug)
         for slug in platform_slugs
     }
     for game in models.ProviderGame.objects.filter(provider__name="GOGDB"):
         product_type = game.metadata.get("product_type")
         if product_type != "Game":
             print("Skipping content type %s for %s" % (product_type, game))
             continue
         match = self.find_match(game)
         if not match and options.get("create_missing"):
             gog_year = self.get_year(game)
             publisher_slug = slugify(game.metadata.get("publisher", ""))
             if publisher_slug:
                 publisher, created = Company.objects.get_or_create(
                     slug=publisher_slug)
                 if created:
                     publisher.name = game.metadata["publisher"]
                     publisher.save()
             else:
                 publisher = None
             supported_systems = game.metadata.get("supported_systems",
                                                   "").split(",")
             lutris_game = Game.objects.create(name=game.name,
                                               slug=get_auto_increment_slug(
                                                   Game, None, game.name),
                                               year=gog_year,
                                               publisher=publisher,
                                               is_public=True,
                                               gogid=game.slug)
             for system in supported_systems:
                 try:
                     lutris_game.platforms.add(platforms[system])
                 except KeyError:
                     pass
             lutris_game.provider_games.add(game)
             print("Created %s" % lutris_game)
         elif not match:
             print("No match found for %s" % game.metadata)
예제 #23
0
파일: steam.py 프로젝트: lutris/website
def create_game(game):
    """ Create game object from Steam API call """
    appid = game['appid']
    from games.models import Game
    slug = slugify(game['name'])[:50]
    LOGGER.info("Adding %s to library", game['name'])
    steam_game = Game(
        name=game['name'],
        steamid=appid,
        slug=slug,
    )

    if game.get('img_logo_url'):
        steam_game.set_logo_from_steam_api(game['img_logo_url'])

    if game.get('img_icon_url'):
        steam_game.set_icon_from_steam_api(game['img_icon_url'])
    try:
        steam_game.save()
    except Exception as ex:
        LOGGER.error("Error while saving game %s: %s", game, ex)
        raise
    return steam_game
예제 #24
0
파일: factories.py 프로젝트: lutris/website
 def set_slug(self, create, extracted, **kwargs):
     if not create:
         return
     self.slug = slugify(self.name)
예제 #25
0
파일: models.py 프로젝트: lutris/website
 def save(self, force_insert=False, force_update=False, using=False,
          update_fields=False):
     self.slug = slugify(self.title)
     return super(News, self).save(force_insert=force_insert, force_update=force_insert,
                                   using=using, update_fields=update_fields)
예제 #26
0
 def set_slug(self, create, extracted, **kwargs):
     if not create:
         return
     self.slug = slugify(self.name)
예제 #27
0
 def build_slug(self, version):
     """Generate a slug that will prevent clashes with other installers"""
     slug = "%s-%s" % (slugify(self.game.name)[:29], slugify(version)[:20])
     return get_auto_increment_slug(self.__class__, self, slug)
예제 #28
0
 def build_slug(self, version):
     slug = "%s-%s" % (slugify(self.game.name)[:29], slugify(version)[:20])
     return get_auto_increment_slug(self.__class__, self, slug)