Page MenuHomeSoftware Heritage

D6911.id25054.diff
No OneTemporary

D6911.id25054.diff

diff --git a/swh/loader/svn/converters.py b/swh/loader/svn/converters.py
--- a/swh/loader/svn/converters.py
+++ b/swh/loader/svn/converters.py
@@ -3,27 +3,32 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+import datetime
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:
"""Convert a string date to an swh one.
Args:
- strdate: A string formatted for .utils.strdate_to_timestamp
- to do its jobs
+ strdate: A string representing a date with format like
+ 'YYYY-mm-DDTHH:MM:SS.800722Z'
Returns:
An swh date format
"""
- return TimestampWithTimezone(
- timestamp=strdate_to_timestamp(strdate), offset=0, negative_utc=False,
- )
+ if not strdate: # either None or empty string
+ dt = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
+ else:
+ # TODO: Migrate to iso8601 if possible
+ 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:
diff --git a/swh/loader/svn/tests/test_utils.py b/swh/loader/svn/tests/test_utils.py
--- a/swh/loader/svn/tests/test_utils.py
+++ b/swh/loader/svn/tests/test_utils.py
@@ -10,7 +10,6 @@
from subprocess import Popen
from swh.loader.svn import utils
-from swh.model.model import Timestamp
def test_outputstream():
@@ -29,22 +28,6 @@
assert lines == ["foo", "bar", "baz"]
-def test_strdate_to_timestamp():
- """Formatted string date should be converted in timestamp."""
- actual_ts = utils.strdate_to_timestamp("2011-05-31T06:04:39.800722Z")
- assert actual_ts == Timestamp(seconds=1306821879, microseconds=800722)
-
- actual_ts = utils.strdate_to_timestamp("2011-05-31T06:03:39.123450Z")
- assert actual_ts == Timestamp(seconds=1306821819, microseconds=123450)
-
-
-def test_strdate_to_timestamp_empty_does_not_break():
- """Empty or None date should be timestamp 0."""
- default_ts = Timestamp(seconds=0, microseconds=0)
- assert default_ts == utils.strdate_to_timestamp("")
- assert default_ts == utils.strdate_to_timestamp(None)
-
-
def test_init_svn_repo_from_dump(datadir, tmp_path):
"""Mounting svn repository out of a dump is ok"""
dump_name = "penguinsdbtools2018.dump.gz"
diff --git a/swh/loader/svn/utils.py b/swh/loader/svn/utils.py
--- a/swh/loader/svn/utils.py
+++ b/swh/loader/svn/utils.py
@@ -9,38 +9,11 @@
import shutil
from subprocess import PIPE, Popen, call
import tempfile
-from typing import Tuple
-
-from dateutil import parser
-
-from swh.model.model import Optional, Timestamp
+from typing import Optional, Tuple
logger = logging.getLogger(__name__)
-def strdate_to_timestamp(strdate: Optional[str]) -> Timestamp:
- """Convert a string date to an int timestamp.
-
- Args:
- strdate: A string representing a date with format like
- 'YYYY-mm-DDTHH:MM:SS.800722Z'
-
- Returns:
- A couple of integers: seconds, microseconds
-
- """
- if strdate:
- # TODO: Migrate to iso8601 if possible
- dt = parser.parse(strdate)
- ts = {
- "seconds": int(dt.timestamp()),
- "microseconds": dt.microsecond,
- }
- else: # epoch
- ts = {"seconds": 0, "microseconds": 0}
- return Timestamp.from_dict(ts)
-
-
class OutputStream:
"""Helper class to read lines from a program output while
it is running

File Metadata

Mime Type
text/plain
Expires
Sun, Aug 17, 8:47 PM (12 h, 54 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218925

Event Timeline