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 | |||||
from typing import Dict, Optional, Sequence, Tuple | from typing import Dict, Optional, Sequence, Tuple | ||||
from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone | import dateutil | ||||
from .utils import strdate_to_timestamp | 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[str]) -> TimestampWithTimezone: | ||||
"""Convert a string date to an swh one. | """Convert a string date to an swh one. | ||||
Args: | Args: | ||||
strdate: A string formatted for .utils.strdate_to_timestamp | strdate: A string representing a date with format like | ||||
to do its jobs | 'YYYY-mm-DDTHH:MM:SS.800722Z' | ||||
Returns: | Returns: | ||||
An swh date format | An swh date format | ||||
""" | """ | ||||
return TimestampWithTimezone( | if not strdate: # either None or empty string | ||||
timestamp=strdate_to_timestamp(strdate), offset=0, negative_utc=False, | dt = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) | ||||
) | else: | ||||
# TODO: Migrate to iso8601 if possible | |||||
anlambert: Yes it is, svn revision dates are stored using ISO8601 format with UTC timezone so you can drop… | |||||
Done Inline Actionsthanks, done in D6912. vlorentz: thanks, done in D6912. | |||||
dt = dateutil.parser.parse(strdate) | |||||
assert dt.tzinfo is not None, strdate | |||||
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. | ||||
Args: | Args: | ||||
author: the svn author (in bytes) | author: the svn author (in bytes) | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
Yes it is, svn revision dates are stored using ISO8601 format with UTC timezone so you can drop the python-dateutil dependency and use iso8601 as in other swh components.