Ejemplo n.º 1
0
    def __init__(self,
                 config_override=None,
                 consoles_override=None,
                 emulators_override=None):
        self.validated_base_environment = False
        self.validated_configuration = False
        self.logger = IceLogger()
        self.logger.debug("Initializing Ice")
        config_data_path = _path_with_override(config_override, "config.txt")
        consoles_data_path = _path_with_override(consoles_override,
                                                 "consoles.txt")
        emulators_data_path = _path_with_override(emulators_override,
                                                  "emulators.txt")
        self.config = Configuration(
            ConfigFileBackingStore(config_data_path),
            ConfigFileBackingStore(consoles_data_path),
            ConfigFileBackingStore(emulators_data_path),
        )
        self.steam = Steam()
        # TODO: Query the list of users some other way
        self.users = self.steam.local_users()

        filesystem = Filesystem()
        parser = ROMParser(self.logger)
        self.rom_finder = ROMFinder(self.config, filesystem, parser)
        archive_data_path = Configuration.path_for_data_file("archive.json")
        managed_rom_archive = ManagedROMArchive(archive_data_path)
        self.shortcut_synchronizer = SteamShortcutSynchronizer(
            managed_rom_archive, self.logger)

        provider = CombinedProvider(
            LocalProvider(self.logger),
            ConsoleGridProvider(self.logger),
        )
        self.grid_updater = SteamGridUpdater(provider, self.logger)
Ejemplo n.º 2
0
 def test_config_file_backing_store_can_read_saved_file(self):
     cfbs = ConfigFileBackingStore(self.tempfile)
     cfbs.add_identifier("Iron Man")
     cfbs.set("Iron Man", "alignment", "good")
     cfbs.add_identifier("Whiplash")
     cfbs.set("Whiplash", "alignment", "evil")
     cfbs.save()
     new_cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertIn("Iron Man", new_cfbs.identifiers())
     self.assertIn("Whiplash", new_cfbs.identifiers())
     self.assertEqual("good", new_cfbs.get("Iron Man", "alignment"))
     self.assertEqual("evil", new_cfbs.get("Whiplash", "alignment"))
Ejemplo n.º 3
0
 def test_save_creates_new_file_when_path_originally_dne(self):
     self.assertFalse(os.path.isfile(self.tempfile))
     cfbs = ConfigFileBackingStore(self.tempfile)
     cfbs.add_identifier("Iron Man")
     cfbs.set("Iron Man", "identity", "Tony Stark")
     cfbs.save()
     self.assertTrue(os.path.isfile(self.tempfile))
 def test_identifiers(self):
     self.create_config_file(self.tempfile, {
         "Iron Man": {},
         "Whiplash": {},
     })
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertEquals(cfbs.identifiers(), ["Iron Man", "Whiplash"])
Ejemplo n.º 5
0
 def test_save_raises_ioerror_when_cant_make_new_file(self):
     temppath = os.path.join(self.tempdir, "extra", "directories",
                             "test.ini")
     cfbs = ConfigFileBackingStore(temppath)
     cfbs.add_identifier("Iron Man")
     cfbs.set("Iron Man", "identity", "Tony Stark")
     with self.assertRaises(IOError):
         cfbs.save()
Ejemplo n.º 6
0
 def _load_roms_for_test(self, directory):
   """Takes the ROMs located in `directory/ROMs` and moves them into the
   ROMs directory specified in the provided config.txt file."""
   config_path = self._test_config_path(directory, 'config')
   c = configuration.from_store(ConfigFileBackingStore(config_path))
   target_roms_directory = self.sandbox.adjusted_path(c.roms_directory)
   source_roms_directory = os.path.join(directory, 'ROMs')
   shutil.copytree(source_roms_directory, target_roms_directory)
