Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
Show All 15 Lines | |||||
from django.urls import reverse as django_reverse | from django.urls import reverse as django_reverse | ||||
from django.http import QueryDict, HttpRequest | from django.http import QueryDict, HttpRequest | ||||
from prometheus_client.registry import CollectorRegistry | from prometheus_client.registry import CollectorRegistry | ||||
from rest_framework.authentication import SessionAuthentication | from rest_framework.authentication import SessionAuthentication | ||||
from swh.model.exceptions import ValidationError | from swh.model.exceptions import ValidationError | ||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
persistent_identifier, parse_persistent_identifier, | persistent_identifier, parse_persistent_identifier, | ||||
CONTENT, DIRECTORY, ORIGIN, RELEASE, REVISION, SNAPSHOT | CONTENT, DIRECTORY, ORIGIN, RELEASE, REVISION, SNAPSHOT | ||||
) | ) | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
▲ Show 20 Lines • Show All 349 Lines • ▼ Show 20 Lines | while branch and branch['target_type'] == 'alias': | ||||
snp = service.lookup_snapshot( | snp = service.lookup_snapshot( | ||||
snapshot['id'], branches_from=branch['target'], | snapshot['id'], branches_from=branch['target'], | ||||
branches_count=1) | branches_count=1) | ||||
if snp and branch['target'] in snp['branches']: | if snp and branch['target'] in snp['branches']: | ||||
branch = snp['branches'][branch['target']] | branch = snp['branches'][branch['target']] | ||||
else: | else: | ||||
branch = None | branch = None | ||||
return branch | return branch | ||||
def group_swh_persistent_identifiers(persistent_ids): | |||||
""" | |||||
Groups many Software Heritage persistent identifiers into a | |||||
dictionary depending on their type. | |||||
Args: | |||||
persistent_ids (list): a list of Software Heritage persistent | |||||
identifier objects | |||||
Returns: | |||||
A dictionary with: | |||||
keys: persistent identifier types | |||||
zack: the indentation of the dictionary keys do not look right here | |||||
values: list(bytes) persistent identifiers id | |||||
""" | |||||
pids_by_type = { | |||||
CONTENT: [], | |||||
DIRECTORY: [], | |||||
REVISION: [], | |||||
RELEASE: [], | |||||
SNAPSHOT: [] | |||||
} | |||||
for pid in persistent_ids: | |||||
obj_id = pid.object_id | |||||
obj_type = pid.object_type | |||||
pids_by_type[obj_type].append(hash_to_bytes(obj_id)) | |||||
return pids_by_type | |||||
Not Done Inline ActionsYou should add a small wrapper around parse_persistent_identifier to handle the error, that can be shared with resolve_swh_persistent_id. vlorentz: You should add a small wrapper around `parse_persistent_identifier` to handle the error, that… |
the indentation of the dictionary keys do not look right here