示例#1
0
    def sync_roms_for_user(self, user, users_roms, consoles, dry_run=False):
        """
    This function takes care of syncing ROMs. After this function exits,
    Steam will contain only non-Ice shortcuts and the ROMs represented
    by `roms`.
    """
        # 'Unmanaged' is just the term I am using for shortcuts that the user has
        # added that Ice shouldn't delete. For example, something like a shortcut
        # to Plex would be 'Unmanaged'
        previous_managed_ids = self.managed_rom_archive.previous_managed_ids(
            user)
        logger.debug("Previous managed ids: %s" % previous_managed_ids)
        current_shortcuts = shortcuts.get_shortcuts(user)
        current_shortcuts = [x for x in current_shortcuts if x is not None]
        unmanaged_shortcuts = self.unmanaged_shortcuts(previous_managed_ids,
                                                       current_shortcuts,
                                                       consoles)
        logger.debug("Unmanaged shortcuts: %s" % unmanaged_shortcuts)
        current_ice_shortcuts = filter(
            lambda shortcut: shortcut not in unmanaged_shortcuts,
            current_shortcuts)
        logger.debug("Current Ice shortcuts: %s" % current_ice_shortcuts)
        # Generate a list of shortcuts out of our list of ROMs
        rom_shortcuts = map(roms.rom_to_shortcut, users_roms)
        # Calculate which ROMs were added and which were removed so we can inform
        # the user
        removed = self.removed_shortcuts(current_ice_shortcuts, rom_shortcuts)
        map(lambda shortcut: logger.info("Removing ROM: `%s`" % shortcut.name),
            removed)
        added = self.added_shortcuts(current_ice_shortcuts, rom_shortcuts)
        map(lambda shortcut: logger.info("Adding ROM: `%s`" % shortcut.name),
            added)

        # Set the updated shortcuts
        updated_shortcuts = unmanaged_shortcuts + rom_shortcuts
        logger.debug("Sync Result: %s" % updated_shortcuts)

        if dry_run:
            logger.debug("Not saving or updating history due to dry run")
            return

        logger.debug("Saving shortcuts")
        shortcuts.set_shortcuts(user, updated_shortcuts)

        # Update the archive
        new_managed_ids = map(shortcuts.shortcut_app_id, rom_shortcuts)
        logger.debug("Updating archive to ids: %s" % new_managed_ids)
        self.managed_rom_archive.set_managed_ids(user, new_managed_ids)
示例#2
0
    def test_get_and_set_shortcuts_creates_file_at_correct_path(self):
        tempdir = tempfile.mkdtemp()

        steam = model.Steam(tempdir)
        context = model.LocalUserContext(steam=steam, user_id='anonymous')
        # Create the `anonymous` directory, cause we can't open shortcuts.vdf for
        # writing if the containing directory doesn't exist
        os.makedirs(paths.user_config_directory(context))

        self.assertFalse(os.path.exists(paths.shortcuts_path(context)))
        self.assertEqual([], shortcuts.get_shortcuts(context))

        updated_shortcuts = [_dummy_shortcut()]
        shortcuts.set_shortcuts(context, updated_shortcuts)
        self.assertEqual(updated_shortcuts, shortcuts.get_shortcuts(context))

        shutil.rmtree(tempdir)
示例#3
0
  def test_create_backup_of_shortcuts_creates_copy_of_shortcuts_at_backup_path(self):
    tempdir = tempfile.mkdtemp()
    backup_dir = os.path.join(tempdir, "Backups")

    config = mock()
    config.backup_directory = backup_dir

    user = self.user_fixture.get_context()

    shortcut = model.Shortcut('Plex', '/Path/to/plex', '/Path/to', '', '', '', False, False, False, 0, [])
    user_shortcuts = [shortcut]

    shortcuts.set_shortcuts(user, user_shortcuts)
    backups.create_backup_of_shortcuts(config, user)

    expected_path = backups.shortcuts_backup_path(backup_dir, user)
    self.assertTrue(os.path.exists(expected_path))
    self.assertEqual(shortcuts.read_shortcuts(expected_path), user_shortcuts)

    shutil.rmtree(tempdir)
示例#4
0
 def set_user_shortcuts(self, uid, new_shortcuts):
   context = model.LocalUserContext(self.steam_fixture.get_steam(), uid)
   return shortcuts.set_shortcuts(context, new_shortcuts)
示例#5
0
 def _set_users_shortcuts(self, users_shortcuts):
     shortcuts.set_shortcuts(self.user_fixture.get_context(),
                             users_shortcuts)