Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/converters.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 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 typing import Dict, Optional, Sequence, Tuple | from typing import Dict, Optional, Sequence, Tuple | ||||
import dateutil | import iso8601 | ||||
from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone | from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone | ||||
def svn_date_to_swh_date(strdate: Optional[str]) -> TimestampWithTimezone: | def svn_date_to_swh_date(strdate: Optional[bytes]) -> TimestampWithTimezone: | ||||
"""Convert a string date to an swh one. | """Convert a string date to an swh one. | ||||
Args: | Args: | ||||
strdate: A string representing a date with format like | strdate: A string representing a date with format like | ||||
'YYYY-mm-DDTHH:MM:SS.800722Z' | ``b'YYYY-mm-DDTHH:MM:SS.800722Z'`` | ||||
Returns: | Returns: | ||||
An swh date format | An swh date format | ||||
""" | """ | ||||
if not strdate: # either None or empty string | if not strdate: # either None or empty string | ||||
dt = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) | dt = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) | ||||
else: | else: | ||||
# TODO: Migrate to iso8601 if possible | dt = iso8601.parse_date(strdate.decode("ascii")) | ||||
dt = dateutil.parser.parse(strdate) | |||||
assert dt.tzinfo is not None, strdate | assert dt.tzinfo is not None, strdate | ||||
return TimestampWithTimezone.from_datetime(dt) | return TimestampWithTimezone.from_datetime(dt) | ||||
def svn_author_to_swh_person(author: Optional[bytes]) -> Person: | def svn_author_to_swh_person(author: Optional[bytes]) -> Person: | ||||
"""Convert an svn author to an swh person. | """Convert an svn author to an swh person. | ||||
Default policy: No information is added. | Default policy: No information is added. | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |