示例#1
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")
示例#2
0
文件: main.py 项目: KevinAnthony/Ice
  def validate_environment(self, skip_steam_check):
    """
    Validate that the current environment meets all of Ice's requirements.
    """
    with EnvironmentChecker(self.filesystem) as env_checker:
      if not skip_steam_check:
        # If Steam is running then any changes we make will be overwritten
        env_checker.require_program_not_running("Steam")
      else:
        logger.warning(STEAM_CHECK_SKIPPED_WARNING)
      # 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())

      for console in self.app_settings.consoles:
        # Consoles assume they have a ROMs directory
        env_checker.require_directory_exists(consoles.console_roms_directory(self.app_settings.config, console))

      for user in self.users:
        # 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))
示例#3
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)
示例#4
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)
示例#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 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)
示例#7
0
 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
示例#8
0
 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())
示例#9
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")
示例#10
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(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
示例#11
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)
示例#12
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))
示例#13
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")