def CheckFile(self, filename):
    """Validates the artifacts definition in a specific file.

    Args:
      filename (str): name of the artifacts definition file.

    Returns:
      bool: True if the file contains valid artifacts definitions.
    """
    result = True
    artifact_reader = reader.YamlArtifactsReader()

    try:
      for artifact_definition in artifact_reader.ReadFile(filename):
        try:
          self._artifact_registry.RegisterDefinition(artifact_definition)
        except KeyError:
          logging.warning(
              'Duplicate artifact definition: {0:s} in file: {1:s}'.format(
                  artifact_definition.name, filename))
          result = False

        artifact_definition_supports_macos = (
            definitions.SUPPORTED_OS_DARWIN in (
                artifact_definition.supported_os))
        artifact_definition_supports_windows = (
            definitions.SUPPORTED_OS_WINDOWS in (
                artifact_definition.supported_os))

        for source in artifact_definition.sources:
          if source.type_indicator in (
              definitions.TYPE_INDICATOR_FILE, definitions.TYPE_INDICATOR_PATH):

            if (definitions.SUPPORTED_OS_DARWIN in source.supported_os or (
                artifact_definition_supports_macos and
                not source.supported_os)):
              if not self._CheckMacOSPaths(
                  filename, artifact_definition, source, source.paths):
                result = False

            elif (artifact_definition_supports_windows or
                  definitions.SUPPORTED_OS_WINDOWS in source.supported_os):
              for path in source.paths:
                if not self._CheckWindowsPath(
                    filename, artifact_definition, source, path):
                  result = False

          elif source.type_indicator == (
              definitions.TYPE_INDICATOR_WINDOWS_REGISTRY_KEY):

            # Exempt the legacy file from duplicate checking because it has
            # duplicates intentionally.
            if (filename != self.LEGACY_PATH and
                self._HasDuplicateRegistryKeyPaths(
                    filename, artifact_definition, source)):
              result = False

            for key_path in source.keys:
              if not self._CheckWindowsRegistryKeyPath(
                  filename, artifact_definition, key_path):
                result = False

          elif source.type_indicator == (
              definitions.TYPE_INDICATOR_WINDOWS_REGISTRY_VALUE):

            for key_value_pair in source.key_value_pairs:
              if not self._CheckWindowsRegistryKeyPath(
                  filename, artifact_definition, key_value_pair['key']):
                result = False

    except errors.FormatError as exception:
      logging.warning(
          'Unable to validate file: {0:s} with error: {1!s}'.format(
              filename, exception))
      result = False

    return result
def CheckFile ( self , filename ) : result = True artifact_reader = reader . YamlArtifactsReader ( ) try : for artifact_definition in artifact_reader . ReadFile ( filename ) : try : self . _artifact_registry . RegisterDefinition ( artifact_definition ) except KeyError : logging . warning ( 'Duplicate artifact definition: {0:s} in file: {1:s}' . format ( artifact_definition . name , filename ) ) result = False artifact_definition_supports_macos = ( definitions . SUPPORTED_OS_DARWIN in ( artifact_definition . supported_os ) ) artifact_definition_supports_windows = ( definitions . SUPPORTED_OS_WINDOWS in ( artifact_definition . supported_os ) ) for source in artifact_definition . sources : if source . type_indicator in ( definitions . TYPE_INDICATOR_FILE , definitions . TYPE_INDICATOR_PATH ) : if ( definitions . SUPPORTED_OS_DARWIN in source . supported_os or ( artifact_definition_supports_macos and not source . supported_os ) ) : if not self . _CheckMacOSPaths ( filename , artifact_definition , source , source . paths ) : result = False elif ( artifact_definition_supports_windows or definitions . SUPPORTED_OS_WINDOWS in source . supported_os ) : for path in source . paths : if not self . _CheckWindowsPath ( filename , artifact_definition , source , path ) : result = False elif source . type_indicator == ( definitions . TYPE_INDICATOR_WINDOWS_REGISTRY_KEY ) : if ( filename != self . LEGACY_PATH and self . _HasDuplicateRegistryKeyPaths ( filename , artifact_definition , source ) ) : result = False for key_path in source . keys : if not self . _CheckWindowsRegistryKeyPath ( filename , artifact_definition , key_path ) : result = False elif source . type_indicator == ( definitions . TYPE_INDICATOR_WINDOWS_REGISTRY_VALUE ) : for key_value_pair in source . key_value_pairs : if not self . _CheckWindowsRegistryKeyPath ( filename , artifact_definition , key_value_pair [ 'key' ] ) : result = False except errors . FormatError as exception : logging . warning ( 'Unable to validate file: {0:s} with error: {1!s}' . format ( filename , exception ) ) result = False return result
Validates the artifacts definition in a specific file.

    Args:
      filename (str): name of the artifacts definition file.

    Returns:
      bool: True if the file contains valid artifacts definitions.