Common Code#

Common classes and values used around relenv

exception relenv.common.RelenvException#

Base class for exeptions generated from relenv

class relenv.common.WorkDirs(root)#

Simple class used to hold references to working directories relenv uses relative to a given root.

Parameters

root (str) – The root of the working directories tree

relenv.common.archived_build(triplet=None)#

Finds a the location of an archived build.

Parameters

triplet (str) – The build triplet to find

Returns

The location of the archived build

Return type

pathlib.Path

relenv.common.download_url(url, dest, verbose=True)#

Download the url to the provided destination. This method assumes the last part of the url is a filename. (https://foo.com/bar/myfile.tar.xz)

Parameters
  • url (str) – The url to download

  • dest (str) – Where to download the url to

  • verbose (bool) – Print download url and destination to stdout

Raises

urllib.error.HTTPError – If the url was unable to be downloaded

Returns

The path to the downloaded content

Return type

str

relenv.common.extract_archive(to_dir, archive)#

Extract an archive to a specific location

Parameters
  • to_dir (str) – The directory to extract to

  • archive (str) – The archive to extract

relenv.common.get_download_location(url, dest)#

Get the full path to where the url will be downloaded to.

Parameters
  • url (str) – The url to donwload

  • dest (str) – Where to download the url to

Returns

The path to where the url will be downloaded to

Return type

str

relenv.common.get_toolchain(arch=None, root=None)#

Get a the toolchain directory, specific to the arch if supplied.

Parameters
  • arch (str) – The architecture to get the toolchain for

  • root (str) – The root of the relenv working directories to search in

Returns

The directory holding the toolchain

Return type

pathlib.Path

relenv.common.get_triplet(machine=None, plat=None)#

Get the target triplet for the specfied machine and platform.

If any of the args are None, it will try to deduce what they should be.

Parameters
  • machine (str) – The machine for the triplet

  • plat (str) – The platform for the triplet

Raises

RelenvException – If the platform is unknown

Returns

The target triplet

Return type

str

relenv.common.runcmd(*args, **kwargs)#

Run the provided command, raising an Exception when the command finishes with a non zero exit code. Arguments are passed through to subprocess.run

Returns

The process result

Return type

subprocess.CompletedProcess

Raises

RelenvException – If the command finishes with a non zero exit code

relenv.common.work_dir(name, root=None)#

Get the absolute path to the relenv working directory of the given name.

Parameters
  • name (str) – The name of the directory

  • root (str) – The root directory that this working directory will be relative to

Returns

An absolute path to the requested relenv working directory

Return type

pathlib.Path

relenv.common.work_dirs(root=None)#

Returns a WorkDirs instance based on the given root.

Parameters

root (str) – The desired root of relenv’s working directories

Returns

A WorkDirs instance based on the given root

Return type

relenv.common.WorkDirs

relenv.common.work_root(root=None)#

Get the root directory that all other relenv working directories should be based on.

Parameters

root (str) – An explicitly requested root directory

Returns

An absolute path to the relenv root working directory

Return type

pathlib.Path