Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/utils.py
# Copyright (C) 2016 The Software Heritage developers | # Copyright (C) 2016-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 errno | import errno | ||||
import os | import os | ||||
import tempfile | import tempfile | ||||
import shutil | import shutil | ||||
from dateutil import parser | from dateutil import parser | ||||
from subprocess import PIPE, Popen, call | from subprocess import PIPE, Popen, call | ||||
from swh.model.model import Optional, Timestamp | |||||
def strdate_to_timestamp(strdate): | |||||
def strdate_to_timestamp(strdate: Optional[str]) -> Timestamp: | |||||
"""Convert a string date to an int timestamp. | """Convert a string date to an int timestamp. | ||||
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' | 'YYYY-mm-DDTHH:MM:SS.800722Z' | ||||
Returns: | Returns: | ||||
A couple of integers: seconds, microseconds | A couple of integers: seconds, microseconds | ||||
""" | """ | ||||
if strdate: | if strdate: | ||||
# TODO: Migrate to iso8601 if possible | |||||
dt = parser.parse(strdate) | dt = parser.parse(strdate) | ||||
olasd: Can we move that to iso8601? | |||||
Done Inline ActionsYes, but i'm pretty sure the input is not always iso8601... ardumont: Yes, but i'm pretty sure the input is not always iso8601...
Well, now we have sentry that can… | |||||
Not Done Inline ActionsThe tests you've introduced, and the documentation of this function, are all iso8601, hence my comment :) olasd: The tests you've introduced, and the documentation of this function, are all iso8601, hence my… | |||||
ts = { | ts = { | ||||
'seconds': int(dt.timestamp()), | 'seconds': int(dt.timestamp()), | ||||
'microseconds': dt.microsecond, | 'microseconds': dt.microsecond, | ||||
} | } | ||||
else: # epoch | else: # epoch | ||||
ts = {'seconds': 0, 'microseconds': 0} | ts = {'seconds': 0, 'microseconds': 0} | ||||
return ts | return Timestamp.from_dict(ts) | ||||
class OutputStream: | class OutputStream: | ||||
"""Helper class to read lines from a program output while | """Helper class to read lines from a program output while | ||||
it is running | it is running | ||||
Args: | Args: | ||||
fileno (int): File descriptor of a program output stream | fileno (int): File descriptor of a program output stream | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |
Can we move that to iso8601?