pcvs.helpers.log module

class pcvs.helpers.log.IOManager(verbose=0, enable_unicode=True, length=80, logfile=None, tty=True)[source]

Bases: object

Manager for Input/Output streams.

Contains methods for logging and printing in PCVS. IOManager handles multiple outputs (file + standard output), logging levels (warning, error, info, etc) and pretty banners. Colors are handled by click and color tags are written in files (use less -r).

Parameters
  • special_chars (dict) – dictionary for fancy bullet characters

  • verb_levels (list) – verbosity level (normal, info, debug)

  • color_list (list) – list of colors used by PCVS

avail_chars()[source]

lists allowed bullet characters

Returns

a list of characters

Return type

list

capture_exception(e_type, user_func=None)[source]

wraps functions to capture unhandled exceptions for high-level function not to crash. :param *e_type: errors to be caught

color_list = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'bright_black', 'bright_red', 'bright_green', 'bright_yellow', 'bright_blue', 'bright_magenta', 'bright_cyan', 'bright_white']
debug(msg)[source]

prints a debug message

disable_tty()[source]

disables tty

enable_tty()[source]

enables tty

enable_unicode(e=True)[source]

enables/disables unicode alphabet usage

Parameters

e (bool, optional) – True to enable unicode usage, defaults to True

err(msg)[source]

prints an error message

get_verbosity_str()[source]

[summary]

Returns

[description]

Return type

[type]

has_verb_level(match)[source]

returns true if the verbosity level is activated.

Parameters

match (str or int) – verbosity level to check

Returns

True if “match” verbosity level is supposed to be printed by the IOManager

Return type

bool

info(msg)[source]

prints an info message

property log_filename

getter for logfile path

Returns

logfile path

Return type

str

nimpl(*msg)[source]

prints the “not implemented” error

print(*msg)[source]

prints a raw line. Takes multiple arguments.

print_banner()[source]

prints a large banner

print_header(s, out=True)[source]

prints a header

Parameters
  • s (str) – header content

  • out (bool, optional) – True if the header has to be logged, False if it has to be returned, defaults to True

Returns

header string if out=False, Nothing otherwise

Return type

str

print_item(s, depth=1, out=True, with_bullet=True)[source]

prints an item

Parameters
  • s (str) – item content

  • depth (int, optional) – number of tabulations used for indentation, defaults to 1

  • out (bool, optional) – True if the item has to be logged, False if it has to be returned, defaults to True

  • with_bullet (bool, optional) – True if the item should have a bullet, defaults to True

Returns

item string if out=False, Nothing otherwise

Return type

str

print_job(label, time, name, colorname='red', icon=None)[source]

prints a job description

Parameters
  • label (str) – job label

  • time (float) – time elapsed since the job launch

  • name (str) – name of the job

  • colorname (str, optional) – color of the job log, defaults to “red”

  • icon (str, optional) – bullet, defaults to None

print_n_stop(**kwargs)[source]

prints a message, then exits the program

print_section(s, out=True)[source]

prints a section

Parameters
  • s (str) – content of the section

  • out (bool, optional) – True if the section has to be logged, False if it has to be returned, defaults to True

Returns

section string if out=False, Nothing otherwise

Return type

str

print_short_banner(string=False)[source]

prints a little banner

Parameters

string (bool) – True if the banner has to be returned, False if it has to be logged

set_logfile(enable, logfile=None)[source]

setter for logfile path

Parameters

logfile (str, optional) – logfile name, defaults to None

set_tty(enable)[source]

[summary]

Parameters

enable ([type]) – [description]

special_chars = {'ascii': {'copy': '(c)', 'empty_pg': '-', 'fail': 'X', 'full_pg': '#', 'git': '(git)', 'hdr': '=', 'item': '*', 'none': '-', 'sec': '#', 'sep_h': '-', 'sep_v': ' | ', 'star': '*', 'succ': 'V', 'time': '(time)'}, 'unicode': {'copy': '©', 'empty_pg': '\x1b[90m\x1b[1m○\x1b[0m', 'fail': '✘', 'full_pg': '\x1b[36m\x1b[1m●\x1b[0m', 'git': '⍿', 'hdr': '⎼', 'item': '⟢', 'none': '∅', 'sec': '❖', 'sep_h': '⎼', 'sep_v': ' ', 'star': '★', 'succ': '✔', 'time': '⌚'}}
style(*args, **kwargs)[source]

returns a string style using click

Returns

a string style

Return type

click.style

property tty

getter for tty information

Returns

False if tty not used, 1 if tty used

Return type

bool

utf(k)[source]

returns the corresponding character to a bullet character

Parameters

k (char) – character used as bullet character

Returns

fancy bullet character

Return type

char

verb_levels = [(0, 'normal'), (1, 'info'), (2, 'debug')]
property verbose

getter for verbosity level

Returns

verbosity level (0, 1, 2)

Return type

int

warn(msg)[source]

prints a warning message

write(txt)[source]

print a string.

Parameters

txt (str) – message to be printed

pcvs.helpers.log.init(v=0, e=False, l=100, quiet=False)[source]

initializes a global manager for everyone to use

Parameters
  • v (int, optional) – verbosity level, defaults to 0

  • e (bool, optional) – True to enable unicode alphabet, False to use ascii, defaults to False

  • l (int, optional) – length of the terminal, defaults to 100

  • quiet (bool, optional) – False to write to stdout, defaults to False

pcvs.helpers.log.pretty_print_exception(e: GenericError)[source]

Display exceptions in a fancy way.

Parameters

e (exceptions.GenericError.) – the execption to print

pcvs.helpers.log.progbar(it, print_func=None, man=None, **kargs)[source]

prints a progress bar using click

Parameters
  • it (iterable) – iterable on which the progress bar has to iterate

  • print_func (function, optional) – method used to show the item next to the progress bar, defaults to None

  • man (log.IOManager, optional) – manager used to describe the bullets, defaults to None

Returns

a click progress bar (iterable)

Return type

click.ProgressBar