예제 #1
0
 def testRequireWritablePathFailsWhenDirectoryIsntWritable(self):
     path = os.path.join(self.tempdir, "readonly")
     os.mkdir(path)
     os.chmod(path, stat.S_IREAD)
     with self.assertRaises(EnvCheckerError):
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_writable_path(path)
예제 #2
0
 def testRequireWritablePathSucceedsWithWritablePath(self):
     # Temp directories are writable by default
     try:
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_writable_path(self.tempdir)
     except:
         self.fail("Should succeed when given a writable path")
예제 #3
0
 def testRequireWritablePathFailsWhenFileIsntWritable(self):
     path = os.path.join(self.tempdir, "mad-scientist")
     with open(path, "w+") as f:
         f.write("its so cool!")
     os.chmod(path, stat.S_IREAD)
     with self.assertRaises(EnvCheckerError):
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_writable_path(path)
예제 #4
0
 def testRequireDirectoryExistsFailsWhenFileExistsAtPath(self):
     path = os.path.join(self.tempdir, "missing")
     self.assertFalse(os.path.exists(path))
     with open(path, "w+") as f:
         f.write("Batman")
     with self.assertRaises(EnvCheckerError):
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_directory_exists(path)
예제 #5
0
 def testRequireDirectoryExistsFailsWhenCantCreateMissingDirectory(self):
     parent_path = os.path.join(self.tempdir, "exists")
     os.mkdir(parent_path)
     os.chmod(parent_path, stat.S_IREAD)
     child_path = os.path.join(parent_path, "dne")
     with self.assertRaises(EnvCheckerError):
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_directory_exists(child_path)
예제 #6
0
 def testRequireProgramNotRunningFailsWhenProgramIsRunning(self):
     # ASSUMPTION: Since I am writing this in Python I am going to cheat a
     # a little and test this by requiring that `python` is not running. If
     # this test is run by a process whose name is something other than `python`
     # it will fail.
     #
     # Also I should make sure not to make it automatically resolve the error
     # by killing the process
     #
     # That would be bad
     with self.assertRaises(EnvCheckerError):
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_program_not_running("python")
예제 #7
0
 def __init__(self, steam=None, filesystem=None):
   self.steam = steam
   self.filesystem = RealFilesystem() if filesystem is None else filesystem
