Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/utils.py
# Copyright (C) 2016-2021 The Software Heritage developers | # Copyright (C) 2016-2021 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 logging | import logging | ||||
import os | import os | ||||
import shutil | import shutil | ||||
from subprocess import PIPE, Popen, call | from subprocess import PIPE, Popen, call | ||||
import tempfile | import tempfile | ||||
from typing import Tuple | from typing import Optional, Tuple | ||||
from dateutil import parser | |||||
from swh.model.model import Optional, Timestamp | |||||
logger = logging.getLogger(__name__) | 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: | 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 | ||||
opened in text mode | opened in text mode | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |