Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/loader.py
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | class DepositLoader(PackageLoader[DepositPackageInfo]): | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
storage: StorageInterface, | storage: StorageInterface, | ||||
url: str, | url: str, | ||||
deposit_id: str, | deposit_id: str, | ||||
deposit_client: "ApiClient", | deposit_client: "ApiClient", | ||||
max_content_size: Optional[int] = None, | max_content_size: Optional[int] = None, | ||||
default_filename: str = "archive.zip", | |||||
): | ): | ||||
"""Constructor | """Constructor | ||||
Args: | Args: | ||||
url: Origin url to associate the artifacts/metadata to | url: Origin url to associate the artifacts/metadata to | ||||
deposit_id: Deposit identity | deposit_id: Deposit identity | ||||
deposit_client: Deposit api client | deposit_client: Deposit api client | ||||
""" | """ | ||||
super().__init__(storage=storage, url=url, max_content_size=max_content_size) | super().__init__(storage=storage, url=url, max_content_size=max_content_size) | ||||
self.deposit_id = deposit_id | self.deposit_id = deposit_id | ||||
self.client = deposit_client | self.client = deposit_client | ||||
self.default_filename = default_filename | |||||
@classmethod | @classmethod | ||||
def from_configfile(cls, **kwargs: Any): | def from_configfile(cls, **kwargs: Any): | ||||
"""Instantiate a loader from the configuration loaded from the | """Instantiate a loader from the configuration loaded from the | ||||
SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments if their | SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments if their | ||||
value is not None. | value is not None. | ||||
Args: | Args: | ||||
Show All 27 Lines | def get_metadata_fetcher(self) -> MetadataFetcher: | ||||
return MetadataFetcher( | return MetadataFetcher( | ||||
name=tool["name"], version=tool["version"], metadata=tool["configuration"], | name=tool["name"], version=tool["version"], metadata=tool["configuration"], | ||||
) | ) | ||||
def get_package_info( | def get_package_info( | ||||
self, version: str | self, version: str | ||||
) -> Iterator[Tuple[str, DepositPackageInfo]]: | ) -> Iterator[Tuple[str, DepositPackageInfo]]: | ||||
p_info = DepositPackageInfo.from_metadata( | p_info = DepositPackageInfo.from_metadata( | ||||
self.metadata(), url=self.url, filename="archive.zip", | self.metadata(), url=self.url, filename=self.default_filename, | ||||
) | ) | ||||
yield "HEAD", p_info | yield "HEAD", p_info | ||||
def download_package( | def download_package( | ||||
self, p_info: DepositPackageInfo, tmpdir: str | self, p_info: DepositPackageInfo, tmpdir: str | ||||
) -> List[Tuple[str, Mapping]]: | ) -> List[Tuple[str, Mapping]]: | ||||
"""Override to allow use of the dedicated deposit client | """Override to allow use of the dedicated deposit client | ||||
▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines |