swh.lister.gnu.tree module#

class swh.lister.gnu.tree.GNUTree(url: str)[source]#

Bases: object

Gnu Tree’s representation

property projects: Mapping[str, Any]#
property artifacts: Mapping[str, Any]#
swh.lister.gnu.tree.find_artifacts(filesystem: List[Mapping[str, Any]], url: str) List[Mapping[str, Any]][source]#

Recursively list artifacts present in the folder and subfolders for a particular package url.

Parameters:
  • filesystem – File structure of the package root directory. This is a list of Dict representing either file or directory information as dict (keys: name, size, time, type).

  • url – URL of the corresponding package

Returns

List of tarball urls and their associated metadata (time, length, etc…). For example:

[
    {
        'url': 'https://ftp.gnu.org/gnu/3dldf/3DLDF-1.1.3.tar.gz',
        'time': 1071002600,
        'filename': '3DLDF-1.1.3.tar.gz',
        'version': '1.1.3',
        'length': 543
    },
    {
        'url': 'https://ftp.gnu.org/gnu/3dldf/3DLDF-1.1.4.tar.gz',
        'time': 1071078759,
        'filename: '3DLDF-1.1.4.tar.gz',
        'version': '1.1.4',
        'length': 456
    },
    {
        'url': 'https://ftp.gnu.org/gnu/3dldf/3DLDF-1.1.5.tar.gz',
        'time': 1074278633,
        'filename': '3DLDF-1.1.5.tar.gz',
        'version': '1.1.5'
        'length': 251
    },
    ...
]
swh.lister.gnu.tree.check_filename_is_archive(filename: str) bool[source]#

Check for the extension of the file, if the file is of zip format of .tar.x format, where x could be anything, then returns true.

Parameters:

filename – name of the file for which the extensions is needs to be checked.

Returns:

Whether filename is an archive or not

Example:

>>> check_filename_is_archive('abc.zip')
True
>>> check_filename_is_archive('abc.tar.gz')
True
>>> check_filename_is_archive('bac.tar')
True
>>> check_filename_is_archive('abc.tar.gz.sig')
False
>>> check_filename_is_archive('foobar.tar.')
False
swh.lister.gnu.tree.get_version(uri: str) str[source]#

Extract branch name from tarball uri

Parameters:

uri (str) – Tarball URI

Returns:

Version detected

Example

>>> uri = 'https://ftp.gnu.org/gnu/8sync/8sync-0.2.0.tar.gz'
>>> get_version(uri)
'0.2.0'
>>> uri = '8sync-0.3.0.tar.gz'
>>> get_version(uri)
'0.3.0'
swh.lister.gnu.tree.load_raw_data(url: str) Sequence[Mapping][source]#

Load the raw json from the tree.json.gz

Parameters:

url – Tree.json.gz url or path

Returns:

The raw json list

swh.lister.gnu.tree.format_date(timestamp: str) str[source]#

Format a string timestamp to an isoformat string