Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/loader.py
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | def resolve_revision_from( | ||||
artifact_metadata: Information dict | artifact_metadata: Information dict | ||||
Returns: | Returns: | ||||
None or revision identifier | None or revision identifier | ||||
""" | """ | ||||
return None | return None | ||||
def resolve_target_from( | |||||
self, known_artifacts: Dict, artifact_metadata: Dict) \ | |||||
-> Tuple[str, Optional[bytes]]: | |||||
return 'revision', self.resolve_revision_from( | |||||
known_artifacts, | |||||
artifact_metadata) | |||||
def download_package(self, p_info: Mapping[str, Any], | def download_package(self, p_info: Mapping[str, Any], | ||||
tmpdir: str) -> List[Tuple[str, Mapping]]: | tmpdir: str) -> List[Tuple[str, Mapping]]: | ||||
"""Download artifacts for a specific package. All downloads happen in | """Download artifacts for a specific package. All downloads happen in | ||||
in the tmpdir folder. | in the tmpdir folder. | ||||
Default implementation expects the artifacts package info to be | Default implementation expects the artifacts package info to be | ||||
about one artifact per package. | about one artifact per package. | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | def load(self) -> Dict: | ||||
logger.debug('default version: %s', default_version) | logger.debug('default version: %s', default_version) | ||||
for version in self.get_versions(): # for each | for version in self.get_versions(): # for each | ||||
logger.debug('version: %s', version) | logger.debug('version: %s', version) | ||||
tmp_revisions[version] = [] | tmp_revisions[version] = [] | ||||
# `p_` stands for `package_` | # `p_` stands for `package_` | ||||
for branch_name, p_info in self.get_package_info(version): | for branch_name, p_info in self.get_package_info(version): | ||||
logger.debug('package_info: %s', p_info) | logger.debug('package_info: %s', p_info) | ||||
revision_id = self.resolve_revision_from( | target_type, target_id = self.resolve_target_from( | ||||
known_artifacts, p_info['raw']) | known_artifacts, p_info['raw']) | ||||
if revision_id is None: | if target_id is None: | ||||
(revision_id, loaded) = \ | (target_type, target_id, loaded) = \ | ||||
self._load_revision(p_info, origin) | self._load_target(p_info, origin) | ||||
if loaded: | if loaded: | ||||
status_load = 'eventful' | status_load = 'eventful' | ||||
else: | else: | ||||
status_visit = 'partial' | status_visit = 'partial' | ||||
if revision_id is None: | if target_id is None: | ||||
continue | continue | ||||
tmp_revisions[version].append((branch_name, revision_id)) | tmp_revisions[version].append(( | ||||
branch_name, | |||||
target_type, | |||||
target_id)) | |||||
logger.debug('tmp_revisions: %s', tmp_revisions) | logger.debug('tmp_revisions: %s', tmp_revisions) | ||||
# Build and load the snapshot | # Build and load the snapshot | ||||
branches = {} # type: Dict[bytes, Mapping[str, Any]] | branches = {} # type: Dict[bytes, Mapping[str, Any]] | ||||
for version, branch_name_revisions in tmp_revisions.items(): | for version, branch_name_revisions in tmp_revisions.items(): | ||||
if version == default_version and \ | if version == default_version and \ | ||||
len(branch_name_revisions) == 1: | len(branch_name_revisions) == 1: | ||||
# only 1 branch (no ambiguity), we can create an alias | # only 1 branch (no ambiguity), we can create an alias | ||||
# branch 'HEAD' | # branch 'HEAD' | ||||
branch_name, _ = branch_name_revisions[0] | branch_name, _ = branch_name_revisions[0] | ||||
# except for some corner case (deposit) | # except for some corner case (deposit) | ||||
if branch_name != 'HEAD': | if branch_name != 'HEAD': | ||||
branches[b'HEAD'] = { | branches[b'HEAD'] = { | ||||
'target_type': 'alias', | 'target_type': 'alias', | ||||
'target': branch_name.encode('utf-8'), | 'target': branch_name.encode('utf-8'), | ||||
} | } | ||||
for branch_name, target in branch_name_revisions: | for branch_name, target_type, target in branch_name_revisions: | ||||
branches[branch_name.encode('utf-8')] = { | branches[branch_name.encode('utf-8')] = { | ||||
'target_type': 'revision', | 'target_type': target_type, | ||||
'target': target, | 'target': target, | ||||
} | } | ||||
for name, target in self.extra_branches().items(): | for name, target in self.extra_branches().items(): | ||||
if name in branches: | if name in branches: | ||||
logger.error("Extra branch '%s' has been ignored", | logger.error("Extra branch '%s' has been ignored", | ||||
name) | name) | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | def _load_revision(self, p_info, origin) -> Tuple[Optional[Sha1Git], bool]: | ||||
}) | }) | ||||
revision = attr.evolve(revision, metadata=metadata) | revision = attr.evolve(revision, metadata=metadata) | ||||
logger.debug('Revision: %s', revision) | logger.debug('Revision: %s', revision) | ||||
self.storage.revision_add([revision]) | self.storage.revision_add([revision]) | ||||
return (revision.id, True) | return (revision.id, True) | ||||
def _load_target( | |||||
self, p_info, origin) \ | |||||
-> Tuple[str, Optional[Sha1Git], bool]: | |||||
revision_id, loaded = self._load_revision(p_info, origin) | |||||
return 'revision', revision_id, loaded |