Esempio n. 1
0
    def test_updater_keeps_image_if_already_exists(self):
        rom = model.ROM(name='Game1',
                        path='/Path/to/game1',
                        console=fixtures.consoles.flagged)
        shortcut = roms.rom_to_shortcut(rom)

        # Start with a custom image, say a .png
        (handle, path) = tempfile.mkstemp('.png')
        grid.set_custom_image(self.user_fixture.get_context(),
                              shortcuts.shortcut_app_id(shortcut), path)
        os.remove(path)

        # Make the provider return a .jpg
        (handle, path) = tempfile.mkstemp('.jpg')
        when(self.mock_provider).image_for_rom(rom).thenReturn(path)

        self.assertTrue(
            grid.has_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))
        self.updater.update_rom_artwork(self.user_fixture.get_context(), rom)
        self.assertTrue(
            grid.has_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))

        # Ensure that we are still using the .png, not the .jpg
        (_, ext) = os.path.splitext(
            grid.get_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))
        self.assertEqual(ext, '.png')
    def test_updater_does_nothing_if_provider_has_no_image(self):
        rom = model.ROM(name="Game1", path="/Path/to/game1", console=fixtures.consoles.flagged)
        shortcut = roms.rom_to_shortcut(rom)

        when(self.mock_provider).image_for_rom(rom).thenReturn(None)

        self.assertFalse(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))
        self.updater.update_rom_artwork(self.user_fixture.get_context(), rom)

        self.assertFalse(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))
    def test_updater_sets_image_if_provider_has_one(self):
        rom = model.ROM(name="Game1", path="/Path/to/game1", console=fixtures.consoles.flagged)
        shortcut = roms.rom_to_shortcut(rom)

        (handle, path) = tempfile.mkstemp(".png")
        when(self.mock_provider).image_for_rom(rom).thenReturn(path)

        self.assertFalse(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))
        self.updater.update_rom_artwork(self.user_fixture.get_context(), rom)
        self.assertTrue(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))

        os.remove(path)
Esempio n. 4
0
    def update_rom_artwork(self, user, rom, dry_run=False):
        shortcut = roms.rom_to_shortcut(rom)
        logger.debug("Updating image for %s (%s)" % (rom, shortcut))
        app_id = shortcuts.shortcut_app_id(shortcut)

        if grid.has_custom_image(user, app_id):
            existing_image = grid.get_custom_image(user, app_id)
            logger.debug(
                "Not looking for new images for %s, it already has a grid image (%s)"
                % (shortcut.name, existing_image)
            )
            return

        path = self.provider.image_for_rom(rom)

        if path is None:
            logger.info("No image found for `%s`" % shortcut.name)
            return

        if dry_run:
            logger.debug("Found image, but not setting because its a dry run")
            return

        logger.info("Found grid image for `%s`" % shortcut.name)
        grid.set_custom_image(user, app_id, path)
 def test_unmanaged_shortcuts_doesnt_return_shortcut_with_appid_in_managed_ids(self):
   managed_shortcut = steam_model.Shortcut("Game", "/Path/to/game", "/Path/to", "", [])
   random_shortcut = steam_model.Shortcut("Plex", "/Some/Random/Path/plex", "/Some/Random/Path", "", [])
   managed_ids = [shortcuts.shortcut_app_id(managed_shortcut)]
   all_shortcuts = [managed_shortcut, random_shortcut]
   unmanaged = self.synchronizer.unmanaged_shortcuts(managed_ids, all_shortcuts, None)
   self.assertEquals(unmanaged, [random_shortcut])
Esempio n. 6
0
    def test_updater_does_nothing_if_provider_has_no_image(self):
        rom = model.ROM(name='Game1',
                        path='/Path/to/game1',
                        console=fixtures.consoles.flagged)
        shortcut = roms.rom_to_shortcut(rom)

        when(self.mock_provider).image_for_rom(rom).thenReturn(None)

        self.assertFalse(
            grid.has_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))
        self.updater.update_rom_artwork(self.user_fixture.get_context(), rom)

        self.assertFalse(
            grid.has_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))
Esempio n. 7
0
    def test_updater_sets_image_if_provider_has_one(self):
        rom = model.ROM(name='Game1',
                        path='/Path/to/game1',
                        console=fixtures.consoles.flagged)
        shortcut = roms.rom_to_shortcut(rom)

        (handle, path) = tempfile.mkstemp('.png')
        when(self.mock_provider).image_for_rom(rom).thenReturn(path)

        self.assertFalse(
            grid.has_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))
        self.updater.update_rom_artwork(self.user_fixture.get_context(), rom)
        self.assertTrue(
            grid.has_custom_image(self.user_fixture.get_context(),
                                  shortcuts.shortcut_app_id(shortcut)))

        os.remove(path)
