Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/utils.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-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 iso8601 | import iso8601 | ||||
from types import GeneratorType | from types import GeneratorType | ||||
from swh.model.identifiers import normalize_timestamp | from swh.model.identifiers import normalize_timestamp | ||||
def origin_url_from(deposit): | |||||
"""Given a deposit instance, return the associated origin url. | |||||
This expects a deposit and the associated client to be correctly | |||||
configured. | |||||
Args: | |||||
deposit (Deposit): The deposit from which derives the origin url | |||||
Raises: | |||||
AssertionError if: | |||||
- the client's provider_url field is not configured. | |||||
- the deposit's external_id field is not configured. | |||||
Returns | |||||
The associated origin url | |||||
""" | |||||
external_id = deposit.external_id | |||||
assert external_id is not None | |||||
base_url = deposit.client.provider_url | |||||
assert base_url is not None | |||||
return '%s/%s' % (base_url.rstrip('/'), external_id) | |||||
def merge(*dicts): | def merge(*dicts): | ||||
"""Given an iterator of dicts, merge them losing no information. | """Given an iterator of dicts, merge them losing no information. | ||||
Args: | Args: | ||||
*dicts: arguments are all supposed to be dict to merge into one | *dicts: arguments are all supposed to be dict to merge into one | ||||
Returns: | Returns: | ||||
dict merged without losing information | dict merged without losing information | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |