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 __init__(self):
    self.validated_base_environment = False
    self.validated_configuration = False
    self.logger = IceLogger()
    self.logger.debug("Initializing Ice")
    config_data_path = Configuration.path_for_data_file("config.txt")
    consoles_data_path = Configuration.path_for_data_file("consoles.txt")
    emulators_data_path = Configuration.path_for_data_file("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.º 3
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, 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.º 4
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.º 5
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.º 6
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.º 7
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
    * verbose   - Turn on debug logging.
    """
    self.validated_base_environment = False
    self.validated_configuration = False
    self.filesystem = filesystem
    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.logger,
        filesystem,
    )
    self.steam = steam

    parser = ROMParser(self.logger)
    self.rom_finder = ROMFinder(self.logger, 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.º 8
0
 def validate_base_environment(self):
   """
   Validate that the current environment meets all of Ice's requirements.
   """
   if self.validated_base_environment:
     return
   with EnvironmentChecker() as env_checker:
     # If Steam is running then any changes we make will be overwritten
     env_checker.require_program_not_running("Steam")
     # I'm not sure if there are situations where this won't exist, but I
     # assume that it does everywhere and better safe than sorry
     env_checker.require_directory_exists(self.steam.userdata_location())
     # This is used to store history information and such
     env_checker.require_directory_exists(Configuration.data_directory())
   self.validated_base_environment = True
Ejemplo n.º 9
0
 def validate_base_environment(self):
     """
 Validate that the current environment meets all of Ice's requirements.
 """
     if self.validated_base_environment:
         return
     with EnvironmentChecker() as env_checker:
         # If Steam is running then any changes we make will be overwritten
         env_checker.require_program_not_running("Steam")
         # I'm not sure if there are situations where this won't exist, but I
         # assume that it does everywhere and better safe than sorry
         env_checker.require_directory_exists(
             self.steam.userdata_location())
         # This is used to store history information and such
         env_checker.require_directory_exists(
             Configuration.data_directory())
     self.validated_base_environment = True
Ejemplo n.º 10
0
class IceEngine(object):
    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)

    def validate_base_environment(self):
        """
    Validate that the current environment meets all of Ice's requirements.
    """
        if self.validated_base_environment:
            return
        with EnvironmentChecker() as env_checker:
            # If Steam is running then any changes we make will be overwritten
            env_checker.require_program_not_running("Steam")
            # I'm not sure if there are situations where this won't exist, but I
            # assume that it does everywhere and better safe than sorry
            env_checker.require_directory_exists(
                self.steam.userdata_location())
            # This is used to store history information and such
            env_checker.require_directory_exists(
                Configuration.data_directory())
        self.validated_base_environment = True

    def validate_configuration(self, configuration):
        if self.validated_configuration:
            return
        with EnvironmentChecker() as env_checker:
            for console in configuration.console_manager:
                if console.is_enabled():
                    # Consoles assume they have a ROMs directory
                    env_checker.require_directory_exists(
                        configuration.roms_directory_for_console(console))
        self.validated_configuration = True

    def validate_user_environment(self, user):
        """
    Validate that the current environment for a given user meets all of
    Ice's requirements.
    """
        with EnvironmentChecker() as env_checker:
            # If the user hasn't added any grid images on their own then this
            # directory wont exist, so we require it explicitly here
            env_checker.require_directory_exists(user.grid_directory())
            # And it needs to be writable if we are going to save images there
            env_checker.require_writable_path(user.grid_directory())

    def main(self):
        self.logger.info("=========== Starting Ice ===========")
        try:
            self.validate_base_environment()
            self.validate_configuration(self.config)
        except EnvCheckerError as e:
            self.logger.info(
                "Ice cannot run because of issues with your system.\n")
            self.logger.info("* %s" % e.message)
            self.logger.info(
                "\nPlease resolve these issues and try running Ice again")
            return
        # TODO: Create any missing directories that Ice will need
        self.logger.log_configuration(self.config)
        for user in self.users:
            self.logger.info("=========== User: %s ===========" %
                             str(user.id32))
            self.run_for_user(user)

    def run_for_user(self, user):
        try:
            self.validate_base_environment()
            self.validate_configuration(self.config)
            self.validate_user_environment(user)
        except EnvCheckerError as e:
            self.logger.info(
                "Ice cannot run because of issues with your system.\n")
            self.logger.info("\t%s\n" % e.message)
            self.logger.info(
                "Please resolve these issues and try running Ice again")
            return
        backup_path = self.config.shortcuts_backup_path(user)
        user.save_shortcuts(backup_path)
        # Find all of the ROMs that are currently in the designated folders
        roms = self.rom_finder.roms_for_consoles(self.config.console_manager)
        self.shortcut_synchronizer.sync_roms_for_user(user, roms, self.config)
        self.grid_updater.update_artwork_for_rom_collection(user, roms)

    def run(self):
        try:
            self.main()
        except Exception as error:
            self.logger.exception("An exception occurred while running Ice")
Ejemplo n.º 11
0
def _path_with_override(path_override, default_name):
    if path_override is not None:
        return path_override
    return Configuration.path_for_data_file(default_name)
Ejemplo n.º 12
0
class IceEngine(object):

  def __init__(self):
    self.validated_base_environment = False
    self.validated_configuration = False
    self.logger = IceLogger()
    self.logger.debug("Initializing Ice")
    config_data_path = Configuration.path_for_data_file("config.txt")
    consoles_data_path = Configuration.path_for_data_file("consoles.txt")
    emulators_data_path = Configuration.path_for_data_file("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)

  def validate_base_environment(self):
    """
    Validate that the current environment meets all of Ice's requirements.
    """
    if self.validated_base_environment:
      return
    with EnvironmentChecker() as env_checker:
      # If Steam is running then any changes we make will be overwritten
      env_checker.require_program_not_running("Steam")
      # I'm not sure if there are situations where this won't exist, but I
      # assume that it does everywhere and better safe than sorry
      env_checker.require_directory_exists(self.steam.userdata_location())
      # This is used to store history information and such
      env_checker.require_directory_exists(Configuration.data_directory())
    self.validated_base_environment = True

  def validate_configuration(self, configuration):
    if self.validated_configuration:
      return
    with EnvironmentChecker() as env_checker:
      for console in configuration.console_manager:
        if console.is_enabled():
          # Consoles assume they have a ROMs directory
          env_checker.require_directory_exists(configuration.roms_directory_for_console(console))
    self.validated_configuration = True

  def validate_user_environment(self, user):
    """
    Validate that the current environment for a given user meets all of
    Ice's requirements.
    """
    with EnvironmentChecker() as env_checker:
      # If the user hasn't added any grid images on their own then this
      # directory wont exist, so we require it explicitly here
      env_checker.require_directory_exists(user.grid_directory())
      # And it needs to be writable if we are going to save images there
      env_checker.require_writable_path(user.grid_directory())

  def main(self):
    self.logger.info("=========== Starting Ice ===========")
    try:
      self.validate_base_environment()
      self.validate_configuration(self.config)
    except EnvCheckerError as e:
      self.logger.info("Ice cannot run because of issues with your system.\n")
      self.logger.info("* %s" % e.message)
      self.logger.info("\nPlease resolve these issues and try running Ice again")
      return
    # TODO: Create any missing directories that Ice will need
    self.logger.log_configuration(self.config)
    for user in self.users:
      self.logger.info("=========== User: %s ===========" % str(user.id32))
      self.run_for_user(user)

  def run_for_user(self, user):
    try:
      self.validate_base_environment()
      self.validate_configuration(self.config)
      self.validate_user_environment(user)
    except EnvCheckerError as e:
      self.logger.info("Ice cannot run because of issues with your system.\n")
      self.logger.info("\t%s\n" % e.message)
      self.logger.info("Please resolve these issues and try running Ice again")
      return
    backup_path = self.config.shortcuts_backup_path(user)
    user.save_shortcuts(backup_path)
    # Find all of the ROMs that are currently in the designated folders
    roms = self.rom_finder.roms_for_consoles(self.config.console_manager)
    self.shortcut_synchronizer.sync_roms_for_user(user, roms)
    self.grid_updater.update_artwork_for_rom_collection(user, roms)

  def run(self):
    try:
      self.main()
    except Exception as error:
      self.logger.exception("An exception occurred while running Ice")
Ejemplo n.º 13
0
class IceEngine(object):
    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)

    def validate_base_environment(self):
        """
    Validate that the current environment meets all of Ice's requirements.
    """
        if self.validated_base_environment:
            return
        with EnvironmentChecker(self.filesystem) as env_checker:
            # If Steam is running then any changes we make will be overwritten
            env_checker.require_program_not_running("Steam")
            # I'm not sure if there are situations where this won't exist, but I
            # assume that it does everywhere and better safe than sorry
            env_checker.require_directory_exists(self.steam.userdata_directory)
            # This is used to store history information and such
            env_checker.require_directory_exists(
                paths.application_data_directory())
        self.validated_base_environment = True

    def validate_configuration(self, configuration):
        if self.validated_configuration:
            return
        with EnvironmentChecker(self.filesystem) as env_checker:
            for console in configuration.console_manager:
                if consoles.console_is_enabled(console):
                    # Consoles assume they have a ROMs directory
                    env_checker.require_directory_exists(
                        consoles.console_roms_directory(
                            configuration, console))
        self.validated_configuration = True

    def validate_user_environment(self, user):
        """
    Validate that the current environment for a given user meets all of
    Ice's requirements.
    """
        with EnvironmentChecker(self.filesystem) as env_checker:
            # If the user hasn't added any grid images on their own then this
            # directory wont exist, so we require it explicitly here
            env_checker.require_directory_exists(
                steam_paths.custom_images_directory(user))
            # And it needs to be writable if we are going to save images there
            env_checker.require_writable_path(
                steam_paths.custom_images_directory(user))

    def main(self, dry_run=False):
        if self.steam is None:
            logger.error(
                "Cannot run Ice because Steam doesn't appear to be installed")
            return

        logger.info("=========== Starting Ice ===========")
        try:
            self.validate_base_environment()
            self.validate_configuration(self.config)
        except EnvCheckerError as e:
            logger.info("Ice cannot run because of issues with your system.\n")
            logger.info("* %s" % e.message)
            logger.info(
                "\nPlease resolve these issues and try running Ice again")
            return
        # TODO: Create any missing directories that Ice will need
        log_configuration(self.config)
        for user_context in steam.local_user_contexts(self.steam):
            logger.info("=========== User: %s ===========" %
                        str(user_context.user_id))
            self.run_for_user(user_context, dry_run=dry_run)

    def run_for_user(self, user, dry_run=False):
        try:
            self.validate_base_environment()
            self.validate_configuration(self.config)
            self.validate_user_environment(user)
        except EnvCheckerError as e:
            logger.info("Ice cannot run because of issues with your system.\n")
            logger.info("\t%s\n" % e.message)
            logger.info(
                "Please resolve these issues and try running Ice again")
            return
        self._create_backup(user, dry_run=dry_run)
        # Find all of the ROMs that are currently in the designated folders
        roms = self.rom_finder.roms_for_consoles(self.config.console_manager)
        self.shortcut_synchronizer.sync_roms_for_user(user,
                                                      roms,
                                                      self.config,
                                                      dry_run=dry_run)
        self.grid_updater.update_artwork_for_rom_collection(user,
                                                            roms,
                                                            dry_run=dry_run)

    def run(self, dry_run=False):
        try:
            self.main(dry_run=dry_run)
        except Exception as error:
            logger.exception("An exception occurred while running Ice")

    def _create_backup(self, user, dry_run=False):
        if dry_run:
            logger.debug("Not creating backup because its a dry run")
            return

        backup_path = self.config.shortcuts_backup_path(user)
        if backup_path is None:
            logger.info(
                "No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info"
            )
            return

        shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
Ejemplo n.º 14
0
class IceEngine(object):

  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
    * verbose   - Turn on debug logging.
    """
    self.validated_base_environment = False
    self.validated_configuration = False
    self.filesystem = filesystem
    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.logger,
        filesystem,
    )
    self.steam = steam

    parser = ROMParser(self.logger)
    self.rom_finder = ROMFinder(self.logger, 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)

  def validate_base_environment(self):
    """
    Validate that the current environment meets all of Ice's requirements.
    """
    if self.validated_base_environment:
      return
    with EnvironmentChecker(self.filesystem) as env_checker:
      # If Steam is running then any changes we make will be overwritten
      env_checker.require_program_not_running("Steam")
      # I'm not sure if there are situations where this won't exist, but I
      # assume that it does everywhere and better safe than sorry
      env_checker.require_directory_exists(self.steam.userdata_directory)
      # This is used to store history information and such
      env_checker.require_directory_exists(Configuration.data_directory())
    self.validated_base_environment = True

  def validate_configuration(self, configuration):
    if self.validated_configuration:
      return
    with EnvironmentChecker(self.filesystem) as env_checker:
      for console in configuration.console_manager:
        if consoles.console_is_enabled(console):
          # Consoles assume they have a ROMs directory
          env_checker.require_directory_exists(configuration.roms_directory_for_console(console))
    self.validated_configuration = True

  def validate_user_environment(self, user):
    """
    Validate that the current environment for a given user meets all of
    Ice's requirements.
    """
    with EnvironmentChecker(self.filesystem) as env_checker:
      # If the user hasn't added any grid images on their own then this
      # directory wont exist, so we require it explicitly here
      env_checker.require_directory_exists(paths.custom_images_directory(user))
      # And it needs to be writable if we are going to save images there
      env_checker.require_writable_path(paths.custom_images_directory(user))

  def main(self, dry_run=False):
    if self.steam is None:
      self.logger.error("Cannot run Ice because Steam doesn't appear to be installed")
      return

    self.logger.info("=========== Starting Ice ===========")
    try:
      self.validate_base_environment()
      self.validate_configuration(self.config)
    except EnvCheckerError as e:
      self.logger.info("Ice cannot run because of issues with your system.\n")
      self.logger.info("* %s" % e.message)
      self.logger.info("\nPlease resolve these issues and try running Ice again")
      return
    # TODO: Create any missing directories that Ice will need
    log_configuration(self.logger, self.config)
    for user_context in steam.local_user_contexts(self.steam):
      self.logger.info("=========== User: %s ===========" % str(user_context.user_id))
      self.run_for_user(user_context, dry_run=dry_run)

  def run_for_user(self, user, dry_run=False):
    try:
      self.validate_base_environment()
      self.validate_configuration(self.config)
      self.validate_user_environment(user)
    except EnvCheckerError as e:
      self.logger.info("Ice cannot run because of issues with your system.\n")
      self.logger.info("\t%s\n" % e.message)
      self.logger.info("Please resolve these issues and try running Ice again")
      return
    self._create_backup(user, dry_run=dry_run)
    # Find all of the ROMs that are currently in the designated folders
    roms = self.rom_finder.roms_for_consoles(self.config.console_manager)
    self.shortcut_synchronizer.sync_roms_for_user(user, roms, self.config, dry_run=dry_run)
    self.grid_updater.update_artwork_for_rom_collection(user, roms, dry_run=dry_run)

  def run(self, dry_run=False):
    try:
      self.main(dry_run=dry_run)
    except Exception as error:
      self.logger.exception("An exception occurred while running Ice")

  def _create_backup(self, user, dry_run=False):
    if dry_run:
      self.logger.debug("Not creating backup because its a dry run")
      return

    backup_path = self.config.shortcuts_backup_path(user)
    if backup_path is None:
      self.logger.info("No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info")
      return

    shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
Ejemplo n.º 15
0
def _path_with_override(path_override, default_name):
  if path_override is not None:
    return path_override
  return Configuration.path_for_data_file(default_name)