Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/utils.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import copy | import copy | ||||
import logging | import logging | ||||
import os | import os | ||||
import requests | import requests | ||||
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple | from typing import Dict, Optional, Tuple | ||||
from swh.model.hashutil import MultiHash, HASH_BLOCK_SIZE | from swh.model.hashutil import MultiHash, HASH_BLOCK_SIZE | ||||
from swh.model.model import Person | from swh.model.model import Person | ||||
from swh.loader.package import DEFAULT_PARAMS | from swh.loader.package import DEFAULT_PARAMS | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | ) -> Tuple[str, Dict]: | ||||
return filepath, extrinsic_metadata | return filepath, extrinsic_metadata | ||||
def release_name(version: str, filename: Optional[str] = None) -> str: | def release_name(version: str, filename: Optional[str] = None) -> str: | ||||
if filename: | if filename: | ||||
return "releases/%s/%s" % (version, filename) | return "releases/%s/%s" % (version, filename) | ||||
return "releases/%s" % version | return "releases/%s" % version | ||||
def artifact_identity(d: Mapping[str, Any], id_keys: Sequence[str]) -> List[Any]: | |||||
"""Compute the primary key for a dict using the id_keys as primary key | |||||
composite. | |||||
Args: | |||||
d: A dict entry to compute the primary key on | |||||
id_keys: Sequence of keys to use as primary key | |||||
Returns: | |||||
The identity for that dict entry | |||||
""" | |||||
return [d.get(k) for k in id_keys] |