pcvs.helpers.utils module

pcvs.helpers.utils.check_is_archive(f)[source]
Return type:

bool

pcvs.helpers.utils.check_is_build_or_archive(x)[source]
Return type:

bool

pcvs.helpers.utils.check_is_buildir(p)[source]
Return type:

bool

pcvs.helpers.utils.check_valid_program(p, succ=None, fail=None, raise_on_fail=True)[source]

Check if p is a valid program, using the which function.

Parameters:
  • p (str) – program to check

  • succ (Optional[Callable]) – function to call in case of success, defaults to None

  • fail (Optional[Callable]) – function to call in case of failure, defaults to None

  • raise_on_fail (bool) – Raise an exception in case of failure, defaults to True

Raises:

RunException.ProgramError – p is not a valid program

Return type:

bool

Returns:

True if p is a program, False otherwise

# noqa: DAR401 # noqa: DAR402

pcvs.helpers.utils.copy_file(src, dest)[source]

Copy a source file into a destination directory.

Parameters:
  • src (str) – source file to copy.

  • dest (str) – destination directory, may not exist yet.

Return type:

None

pcvs.helpers.utils.create_home_dir()[source]

Create a home directory

Return type:

None

pcvs.helpers.utils.create_or_clean_path(prefix, directory=False)[source]

Create a path or cleans it if it already exists.

Parameters:
  • prefix (str) – prefix of the path to create

  • directory (bool) – True if the path is a directory, defaults to False

Return type:

None

pcvs.helpers.utils.cwd(path)[source]

Change the working directory.

Parameters:

path (str) – new working directory

Yield:

The new current working directory.

Return type:

Iterator[str]

pcvs.helpers.utils.find_buildir_from_prefix(path)[source]

Find the build directory from the path prefix.

Parameters:

path (str) – path to search the build directory from

Raises:

CommonException.NotFoundError – the build directory is not found

Return type:

str

Returns:

the path of the build directory

# noqa: DAR401 # noqa: DAR402

pcvs.helpers.utils.get_lock_owner(f)[source]

The lock file will contain the process ID owning the lock. This function returns it.

Parameters:

f (str) – the original file to mutex

Return type:

tuple[str, int]

Returns:

the process ID

pcvs.helpers.utils.get_lockfile_name(f)[source]

From a file to mutex, return the file lock name associated with it.

For instance for /a/b.yml, the lock file name will be /a/.b.yml.lck

Parameters:

f (str) – the file to mutex

Return type:

str

Returns:

The full path to the file.

pcvs.helpers.utils.is_locked(f)[source]

Is the given file locked somewhere else ?

Parameters:

f (str) – the file to test

Return type:

bool

Returns:

a boolean indicating whether the lock is hold or not.

pcvs.helpers.utils.list_valid_archive_in_dir(p)[source]
Return type:

list[str]

pcvs.helpers.utils.list_valid_buildirs_in_dir(p)[source]
Return type:

list[str]

pcvs.helpers.utils.lock_file(f, reentrant=False, timeout=None, force=True)[source]

Try to lock a directory.

Parameters:
  • f (str) – name of lock

  • reentrant (bool) – True if this process may have locked this file before, defaults to False

  • timeout (int | None) – time before timeout, defaults to None

  • force (bool) – Unlock the file if it is locked.

Raises:

CommonException.TimeoutError – timeout is reached before the directory is locked

Return type:

bool

Returns:

True if the file is reached, False otherwise

# noqa: DAR401 # noqa: DAR402

pcvs.helpers.utils.program_timeout(sig, ft)[source]

Timeout handler, called when a SIGALRM is received.

Parameters:
  • sig (int) – signal number

  • ft (FrameType | None) – frame type

Raises:

CommonException.TimeoutError – timeout is reached

Return type:

None

# noqa: DAR401 # noqa: DAR402

pcvs.helpers.utils.start_autokill(timeout=None)[source]

Initialize a new time to automatically stop the current process once time is expired.

Parameters:

timeout (int | None) – value in seconds before the autokill will be raised

Return type:

None

pcvs.helpers.utils.str_dict_as_envvar(d)[source]

Convert a dict to a list of shell-compliant variable strings.

The final result is a regular multiline str, each line being an entry.

Parameters:

d (dict[str, str]) – the dict containing env vars to serialize

Return type:

str

Returns:

the str, containing multiple lines, each of them being a var.

pcvs.helpers.utils.trylock_file(f, reentrant=False)[source]

Try to lock a file (used in lock_file).

Parameters:
  • f (str) – name of lock

  • reentrant (bool) – True if this process may have locked this file before, defaults to False

Return type:

bool

Returns:

True if the file is reached, False otherwise

pcvs.helpers.utils.unlock_file(f)[source]

Remove lock from a directory.

Parameters:

f (str) – file locking the directory

Return type:

None