Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/loader.py
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | ) -> Optional[Revision]: | ||||
# `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 | ||||
# revision. | # revision. | ||||
# date: codemeta:dateCreated if any, deposit completed_date otherwise | # date: codemeta:dateCreated if any, deposit completed_date otherwise | ||||
date = TimestampWithTimezone.from_dict(revision_data["date"]) | date = TimestampWithTimezone.from_dict(revision_data["date"]) | ||||
# commit_date: codemeta:datePublished if any, deposit completed_date otherwise | # commit_date: codemeta:datePublished if any, deposit completed_date otherwise | ||||
commit_date = TimestampWithTimezone.from_dict(revision_data["committer_date"]) | commit_date = TimestampWithTimezone.from_dict(revision_data["committer_date"]) | ||||
metadata = revision_data["metadata"] | |||||
metadata.update( | |||||
{ | |||||
"extrinsic": { | |||||
"provider": self.client.metadata_url(self.deposit_id), | |||||
"when": self.visit_date.isoformat(), | |||||
"raw": a_metadata, | |||||
}, | |||||
} | |||||
) | |||||
return Revision( | return Revision( | ||||
type=RevisionType.TAR, | type=RevisionType.TAR, | ||||
message=revision_data["message"].encode("utf-8"), | message=revision_data["message"].encode("utf-8"), | ||||
author=parse_author(revision_data["author"]), | author=parse_author(revision_data["author"]), | ||||
date=date, | date=date, | ||||
committer=parse_author(revision_data["committer"]), | committer=parse_author(revision_data["committer"]), | ||||
committer_date=commit_date, | committer_date=commit_date, | ||||
parents=[hash_to_bytes(p) for p in revision_data.get("parents", [])], | parents=[hash_to_bytes(p) for p in revision_data.get("parents", [])], | ||||
directory=directory, | directory=directory, | ||||
synthetic=True, | synthetic=True, | ||||
metadata=metadata, | metadata={ | ||||
"extrinsic": { | |||||
"provider": self.client.metadata_url(self.deposit_id), | |||||
"when": self.visit_date.isoformat(), | |||||
"raw": a_metadata, | |||||
}, | |||||
}, | |||||
) | ) | ||||
def load(self) -> Dict: | def load(self) -> Dict: | ||||
# First making sure the deposit is known prior to trigger a loading | # First making sure the deposit is known prior to trigger a loading | ||||
try: | try: | ||||
self.metadata = self.client.metadata_get(self.deposit_id) | self.metadata = self.client.metadata_get(self.deposit_id) | ||||
except ValueError: | except ValueError: | ||||
logger.error(f"Unknown deposit {self.deposit_id}, ignoring") | logger.error(f"Unknown deposit {self.deposit_id}, ignoring") | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |