Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/converters.py
# Copyright (C) 2015 The Software Heritage developers | # Copyright (C) 2015 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 datetime | import datetime | ||||
from swh.core.utils import decode_with_escape, encode_with_unescape | from swh.core.utils import decode_with_escape, encode_with_unescape | ||||
from swh.model import identifiers | from swh.model import identifiers | ||||
from swh.model.hashutil import MultiHash | |||||
DEFAULT_AUTHOR = { | DEFAULT_AUTHOR = { | ||||
'fullname': None, | 'fullname': None, | ||||
'name': None, | 'name': None, | ||||
'email': None, | 'email': None, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Lines | ret = { | ||||
'target': db_release['target'], | 'target': db_release['target'], | ||||
'target_type': db_release['target_type'], | 'target_type': db_release['target_type'], | ||||
} | } | ||||
if 'object_id' in db_release: | if 'object_id' in db_release: | ||||
ret['object_id'] = db_release['object_id'] | ret['object_id'] = db_release['object_id'] | ||||
return ret | return ret | ||||
def origin_url_to_sha1(origin_url): | |||||
"""Convert an origin URL to a sha1. Encodes URL to utf-8.""" | |||||
return MultiHash.from_data( | |||||
origin_url.encode('utf-8'), {'sha1'} | |||||
).digest()['sha1'] |