Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/loader.py
Show All 38 Lines | |||||
def now() -> datetime.datetime: | def now() -> datetime.datetime: | ||||
return datetime.datetime.now(tz=timezone.utc) | return datetime.datetime.now(tz=timezone.utc) | ||||
@attr.s | @attr.s | ||||
class DepositPackageInfo(BasePackageInfo): | class DepositPackageInfo(BasePackageInfo): | ||||
filename = attr.ib(type=str) # instead of Optional[str] | filename = attr.ib(type=str) # instead of Optional[str] | ||||
raw_info = attr.ib(type=Dict[str, Any]) | |||||
author_date = attr.ib(type=datetime.datetime) | author_date = attr.ib(type=datetime.datetime) | ||||
"""codemeta:dateCreated if any, deposit completed_date otherwise""" | """codemeta:dateCreated if any, deposit completed_date otherwise""" | ||||
commit_date = attr.ib(type=datetime.datetime) | commit_date = attr.ib(type=datetime.datetime) | ||||
"""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) | ||||
release_notes = attr.ib(type=Optional[str]) | release_notes = attr.ib(type=Optional[str]) | ||||
@classmethod | @classmethod | ||||
def from_metadata( | def from_metadata( | ||||
cls, metadata: Dict[str, Any], url: str, filename: str, version: str | cls, metadata: Dict[str, Any], url: str, filename: str, version: 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 | ||||
# release. | # release. | ||||
all_metadata_raw: List[str] = metadata["metadata_raw"] | all_metadata_raw: List[str] = metadata["metadata_raw"] | ||||
raw_info = { | |||||
"origin": metadata["origin"], | |||||
"origin_metadata": { | |||||
"metadata": metadata["metadata_dict"], | |||||
"provider": metadata["provider"], | |||||
"tool": metadata["tool"], | |||||
}, | |||||
} | |||||
depo = metadata["deposit"] | depo = metadata["deposit"] | ||||
return cls( | return cls( | ||||
url=url, | url=url, | ||||
filename=filename, | filename=filename, | ||||
version=version, | version=version, | ||||
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"]), | ||||
release_notes=depo["release_notes"], | release_notes=depo["release_notes"], | ||||
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 293 Lines • Show Last 20 Lines |