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)
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")
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)
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)
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)
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")
def __init__(self, steam=None, filesystem=None): self.steam = steam self.filesystem = RealFilesystem() if filesystem is None else filesystem
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 )
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)
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))
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")
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
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)