pcvs.helpers.utils module
- 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
whichfunction.- Parameters:
p (
str) – program to checksucc (
Optional[Callable]) – function to call in case of success, defaults to Nonefail (
Optional[Callable]) – function to call in case of failure, defaults to Noneraise_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_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 createdirectory (
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
pathprefix.- 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.lock_file(f, reentrant=False, timeout=None, force=True)[source]
Try to lock a directory.
- Parameters:
f (
str) – name of lockreentrant (
bool) – True if this process may have locked this file before, defaults to Falsetimeout (
int|None) – time before timeout, defaults to Noneforce (
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 numberft (
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.