Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/utils.py
# Copyright (C) 2016-2022 The Software Heritage developers | # Copyright (C) 2016-2022 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 re | import re | ||||
import shutil | import shutil | ||||
from subprocess import PIPE, Popen, call | from subprocess import PIPE, Popen, call, run | ||||
import tempfile | import tempfile | ||||
from typing import Optional, Tuple | from typing import Optional, Tuple | ||||
from urllib.parse import quote, urlparse, urlunparse | from urllib.parse import quote, urlparse, urlunparse | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
class OutputStream: | class OutputStream: | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | try: | ||||
if gzip: | if gzip: | ||||
read_dump_cmd = ["gzip", "-dc", dump_path] | read_dump_cmd = ["gzip", "-dc", dump_path] | ||||
with Popen(read_dump_cmd, stdout=PIPE) as dump: | with Popen(read_dump_cmd, stdout=PIPE) as dump: | ||||
# load dump and bypass properties validation as Unicode decoding errors | # load dump and bypass properties validation as Unicode decoding errors | ||||
# are already handled in loader implementation (see _ra_codecs_error_handler | # are already handled in loader implementation (see _ra_codecs_error_handler | ||||
# in ra.py) | # in ra.py) | ||||
cmd = ["svnadmin", "load", "-q", "--bypass-prop-validation", repo_path] | cmd = ["svnadmin", "load", "-q", "--bypass-prop-validation", repo_path] | ||||
r = call(cmd, stdin=dump.stdout) | completed_process = run( | ||||
if r != 0: | cmd, stdin=dump.stdout, capture_output=True, text=True | ||||
) | |||||
if completed_process.returncode != 0: | |||||
raise ValueError( | raise ValueError( | ||||
"Failed to mount the svn dump for project %s" % project_name | f"Failed to mount the svn dump for project {project_name}\n" | ||||
+ completed_process.stderr | |||||
) | ) | ||||
return temp_dir, repo_path | return temp_dir, repo_path | ||||
except Exception as e: | except Exception as e: | ||||
shutil.rmtree(temp_dir) | shutil.rmtree(temp_dir) | ||||
raise e | raise e | ||||
finally: | finally: | ||||
if cleanup_dump: | if cleanup_dump: | ||||
try: | try: | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |