Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/loader.py
Show First 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | Local repository not cleaned up for investigation: %s""", | ||||
def prepare_origin_visit(self): | def prepare_origin_visit(self): | ||||
self.origin = Origin(url=self.origin_url if self.origin_url else self.svn_url) | self.origin = Origin(url=self.origin_url if self.origin_url else self.svn_url) | ||||
def prepare(self): | def prepare(self): | ||||
latest_snapshot_revision = self._latest_snapshot_revision(self.origin_url) | latest_snapshot_revision = self._latest_snapshot_revision(self.origin_url) | ||||
if latest_snapshot_revision: | if latest_snapshot_revision: | ||||
self.latest_snapshot, self.latest_revision = latest_snapshot_revision | self.latest_snapshot, self.latest_revision = latest_snapshot_revision | ||||
local_dirname = tempfile.mkdtemp( | local_dirname = self._create_tmp_dir(self.temp_directory) | ||||
dir=self.temp_directory, | |||||
prefix=TEMPORARY_DIR_PREFIX_PATTERN, | |||||
suffix="-%s" % os.getpid(), | |||||
) | |||||
try: | try: | ||||
self.svnrepo = SvnRepo( | self.svnrepo = SvnRepo( | ||||
self.svn_url, self.origin_url, local_dirname, self.max_content_size | self.svn_url, self.origin_url, local_dirname, self.max_content_size | ||||
) | ) | ||||
except SubversionException as e: | except SubversionException as e: | ||||
error_msgs = [ | error_msgs = [ | ||||
"Unable to connect to a repository at URL", | "Unable to connect to a repository at URL", | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | def post_load(self, success: bool = True) -> None: | ||||
# consistent with the one obtained with a svn export operation. If it is not | # consistent with the one obtained with a svn export operation. If it is not | ||||
# the case, an exception will be raised to report the issue and mark the | # the case, an exception will be raised to report the issue and mark the | ||||
# visit as partial | # visit as partial | ||||
self._check_revision_divergence( | self._check_revision_divergence( | ||||
int(dict(self._last_revision.extra_headers)[b"svn_revision"]), | int(dict(self._last_revision.extra_headers)[b"svn_revision"]), | ||||
self._last_revision.directory, | self._last_revision.directory, | ||||
) | ) | ||||
def _create_tmp_dir(self, root_tmp_dir: str) -> str: | |||||
return tempfile.mkdtemp( | |||||
dir=root_tmp_dir, | |||||
prefix=TEMPORARY_DIR_PREFIX_PATTERN, | |||||
suffix="-%s" % os.getpid(), | |||||
) | |||||
class SvnLoaderFromDumpArchive(SvnLoader): | class SvnLoaderFromDumpArchive(SvnLoader): | ||||
"""Uncompress an archive containing an svn dump, mount the svn dump as a local svn | """Uncompress an archive containing an svn dump, mount the svn dump as a local svn | ||||
repository and load that repository. | repository and load that repository. | ||||
""" | """ | ||||
def __init__( | def __init__( | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | ): | ||||
origin_url=origin_url, | origin_url=origin_url, | ||||
incremental=incremental, | incremental=incremental, | ||||
visit_date=visit_date, | visit_date=visit_date, | ||||
temp_directory=temp_directory, | temp_directory=temp_directory, | ||||
debug=debug, | debug=debug, | ||||
check_revision=check_revision, | check_revision=check_revision, | ||||
max_content_size=max_content_size, | max_content_size=max_content_size, | ||||
) | ) | ||||
self.temp_dir = tempfile.mkdtemp(dir=self.temp_directory) | self.temp_dir = self._create_tmp_dir(self.temp_directory) | ||||
self.repo_path = None | self.repo_path = None | ||||
self.truncated_dump = False | self.truncated_dump = False | ||||
ardumont: since we repeat it at least twice now in that loader, wondering whether we should not wrap this… | |||||
Done Inline Actionsack, will update. anlambert: ack, will update. | |||||
def get_last_loaded_svn_rev(self, svn_url: str) -> int: | def get_last_loaded_svn_rev(self, svn_url: str) -> int: | ||||
"""Check if the svn repository has already been visited and return the last | """Check if the svn repository has already been visited and return the last | ||||
loaded svn revision number or -1 otherwise. | loaded svn revision number or -1 otherwise. | ||||
""" | """ | ||||
origin = list(self.storage.origin_get([svn_url]))[0] | origin = list(self.storage.origin_get([svn_url]))[0] | ||||
if not origin: | if not origin: | ||||
return -1 | return -1 | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |
since we repeat it at least twice now in that loader, wondering whether we should not wrap this in an utility function.