Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/loader.py
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | def uncompress(self, dl_artifacts: List[Tuple[str, Mapping[str, Any]]], | ||||
information (debian). | information (debian). | ||||
""" | """ | ||||
uncompressed_path = os.path.join(dest, 'src') | uncompressed_path = os.path.join(dest, 'src') | ||||
for a_path, _ in dl_artifacts: | for a_path, _ in dl_artifacts: | ||||
uncompress(a_path, dest=uncompressed_path) | uncompress(a_path, dest=uncompressed_path) | ||||
return uncompressed_path | return uncompressed_path | ||||
def hook_branches( | |||||
self, branches: Dict[bytes, Mapping[str, Any]]) \ | |||||
-> Dict[bytes, Mapping[str, Any]]: | |||||
"""This hook allows to modify the branches dict before creating the | |||||
snapshot. | |||||
""" | |||||
return branches | |||||
def load(self) -> Dict: | def load(self) -> Dict: | ||||
"""Load for a specific origin the associated contents. | """Load for a specific origin the associated contents. | ||||
for each package version of the origin | for each package version of the origin | ||||
1. Fetch the files for one package version By default, this can be | 1. Fetch the files for one package version By default, this can be | ||||
implemented as a simple HTTP request. Loaders with more specific | implemented as a simple HTTP request. Loaders with more specific | ||||
requirements can override this, e.g.: the PyPI loader checks the | requirements can override this, e.g.: the PyPI loader checks the | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | def load(self) -> Dict: | ||||
'target': branch_name.encode('utf-8'), | 'target': branch_name.encode('utf-8'), | ||||
} | } | ||||
for branch_name, target in branch_name_revisions: | for branch_name, target in branch_name_revisions: | ||||
branches[branch_name.encode('utf-8')] = { | branches[branch_name.encode('utf-8')] = { | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
'target': target, | 'target': target, | ||||
} | } | ||||
ardumont: Please, give better name to k and v. | |||||
Done Inline ActionsHm, mypy doesn't allow to change the type of a varaible in a scope. So, I add to rename k to name (and not to branch_name which is already used). lewo: Hm, mypy doesn't allow to change the type of a varaible in a scope. So, I add to rename `k` to… | |||||
Not Done Inline Actionsyes, that's quite fine ;) ardumont: yes, that's quite fine ;) | |||||
snapshot_data = { | snapshot_data = { | ||||
'branches': branches | 'branches': self.hook_branches(branches) | ||||
} | } | ||||
logger.debug('snapshot: %s', snapshot_data) | logger.debug('snapshot: %s', snapshot_data) | ||||
snapshot = Snapshot.from_dict(snapshot_data) | snapshot = Snapshot.from_dict(snapshot_data) | ||||
logger.debug('snapshot: %s', snapshot) | logger.debug('snapshot: %s', snapshot) | ||||
self.storage.snapshot_add([snapshot]) | self.storage.snapshot_add([snapshot]) | ||||
if hasattr(self.storage, 'flush'): | if hasattr(self.storage, 'flush'): | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
Please, give better name to k and v.