pcvs.backend.session module

class pcvs.backend.session.Session(date=None, path='.')[source]

Bases: object

Object representing a running validation (detached or not).

Despite the fact it is designed for manage concurrent runs, it takes a callback and can be derived for other needs.

Parameters:
  • _func – user function to be called once the session starts

  • _sid – session id, automatically generated

  • _session_infos – session infos dict

constructor method.

Parameters:
  • date (datetime | None) – the start timestamp

  • path (str) – the build directory

property id: str

Getter to session id.

Returns:

session hash

property infos: dict[str, Any]

Getter to session infos.

Returns:

session infos

load_from(sid, data)[source]

Update the current object with session infos read from global file.

Parameters:
  • sid (str) – session id read from file

  • data (dict[str, Any]) – session infos read from file

Return type:

None

property(kw)[source]

Access specific data from the session stored info session.yml.

Parameters:

kw (str) – the information to retrieve. kw must be a valid key

Return type:

Any

Returns:

the requested session infos if exist

property rc: int

Gett to final RC.

Returns:

rc

register_callback(callback)[source]

Register the callback used as main function once the session is started.

Parameters:

callback (Callable[..., int]) – function to invoke

Return type:

None

run(*args, **kwargs)[source]

Run the session normally, without detaching the focus.

Arguments are user function ones. This function is also in charge of redirecting I/O properly (stdout, file, logs)

Parameters:
  • args – user function positional arguments

  • kwargs – user function keyword-based arguments.

Return type:

str

Returns:

the session ID for this run

run_detached(*args, **kwargs)[source]

Run the session in detached mode.

Arguments are for user function only. :type args: :param args: user function positional arguments :type kwargs: :param kwargs: user function keyword-based arguments.

Return type:

str

Returns:

the Session id created for this run.

property state: SessionState

Getter to session status.

Returns:

session status

class pcvs.backend.session.SessionState(*values)[source]

Bases: IntEnum

Enum of possible Session states.

COMPLETED = 2
ERROR = 3
IN_PROGRESS = 1
WAITING = 0
classmethod from_yaml(constructor, node)[source]

Construct a Session.State from its YAML representation.

Relies on the fact the node contains a ‘Session.State’ tag. :type constructor: Constructor :param constructor: the YAML loader :type node: Any :param node: the YAML representation :rtype: Self :return: The session State as an object

classmethod to_yaml(representer, data)[source]

Convert a Test.State to a valid YAML representation.

A new tag is created: ‘Session.State’ as a scalar (str). :type representer: RoundTripRepresenter :param representer: the YAML dumper object :type data: Self :param data: the object to represent :rtype: Any :return: the YAML representation

pcvs.backend.session.list_alive_sessions()[source]

Load and return the complete dict from session.yml file

Return type:

dict[str, dict]

Returns:

the session dict

pcvs.backend.session.main_detached_session(sid, user_func, *args, **kwargs)[source]

Main function processed when running in detached mode.

This function is called by Session.run_detached() and is launched from cloned process (same global env, new main function).

Raises:

Exception – Any error occurring during the main process is re-raised.

Parameters:
  • sid (str) – the session id

  • user_func (Callable) – the Python function used as the new main()

  • args (tuple) – user_func() arguments

  • kwargs (dict) – user_func() arguments

Return type:

int

Returns:

The return of the user_func function.

pcvs.backend.session.remove_session_from_file(sid)[source]

clear a session from logs.

Parameters:

sid (str) – the session id to remove.

Return type:

bool

Returns:

if the session was successfully removed. (== if the session exist)

pcvs.backend.session.session_file_hash(session_infos)[source]
Return type:

str

pcvs.backend.session.store_session_to_file(infos)[source]

Save a new session into the session file (in HOME dir).

Parameters:

infos (dict) – session infos to store

Raises:

IOError – When the session file can’t be written to disk.

Return type:

str

Returns:

the sid associated to new create session id.

pcvs.backend.session.update_session_from_file(sid, update)[source]

Update data from a running session from the global file.

This only add/replace keys present in argument dict. Other keys remain.

Parameters:
  • sid (str) – the session id

  • update (dict) – the keys to update. If already existing, content is replaced

Return type:

bool

Returns:

if a session file was successfully modify (== if the session exist)