def _load_file_manifest(self, path_prefix, file_manifest_file): """Load CollectionArtifactFileManifest data from file_manifest_file Args: path_prefix (str): Any file path prefix we need to add to file paths in the CollectionArtifactFile artifact_file file_manifest_file (CollectionArtifactFile): object with info about the FILES.json in the artifact. The info includes the name, type, path, and chksum. Raises: ManifestValidationError: If there are any errors loading, parsing, deserializing, or validating the data in file_manifest_file Returns: CollectionArtifactFileManifest: The data from file_manifest_file """ default_logger.debug("file_manifest_file: %s", file_manifest_file) chksums.check_artifact_file(path_prefix=path_prefix, artifact_file=file_manifest_file) files_manifest_file = os.path.join(path_prefix, file_manifest_file.name) default_logger.debug("files_manifest_file: %s", files_manifest_file) with open(files_manifest_file, "r") as f: try: file_manifest = schema.CollectionArtifactFileManifest.parse( f.read()) except ValueError as e: raise exc.ManifestValidationError(str(e)) return file_manifest
def _check_metadata_filepaths(self): paths = [] paths.append(os.path.join(self.path, self.metadata.readme)) if self.metadata.license_file: paths.append(os.path.join(self.path, self.metadata.license_file)) for path in paths: if not os.path.exists(path): raise exc.ManifestValidationError( f'Could not find file {os.path.basename(path)}')
def _check_metadata_filepaths(self): # NOTE: This may be redundant if _check_file_manifest() looks for missing files paths = [] paths.append(os.path.join(self.path, self.metadata.readme)) if self.metadata.license_file: paths.append(os.path.join(self.path, self.metadata.license_file)) for path in paths: if not os.path.exists(path): raise exc.ManifestValidationError( f"Could not find file {os.path.basename(path)}")
def _load_collection_manifest(self): manifest_file = os.path.join(self.path, 'MANIFEST.json') if not os.path.exists(manifest_file): raise exc.ManifestNotFound('No manifest found in collection') with open(manifest_file, 'r') as f: try: data = schema.CollectionArtifactManifest.parse(f.read()) except ValueError as e: raise exc.ManifestValidationError(str(e)) self.metadata = data.collection_info
def _check_filename_matches_manifest(self): if not self.filename: return for item in ['namespace', 'name', 'version']: filename_item = getattr(self.filename, item, None) metadata_item = getattr(self.metadata, item, None) if not filename_item: continue if filename_item != metadata_item: raise exc.ManifestValidationError( f'Filename {item} "{filename_item}" did not match metadata "{metadata_item}"')
def _load_manifest(self): manifest_file = os.path.join(self.path, "MANIFEST.json") if not os.path.exists(manifest_file): raise exc.ManifestNotFound("No manifest found in collection") default_logger.debug("manifest_file: %s", manifest_file) with open(manifest_file, "r") as f: try: data = schema.CollectionArtifactManifest.parse(f.read()) except ValueError as e: raise exc.ManifestValidationError(str(e)) from e default_logger.debug("data: %s", data) default_logger.debug("data.file_manifest_file: %s", data.file_manifest_file) return data