Esempio n. 8
0
 def test_unmanaged_shortcuts_doesnt_return_shortcut_with_appid_in_managed_ids(
         self):
     managed_shortcut = steam_model.Shortcut("Game", "/Path/to/game",
                                             "/Path/to", "", [])
     random_shortcut = steam_model.Shortcut("Plex",
                                            "/Some/Random/Path/plex",
                                            "/Some/Random/Path", "", [])
     managed_ids = [shortcuts.shortcut_app_id(managed_shortcut)]
     all_shortcuts = [managed_shortcut, random_shortcut]
     unmanaged = self.synchronizer.unmanaged_shortcuts(
         managed_ids, all_shortcuts, None)
     self.assertEquals(unmanaged, [random_shortcut])
    def test_updater_keeps_image_if_already_exists(self):
        rom = model.ROM(name="Game1", path="/Path/to/game1", console=fixtures.consoles.flagged)
        shortcut = roms.rom_to_shortcut(rom)

        # Start with a custom image, say a .png
        (handle, path) = tempfile.mkstemp(".png")
        grid.set_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut), path)
        os.remove(path)

        # Make the provider return a .jpg
        (handle, path) = tempfile.mkstemp(".jpg")
        when(self.mock_provider).image_for_rom(rom).thenReturn(path)

        self.assertTrue(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))
        self.updater.update_rom_artwork(self.user_fixture.get_context(), rom)
        self.assertTrue(grid.has_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut)))

        # Ensure that we are still using the .png, not the .jpg
        (_, ext) = os.path.splitext(
            grid.get_custom_image(self.user_fixture.get_context(), shortcuts.shortcut_app_id(shortcut))
        )
        self.assertEqual(ext, ".png")
Esempio n. 10
0
  def update_rom_artwork(self, user, rom, dry_run=False):
    shortcut = roms.rom_to_shortcut(rom)
    logger.debug("Updating image for %s (%s)" % (rom, shortcut))
    app_id = shortcuts.shortcut_app_id(shortcut)

    if grid.has_custom_image(user, app_id):
      existing_image = grid.get_custom_image(user, app_id)
      logger.debug("Not looking for new images for %s, it already has a grid image (%s)" % (shortcut.name, existing_image))
      return

    path = self.provider.image_for_rom(rom)

    if path is None:
      logger.info("No image found for `%s`" % shortcut.name)
      return

    if dry_run:
      logger.debug("Found image, but not setting because its a dry run")
      return

    logger.info("Found grid image for `%s`" % shortcut.name)
    grid.set_custom_image(user, app_id, path)
 def shortcut_is_managed_by_ice(self, managed_ids, shortcut, configuration):
   # LEGACY: At one point I added ICE_FLAG_TAG to every shortcut Ice made.
   # That was a terrible idea, the managed_ids is a much better system. I
   # keep this check around for legacy reasons though.
   if roms.ICE_FLAG_TAG in shortcut.tags:
     return True
   # LEGACY: For most of Ice's life it guessed whether it managed a shortcut
   # or not. This was REALLY bad, as it was very dependent on configuration
   # and caused really strange bugs where moving directories would cause ROMs
   # to get duplicated and all sorts of bad stuff.
   #
   # Luckily, we have a history now and don't have to deal with that crap.
   # Yay! Except that this screws over anyone who used Ice //before// it had
   # a history, as we have no record of what they added before. Shit.
   #
   # To fix this, we provide a migration path for these people. If we have NO
   # history (not an empty history, NO history) then we fall back to our old
   # way of checking whether we manage the shortcut. The next time Ice is run
   # we will have a history to work with and can avoid using this hacky garbage.
   if managed_ids is None:
     return self._guess_whether_shortcut_is_managed_by_ice(shortcut, configuration)
   # We only 'manage' it if we added the shortcut in the last run
   return shortcuts.shortcut_app_id(shortcut) in managed_ids
 def shortcut_is_managed_by_ice(self, managed_ids, shortcut, consoles):
     # LEGACY: At one point I added ICE_FLAG_TAG to every shortcut Ice made.
     # That was a terrible idea, the managed_ids is a much better system. I
     # keep this check around for legacy reasons though.
     if roms.ICE_FLAG_TAG in shortcut.tags:
         return True
     # LEGACY: For most of Ice's life it guessed whether it managed a shortcut
     # or not. This was REALLY bad, as it was very dependent on configuration
     # and caused really strange bugs where moving directories would cause ROMs
     # to get duplicated and all sorts of bad stuff.
     #
     # Luckily, we have a history now and don't have to deal with that crap.
     # Yay! Except that this screws over anyone who used Ice //before// it had
     # a history, as we have no record of what they added before. Shit.
     #
     # To fix this, we provide a migration path for these people. If we have NO
     # history (not an empty history, NO history) then we fall back to our old
     # way of checking whether we manage the shortcut. The next time Ice is run
     # we will have a history to work with and can avoid using this hacky garbage.
     if managed_ids is None:
         return self._guess_whether_shortcut_is_managed_by_ice(
             shortcut, consoles)
     # We only 'manage' it if we added the shortcut in the last run
     return shortcuts.shortcut_app_id(shortcut) in managed_ids
Esempio n. 13
0
 def test_appid_generation(self, name, exe, expected):
     """Tests that pysteam generates the correct appid hash for shortcuts."""
     s = model.Shortcut(name, exe, "", "", None)
     self.assertEqual(shortcuts.shortcut_app_id(s), expected)
Esempio n. 14
0
 def test_appid_generation(self, name, exe, expected):
   """Tests that pysteam generates the correct appid hash for shortcuts."""
   s = model.Shortcut(name, exe, "", "", None)
   self.assertEqual(shortcuts.shortcut_app_id(s), expected)