pcvs.helpers.utils module
- class pcvs.helpers.utils.Program(cmd=None)[source]
Bases:
object
Simple class to encapsulate process management.
This is better and should be preferred as importing subprocess everywhere.
- property exception
Getter, raised exception (for any reason)
- Returns:
an Exception-derived object
- Return type:
- property rc
Getter, effective return code.
- Returns:
return code
- Return type:
integer
- run(input='', shell=False, timeout=0)[source]
Run the given program and capture I/Os
- Parameters:
input (str) – raw data to be used as stdin
shell (boolean) – is the provided command to be run within a shell
timeout (positive integer) – allowed time before automatically killing the process
- Returns:
zero if the process started successfully, non-zero otherwise.
- Return type:
integer
- pcvs.helpers.utils.check_valid_program(p, succ=None, fail=None, raise_if_fail=True)[source]
Check if p is a valid program, using the
which
function.- Parameters:
- Raises:
RunException.ProgramError – p is not a valid program
- Returns:
True if p is a program, False otherwise
- Return type:
- pcvs.helpers.utils.check_valid_scope(s)[source]
Check if argument is a valid scope (local, user, global).
- Parameters:
s (str) – scope to check
- Raises:
CommonException.BadTokenError – the argument is not a valid scope
- pcvs.helpers.utils.create_or_clean_path(prefix, dir=False)[source]
Create a path or cleans it if it already exists.
- pcvs.helpers.utils.cwd(path)[source]
Change the working directory.
- Parameters:
path (os.path, str) – new working directory
- pcvs.helpers.utils.extract_infos_from_token(s, pair='right', single='right', maxsplit=3)[source]
Extract fields from tokens (a, b, c) from user’s string.
- Parameters:
- Returns:
3-string-tuple: mapping (scope, kind, name), any of them may be null
- Return type:
- pcvs.helpers.utils.find_buildir_from_prefix(path)[source]
Find the build directory from the
path
prefix.- Parameters:
path (os.path, str) – path to search the build directory from
- Raises:
CommonException.NotFoundError – the build directory is not found
- Returns:
the path of the build directory
- Return type:
os.path
- pcvs.helpers.utils.get_lock_owner(f)[source]
The lock file will contain the process ID owning the lock. This function returns it.
- 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
- pcvs.helpers.utils.lock_file(f, reentrant=False, timeout=None, force=True)[source]
Try to lock a directory.
- Parameters:
- Raises:
LockException.TimeoutError – timeout is reached before the directory is locked
- Returns:
True if the file is reached, False otherwise
- Return type:
- pcvs.helpers.utils.program_timeout(sig, frame)[source]
Timeout handler, called when a SIGALRM is received.
- Parameters:
sig (int) – signal number
frame – the callee (unused)
- Raises:
CommonException.TimeoutError – timeout is reached
- pcvs.helpers.utils.set_local_path(path)[source]
Set the prefix for the
local
storage.- Parameters:
path (os.path) – path of the
local
storage
- pcvs.helpers.utils.start_autokill(timeout=None)[source]
Initialize a new time to automatically stop the current process once time is expired.
- Parameters:
timeout (positive integer) – value in seconds before the autokill will be raised
- pcvs.helpers.utils.storage_order()[source]
Return scopes in order of searching.
- Returns:
a list of scopes
- Return type:
- 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.