Ejemplo n.º 7
0
 def test_get_keys_are_case_insensitive(self):
     self.create_config_file(
         self.tempfile,
         {"Iron Man": {
             "identity": "Tony Stark",
             "alignment": "good",
         }})
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertEqual(cfbs.get("Iron Man", "IDENTITY", ""), "Tony Stark")
Ejemplo n.º 8
0
 def test_get(self):
     self.create_config_file(
         self.tempfile,
         {"Iron Man": {
             "identity": "Tony Stark",
             "alignment": "good",
         }})
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertEqual(cfbs.get("Iron Man", "identity", ""), "Tony Stark")
Ejemplo n.º 9
0
 def test_raises_ioerror_when_permission_denied(self):
     self.create_config_file(self.tempfile, {})
     mode = os.stat(self.tempfile)[stat.ST_MODE]
     new_mode = mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH
     os.chmod(self.tempfile, new_mode)
     cfbs = ConfigFileBackingStore(self.tempfile)
     cfbs.add_identifier("Iron Man")
     cfbs.set("Iron Man", "identity", "Tony Stark")
     with self.assertRaises(IOError):
         cfbs.save()
Ejemplo n.º 10
0
    def __init__(self, options):
        """Valid options for creating an IceEngine are as follows:

    * config    - The path to the config file to use. Searches the default paths
                  for 'config.txt' otherwise
    * consoles  - The path to the consoles file to use. Searches the default
                  paths for 'consoles.txt' if none is provided
    * emulators - The path to the emulators file to use. Searches the default
                  paths for 'emulators.txt' if none is provided
    * verbose   - Turn on debug logging.
    """
        self.validated_base_environment = False
        self.validated_configuration = False
        self.logger = IceLogger(verbose=options.verbose)
        self.logger.debug("Initializing Ice")
        config_data_path = _path_with_override(options.config, "config.txt")
        consoles_data_path = _path_with_override(options.consoles,
                                                 "consoles.txt")
        emulators_data_path = _path_with_override(options.emulators,
                                                  "emulators.txt")
        self.config = Configuration(
            ConfigFileBackingStore(config_data_path),
            ConfigFileBackingStore(consoles_data_path),
            ConfigFileBackingStore(emulators_data_path),
        )
        self.steam = Steam()
        # TODO: Query the list of users some other way
        self.users = self.steam.local_users()

        filesystem = Filesystem()
        parser = ROMParser(self.logger)
        self.rom_finder = ROMFinder(self.config, filesystem, parser)
        archive_data_path = Configuration.path_for_data_file("archive.json")
        managed_rom_archive = ManagedROMArchive(archive_data_path)
        self.shortcut_synchronizer = SteamShortcutSynchronizer(
            managed_rom_archive, self.logger)

        provider = CombinedProvider(
            LocalProvider(self.logger),
            ConsoleGridProvider(self.logger),
        )
        self.grid_updater = SteamGridUpdater(provider, self.logger)
Ejemplo n.º 11
0
    def __init__(self, steam, filesystem, options):
        """Valid options for creating an IceEngine are as follows:

    * config    - The path to the config file to use. Searches the default paths
                  for 'config.txt' otherwise
    * consoles  - The path to the consoles file to use. Searches the default
                  paths for 'consoles.txt' if none is provided
    * emulators - The path to the emulators file to use. Searches the default
                  paths for 'emulators.txt' if none is provided
    """
        self.validated_base_environment = False
        self.validated_configuration = False
        self.filesystem = filesystem
        logger.debug("Initializing Ice")
        config_data_path = _path_with_override(filesystem, options.config,
                                               "config.txt")
        consoles_data_path = _path_with_override(filesystem, options.consoles,
                                                 "consoles.txt")
        emulators_data_path = _path_with_override(filesystem,
                                                  options.emulators,
                                                  "emulators.txt")
        self.config = Configuration(
            ConfigFileBackingStore(config_data_path),
            ConfigFileBackingStore(consoles_data_path),
            ConfigFileBackingStore(emulators_data_path),
            filesystem,
        )
        self.steam = steam

        parser = ROMParser()
        self.rom_finder = ROMFinder(self.config, filesystem, parser)
        archive_data_path = paths.highest_precedent_data_file(
            filesystem, "archive.json")
        managed_rom_archive = ManagedROMArchive(archive_data_path)
        self.shortcut_synchronizer = SteamShortcutSynchronizer(
            managed_rom_archive)

        provider = CombinedProvider(
            LocalProvider(),
            ConsoleGridProvider(),
        )
        self.grid_updater = SteamGridUpdater(provider)
