swh.loader.svn.utils module#

class swh.loader.svn.utils.OutputStream(fileno)[source]#

Bases: object

Helper class to read lines from a program output while it is running

Parameters:

fileno (int) – File descriptor of a program output stream opened in text mode

read_lines()[source]#

Read available lines from the output stream and return them.

Returns:

A tuple whose first member is the read

lines and second member a boolean indicating if there are still some other lines available to read.

Return type:

Tuple[List[str], bool]

swh.loader.svn.utils.init_svn_repo_from_dump(dump_path: str, prefix: str | None = None, suffix: str | None = None, root_dir: str = '/tmp', gzip: bool = False, cleanup_dump: bool = True, max_rev: int = -1) Tuple[str, str][source]#

Given a path to a svn dump, initialize an svn repository with the content of said dump.

Parameters:
  • dump_path – The dump to the path

  • prefix – optional prefix file name for the working directory

  • suffix – optional suffix file name for the working directory

  • root_dir – the root directory where the working directory is created

  • gzip – Boolean to determine whether we treat the dump as compressed or not.

  • cleanup_dump – Whether we want this function call to clean up the dump at the end of the repository initialization.

Raises:
  • ValueError in case of failure to run the command to uncompress and load the

  • dump.

Returns:

  • temporary folder: containing the mounted repository

  • repo_path: path to the mounted repository inside the temporary folder

Return type:

A tuple

swh.loader.svn.utils.init_svn_repo_from_archive_dump(archive_path: str, prefix: str | None = None, suffix: str | None = None, root_dir: str = '/tmp', cleanup_dump: bool = True) Tuple[str, str][source]#

Given a path to an archive containing an svn dump, initializes an svn repository with the content of the uncompressed dump.

Parameters:
  • archive_path – The archive svn dump path

  • prefix – optional prefix file name for the working directory

  • suffix – optional suffix file name for the working directory

  • root_dir – the root directory where the working directory is created

  • gzip – Boolean to determine whether we treat the dump as compressed or not.

  • cleanup_dump – Whether we want this function call to clean up the dump at the end of the repository initialization.

Raises:
  • ValueError in case of failure to run the command to uncompress

  • and load the dump.

Returns:

  • temporary folder: containing the mounted repository

  • repo_path: path to the mounted repository inside the

    temporary folder

Return type:

A tuple

swh.loader.svn.utils.svn_urljoin(base_url: str, *args) str[source]#

Join a base URL and a list of paths in a SVN way.

For instance:

Parameters:
  • base_url – Base URL to join paths with

  • args – path components

Returns:

The joined URL

class swh.loader.svn.utils.ExternalDefinition(path: str, url: str, revision: int | None, peg_revision: int | None, relative_url: bool, legacy_format: bool)[source]#

Bases: object

path: str#
url: str#
revision: int | None#
peg_revision: int | None#
relative_url: bool#
legacy_format: bool#
swh.loader.svn.utils.parse_external_definition(external: str, dir_path: str, repo_url: str) ExternalDefinition[source]#

Parse a subversion external definition.

Parameters:
  • external – an external definition, extracted from the lines split of a svn:externals property value

  • dir_path – The path of the directory in the subversion repository where the svn:externals property was set

  • repo_url – URL of the subversion repository

Returns:

  • path relative to dir_path where the external should be exported

  • URL of the external to export

  • optional revision of the external to export

  • optional peg revision of the external to export

  • boolean indicating if the external URL is relative to the repository URL and targets a path not in the repository

Return type:

A tuple with the following members

swh.loader.svn.utils.is_recursive_external(origin_url: str, dir_path: str, external_path: str, external_url: str) bool[source]#

Check if an external definition can lead to a recursive subversion export operation (https://issues.apache.org/jira/browse/SVN-1703).

Parameters:
  • origin_url – repository URL

  • dir_path – path of the directory where external is defined

  • external_path – path of the external relative to the directory

  • external_url – external URL

Returns:

Whether the external definition is recursive

swh.loader.svn.utils.get_head_revision_at_date(svn_url: str, date: datetime) int[source]#

Get HEAD revision for repository at given date.

This function wraps calls to swh.loader.svn.svn_repo.SvnRepo.get_head_revision_at_date() and put result in cache.

Parameters:
  • svn_url – URL of subversion repository

  • date – the reference date

Returns:

the revision number of the HEAD revision at that date

Raises:
  • SubversionException – repository URL is not valid

  • ValueError – first revision date is greater than given date

swh.loader.svn.utils.get_repo_root_url(svn_url)[source]#

Get root URL for a repository.

Suversion URL might target a sub-project in a repository. That function computes the root URL of the repository and put result in cache.

Parameters:

svn_url – URL of subversion repository

Returns:

the root URL of the repository

Raises:

SubversionException – subversion URL is not valid

swh.loader.svn.utils.quote_svn_url(url: str) str[source]#

Quote Subversion URL with special characters in it for subversion operations involving URLs (export for instance) to succeed.