Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/archive/loader.py
Show All 28 Lines | |||||
@attr.s | @attr.s | ||||
class ArchivePackageInfo(BasePackageInfo): | class ArchivePackageInfo(BasePackageInfo): | ||||
raw_info = attr.ib(type=Dict[str, Any]) | raw_info = attr.ib(type=Dict[str, Any]) | ||||
length = attr.ib(type=int) | length = attr.ib(type=int) | ||||
"""Size of the archive file""" | """Size of the archive file""" | ||||
time = attr.ib(type=Union[str, datetime.datetime]) | time = attr.ib(type=Union[str, datetime.datetime]) | ||||
"""Timestamp of the archive file on the server""" | """Timestamp of the archive file on the server""" | ||||
version = attr.ib(type=str) | |||||
# default format for gnu | # default format for gnu | ||||
MANIFEST_FORMAT = string.Template("$time $length $version $url") | MANIFEST_FORMAT = string.Template("$time $length $version $url") | ||||
def extid(self, manifest_format: Optional[string.Template] = None) -> PartialExtID: | def extid(self, manifest_format: Optional[string.Template] = None) -> PartialExtID: | ||||
"""Returns a unique intrinsic identifier of this package info | """Returns a unique intrinsic identifier of this package info | ||||
``manifest_format`` allows overriding the class' default MANIFEST_FORMAT""" | ``manifest_format`` allows overriding the class' default MANIFEST_FORMAT""" | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | ) -> Iterator[Tuple[str, ArchivePackageInfo]]: | ||||
yield release_name(version), p_info | yield release_name(version), p_info | ||||
def new_packageinfo_to_extid( | def new_packageinfo_to_extid( | ||||
self, p_info: ArchivePackageInfo | self, p_info: ArchivePackageInfo | ||||
) -> Optional[PartialExtID]: | ) -> Optional[PartialExtID]: | ||||
return p_info.extid(manifest_format=self.extid_manifest_format) | return p_info.extid(manifest_format=self.extid_manifest_format) | ||||
def build_release( | def build_release( | ||||
self, | self, p_info: ArchivePackageInfo, uncompressed_path: str, directory: Sha1Git | ||||
version: str, | |||||
p_info: ArchivePackageInfo, | |||||
uncompressed_path: str, | |||||
directory: Sha1Git, | |||||
) -> Optional[Release]: | ) -> Optional[Release]: | ||||
time = p_info.time # assume it's a timestamp | time = p_info.time # assume it's a timestamp | ||||
if isinstance(time, str): # otherwise, assume it's a parsable date | if isinstance(time, str): # otherwise, assume it's a parsable date | ||||
parsed_time = iso8601.parse_date(time) | parsed_time = iso8601.parse_date(time) | ||||
else: | else: | ||||
parsed_time = time | parsed_time = time | ||||
normalized_time = TimestampWithTimezone.from_datetime(parsed_time) | normalized_time = TimestampWithTimezone.from_datetime(parsed_time) | ||||
return Release( | return Release( | ||||
name=version.encode(), | name=p_info.version.encode(), | ||||
message=REVISION_MESSAGE, | message=REVISION_MESSAGE, | ||||
date=normalized_time, | date=normalized_time, | ||||
author=SWH_PERSON, | author=SWH_PERSON, | ||||
target=directory, | target=directory, | ||||
target_type=ObjectType.DIRECTORY, | target_type=ObjectType.DIRECTORY, | ||||
synthetic=True, | synthetic=True, | ||||
) | ) | ||||
def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | ||||
if not self.snapshot_append: | if not self.snapshot_append: | ||||
return {} | return {} | ||||
last_snapshot = self.last_snapshot() | last_snapshot = self.last_snapshot() | ||||
return last_snapshot.to_dict()["branches"] if last_snapshot else {} | return last_snapshot.to_dict()["branches"] if last_snapshot else {} |