Ejemplo n.º 12
0
 def _load_roms_for_test(self, directory):
     """Takes the ROMs located in `directory/ROMs` and moves them into the
 ROMs directory specified in the provided config.txt file."""
     # TODO: This is extremely non-kosher. The fact that I have to do this
     # suggests that something is very wrong with my Configuration object.
     #
     # Knowing that object I'm tempted to agree.
     c = Configuration(
         ConfigFileBackingStore(self._test_config_path(directory,
                                                       'config')),
         None,
         None,
         None,
     )
     target_roms_directory = self.sandbox.adjusted_path(c.roms_directory())
     source_roms_directory = os.path.join(directory, 'ROMs')
     shutil.copytree(source_roms_directory, target_roms_directory)
Ejemplo n.º 13
0
 def test_save_modifies_contents_of_file(self):
     self.create_config_file(self.tempfile,
                             {"Iron Man": {
                                 "identity": "Tony Stark"
                             }})
     old_contents = self.file_contents(self.tempfile)
     cfbs = ConfigFileBackingStore(self.tempfile)
     cfbs.set("Iron Man", "alignment", "good")
     cfbs.add_identifier("Whiplash")
     cfbs.set("Whiplash", "alignment", "evil")
     cfbs.save()
     new_contents = self.file_contents(self.tempfile)
     self.assertNotIn("Whiplash", old_contents)
     self.assertIn("Whiplash", new_contents)
     self.assertNotIn("alignment", old_contents)
     self.assertIn("alignment", new_contents)
     self.assertIn("good", new_contents)
     self.assertIn("evil", new_contents)
Ejemplo n.º 14
0
 def test_get_returns_empty_string_when_value_is_emptry_string(self):
     self.create_config_file(self.tempfile, {"Iron Man": {"identity": ""}})
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertEqual(cfbs.get("Iron Man", "identity", "Unknown"), "")
Ejemplo n.º 15
0
 def test_remove_identifier_does_nothing_when_identifer_dne(self):
     self.create_config_file(self.tempfile, {})
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertNotIn("Iron Man", cfbs.identifiers())
     cfbs.remove_identifier("Iron Man")
     self.assertNotIn("Iron Man", cfbs.identifiers())
Ejemplo n.º 16
0
 def test_add_identifier_raises_valueerror_when_identifier_exists(self):
     self.create_config_file(self.tempfile, {"Iron Man": {}})
     cfbs = ConfigFileBackingStore(self.tempfile)
     with self.assertRaises(ValueError):
         cfbs.add_identifier("Iron Man")
Ejemplo n.º 17
0
 def test_removed_identifiers_dont_show_up_in_subsequent_calls(self):
     self.create_config_file(self.tempfile, {"Iron Man": {}})
     cfbs = ConfigFileBackingStore(self.tempfile)
     cfbs.remove_identifier("Iron Man")
     self.assertNotIn("Iron Man", cfbs.identifiers())
Ejemplo n.º 18
0
 def test_added_identifiers_show_up_in_subsequent_calls(self):
     self.create_config_file(self.tempfile, {})
     cfbs = ConfigFileBackingStore(self.tempfile)
     cfbs.add_identifier("Iron Man")
     self.assertIn("Iron Man", cfbs.identifiers())
Ejemplo n.º 19
0
 def test_empty_file(self):
     self.create_config_file(self.tempfile, {})
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertEqual(cfbs.identifiers(), [])
Ejemplo n.º 20
0
 def test_get_returns_default_when_section_dne(self):
     self.create_config_file(self.tempfile, {"Iron Man": {}})
     cfbs = ConfigFileBackingStore(self.tempfile)
     self.assertEqual(cfbs.get("Superman", "identity", "Unknown"),
                      "Unknown")
Ejemplo n.º 21
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.tempfile = os.path.join(self.tempdir, "test.ini")
     self.backing_store = ConfigFileBackingStore(self.tempfile)
     self.manager = BackedObjectManager(self.backing_store,
                                        BackedObjectBackedObjectAdapter())
Ejemplo n.º 22
0
 def test_keys_raises_valueerror_when_section_dne(self):
     self.create_config_file(self.tempfile, {})
     cfbs = ConfigFileBackingStore(self.tempfile)
     with self.assertRaises(ValueError):
         cfbs.keys("Iron Man")