예제 #8
0
class CommandLineRunner(object):

  def __init__(self, steam=None, filesystem=None):
    self.steam = steam
    self.filesystem = RealFilesystem() if filesystem is None else filesystem

  def get_command_line_args(self, argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('pdebug', type=bool, nargs='?', help="Pastes debug logs to pastebin to include with bug reports.")
    parser.add_argument('--skip-steam-check', action='store_true', help="Skips checking whether Steam is running")
    parser.add_argument('--launch-steam', action='store_true', help="Launches Steam after the shortcuts have been synced and its safe to do so")
    # Config options
    parser.add_argument('-c', '--config', type=str, default=None)
    parser.add_argument('-C', '--consoles', type=str, default=None)
    parser.add_argument('-e', '--emulators', type=str, default=None)
    # Debugging options
    parser.add_argument('-d', '--dry-run', action='store_true')
    return parser.parse_args(argv)

  def should_use_user_override(self, override):
    if override is None:
      return False
    if override == "":
      return False
    if not self.filesystem.path_exists(override):
      logger.warning("config.txt specifies a Steam userdata directory that doesn't exist. Ignoring.")
      return False
    return False

  def get_steam(self, config):
    override = config.userdata_directory
    if self.should_use_user_override(override):
      return Steam(override)

    if self.steam is not None:
      return self.steam

    return get_steam()

  @decorators.catch_exceptions(handle_exception)
  def run(self, argv):
    opts = self.get_command_line_args(argv[1:])

    if opts.pdebug is True:
      debug.paste_debug_logs()
      return

    task_coordinator = tasks.TaskCoordinator(self.filesystem)

    app_settings = settings.load_app_settings(self.filesystem, file_overrides = {
        'config.txt': opts.config,
        'consoles.txt': opts.consoles,
        'emulators.txt': opts.emulators,
    })

    engine = TaskEngine(
      self.get_steam(app_settings.config),
    )

    tasks_to_run = task_coordinator.tasks_for_options(
      launch_steam = opts.launch_steam,
      skip_steam_check = opts.skip_steam_check,
    )

    engine.run(
      tasks = tasks_to_run,
      app_settings = app_settings,
      dry_run=opts.dry_run
    )
예제 #9
0
 def testRequireWritablePathFailsWhenDirectoryDoesntExist(self):
     path = os.path.join(self.tempdir, "dne")
     with self.assertRaises(EnvCheckerError):
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_writable_path(path)
예제 #10
0
 def testRequireDirectoryExistsCreatesMissingDirectory(self):
     path = os.path.join(self.tempdir, "missing")
     self.assertFalse(os.path.exists(path))
     with EnvironmentChecker(RealFilesystem()) as env_checker:
         env_checker.require_directory_exists(path)
     self.assertTrue(os.path.isdir(path))
예제 #11
0
 def testRequireDirectoryExistsSucceedsWhenDirectoryExists(self):
     try:
         with EnvironmentChecker(RealFilesystem()) as env_checker:
             env_checker.require_directory_exists(self.tempdir)
     except:
         self.fail("Should succeed when given a directory that exists")
예제 #12
0
 def __init__(self, steam=None, filesystem=None):
   self.steam = steam if steam is not None else get_steam()
   self.filesystem = RealFilesystem() if filesystem is None else filesystem
예제 #13
0
파일: runner.py 프로젝트: drglove/Ice
 def __init__(self, steam=None, filesystem=None):
     self.steam = steam
     self.filesystem = RealFilesystem() if filesystem is None else filesystem
예제 #14
0
파일: runner.py 프로젝트: drglove/Ice
class CommandLineRunner(object):
    def __init__(self, steam=None, filesystem=None):
        self.steam = steam
        self.filesystem = RealFilesystem() if filesystem is None else filesystem

    def get_command_line_args(self, argv):
        parser = argparse.ArgumentParser()
        parser.add_argument(
            "pdebug", type=bool, nargs="?", help="Pastes debug logs to pastebin to include with bug reports."
        )
        parser.add_argument("--skip-steam-check", action="store_true", help="Skips checking whether Steam is running")
        parser.add_argument(
            "--launch-steam",
            action="store_true",
            help="Launches Steam after the shortcuts have been synced and its safe to do so",
        )
        # Config options
        parser.add_argument("-c", "--config", type=str, default=None)
        parser.add_argument("-C", "--consoles", type=str, default=None)
        parser.add_argument("-e", "--emulators", type=str, default=None)
        # Debugging options
        parser.add_argument("-d", "--dry-run", action="store_true")
        return parser.parse_args(argv)

    def should_use_user_override(self, override):
        if override is None:
            return False
        if override == "":
            return False
        if not self.filesystem.path_exists(override):
            logger.warning("config.txt specifies a Steam userdata directory that doesn't exist. Ignoring.")
            return False
        return False

    def get_steam(self, config):
        override = config.userdata_directory
        if self.should_use_user_override(override):
            return Steam(override)

        if self.steam is not None:
            return self.steam

        return get_steam()

    @decorators.catch_exceptions(handle_exception)
    def run(self, argv):
        opts = self.get_command_line_args(argv[1:])

        if opts.pdebug is True:
            debug.paste_debug_logs()
            return

        task_coordinator = tasks.TaskCoordinator(self.filesystem)

        app_settings = settings.load_app_settings(
            self.filesystem,
            file_overrides={"config.txt": opts.config, "consoles.txt": opts.consoles, "emulators.txt": opts.emulators},
        )

        engine = TaskEngine(self.get_steam(app_settings.config))

        tasks_to_run = task_coordinator.tasks_for_options(
            launch_steam=opts.launch_steam, skip_steam_check=opts.skip_steam_check
        )

        engine.run(tasks=tasks_to_run, app_settings=app_settings, dry_run=opts.dry_run)