Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/loader.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | class DepositPackageInfo(BasePackageInfo): | ||||
"""codemeta:datePublished if any, deposit completed_date otherwise""" | """codemeta:datePublished if any, deposit completed_date otherwise""" | ||||
client = attr.ib(type=str) | client = attr.ib(type=str) | ||||
id = attr.ib(type=int) | id = attr.ib(type=int) | ||||
"""Internal ID of the deposit in the deposit DB""" | """Internal ID of the deposit in the deposit DB""" | ||||
collection = attr.ib(type=str) | collection = attr.ib(type=str) | ||||
"""The collection in the deposit; see SWORD specification.""" | """The collection in the deposit; see SWORD specification.""" | ||||
author = attr.ib(type=Person) | author = attr.ib(type=Person) | ||||
committer = attr.ib(type=Person) | committer = attr.ib(type=Person) | ||||
revision_parents = attr.ib(type=Tuple[Sha1Git, ...]) | |||||
"""Revisions created from previous deposits, that will be used as parents of the | |||||
revision created for this deposit.""" | |||||
@classmethod | @classmethod | ||||
def from_metadata( | def from_metadata( | ||||
cls, metadata: Dict[str, Any], url: str, filename: str | cls, metadata: Dict[str, Any], url: str, filename: str | ||||
) -> "DepositPackageInfo": | ) -> "DepositPackageInfo": | ||||
# Note: | # Note: | ||||
# `date` and `committer_date` are always transmitted by the deposit read api | # `date` and `committer_date` are always transmitted by the deposit read api | ||||
# which computes itself the values. The loader needs to use those to create the | # which computes itself the values. The loader needs to use those to create the | ||||
Show All 14 Lines | ) -> "DepositPackageInfo": | ||||
filename=filename, | filename=filename, | ||||
author_date=depo["author_date"], | author_date=depo["author_date"], | ||||
commit_date=depo["committer_date"], | commit_date=depo["committer_date"], | ||||
client=depo["client"], | client=depo["client"], | ||||
id=depo["id"], | id=depo["id"], | ||||
collection=depo["collection"], | collection=depo["collection"], | ||||
author=parse_author(depo["author"]), | author=parse_author(depo["author"]), | ||||
committer=parse_author(depo["committer"]), | committer=parse_author(depo["committer"]), | ||||
revision_parents=tuple(hash_to_bytes(p) for p in depo["revision_parents"]), | |||||
raw_info=raw_info, | raw_info=raw_info, | ||||
directory_extrinsic_metadata=[ | directory_extrinsic_metadata=[ | ||||
RawExtrinsicMetadataCore( | RawExtrinsicMetadataCore( | ||||
discovery_date=now(), | discovery_date=now(), | ||||
metadata=raw_metadata.encode(), | metadata=raw_metadata.encode(), | ||||
format="sword-v2-atom-codemeta-v2", | format="sword-v2-atom-codemeta-v2", | ||||
) | ) | ||||
for raw_metadata in all_metadata_raw | for raw_metadata in all_metadata_raw | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | ) -> Optional[Revision]: | ||||
return Revision( | return Revision( | ||||
type=RevisionType.TAR, | type=RevisionType.TAR, | ||||
message=message, | message=message, | ||||
author=p_info.author, | author=p_info.author, | ||||
date=TimestampWithTimezone.from_dict(p_info.author_date), | date=TimestampWithTimezone.from_dict(p_info.author_date), | ||||
committer=p_info.committer, | committer=p_info.committer, | ||||
committer_date=TimestampWithTimezone.from_dict(p_info.commit_date), | committer_date=TimestampWithTimezone.from_dict(p_info.commit_date), | ||||
parents=p_info.revision_parents, | |||||
directory=directory, | directory=directory, | ||||
synthetic=True, | synthetic=True, | ||||
) | ) | ||||
def get_extrinsic_origin_metadata(self) -> List[RawExtrinsicMetadataCore]: | def get_extrinsic_origin_metadata(self) -> List[RawExtrinsicMetadataCore]: | ||||
metadata = self.metadata() | metadata = self.metadata() | ||||
all_metadata_raw: List[str] = metadata["metadata_raw"] | all_metadata_raw: List[str] = metadata["metadata_raw"] | ||||
origin_metadata = json.dumps( | origin_metadata = json.dumps( | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |