aquaduct.utils.clui module

Module comprises convieniences functions and definitios for different operations related to command line user interface.

class roman_emulation[source]

Bases: object

toRoman(nr)[source]
emit_message_to_file_in_root_logger(mess)[source]
message_special(mess)[source]
message(mess, cont=False)[source]

Prints message to standard error. If FileHandler is present in the root_logger the same message is appended to the log file.

Parameters:
  • mess (str) – message to print
  • cont (bool) – if set True no new line is printed
class fbm(info, cont=True)[source]

Bases: object

__init__(info, cont=True)[source]
__enter__()[source]
__exit__(typ, value, traceback)[source]
__call__(info)[source]
class tictoc(mess)[source]

Bases: object

__init__(mess)[source]
__enter__()[source]
__exit__(typ, value, traceback)[source]
gregorian_year_in_days = 365.2425

Length of Gregorian year in days. Average value. Source: https://en.wikipedia.org/wiki/Year

smart_time_string(s, rl=0, t=1.1, maximal_length=None, maximal_units=5)[source]

Function transforms time in seconds to nicely formatted string of length defined by maximal_length. Depending on number of seconds time is represented with one or more of the following units:

Unit name Unit abbreviation
seconds s
minutes m
hours h
days d
years y

Maximal number of units used in time string can be set with maximal_units.

Parameters:
  • s (int) – Input time in seconds.
  • rl (int) – Number of units already used for representing time.
  • t (float) – Exces above standard number of current time units.
  • maximal_length (int) – Maximal length of the output string. Must be greater then 0.
  • maximal_units (int) – Maximal number of units used in the output string. Must be greater then 0 and lower then 6.
Returns:

string of nicely formated time

Return type:

str

gsep(sep='-', times=72, length=None)[source]

Generic separator.

Parameters:
  • sep (str) – Element(s) of separator.
  • times (int) – Number of times sep is printed.
  • length (int) – Optional maximal length of output.
Returns:

String separator.

Return type:

str

tsep(line)[source]
Parameters:line (str) – Input line.
Returns:Returns default gsep() of length of line.
underline(line)[source]
Parameters:line (str) – Input line.
Returns:String made by concatenation of line, os.linesep, and output of tsep() called with line.
Return type:str
thead(line)[source]
Parameters:line (str) – Input line.
Returns:String made by concatenation of output of tsep() called with line, line, os.linesep, and again output of tsep() called with line.
Return type:str
class SimpleProgressBar(maxval=None, mess=None)[source]

Bases: object

Simple progress bar displaying progress with percent indicator, progress bar and ETA. Progress is measured by iterations.

Variables:
  • rotate (str) – String comprising characters with frames of a rotating toy.
  • barlenght (int) – Length of progress bar.
  • maxval (int) – maximal number of iterations
  • current (int) – current number of iterations
  • overrun_notice (bool) – if True, overrun above maxval iterations causes insert of newline
  • overrun (bool) – flag of overrun
  • begin (int) – time in seconds at the initialization of the SimpleProgressBar class.
  • tcurrent (int) – time in seconds of current iteration
rotate = '\\|/-'
barlenght = 24
__init__(maxval=None, mess=None)[source]
Parameters:
  • maxval (int) – Maximal number of iterations stored to maxval.
  • mess (str) – Optional message displayed at progress bar initialization.
bar()[source]
ETA()[source]

Returns ETA calculated on the basis of current number of iterations current and current time tcurrent. If number of iterations is 0 returns ?. Time is formated wiht smart_time_string().

Returns:ETA as string.
Return type:str
percent()[source]

Returns float number of precent progress calculated in the basis of current number of iterations current. Should return number between 0 and 100.

Returns:percent progress number
Return type:float
show()[source]

Shows current progress.

If value returned by percent() is =< 100 then progres is printed as percent indicator leaded by ETA calculated by ETA().

If value returned by percent() is > 100 then progress is printed as number of iterations and total time.

Progress bar is writen to standard error.

heartbeat()[source]
next()[source]
update(step)[source]

Updates number of current iterations current by one if step is > 0. Otherwise number of current iterations is not updated. In boths cases time of current iteration tcurrent is updated and show() is called.

Parameters:step (int) – update step
ttime()[source]

Calculates and returns total time string formated with smart_time_string().

Returns:string of total time
Return type:str
finish()[source]

Finishes progress bar. First, update() is called with step = 0. Next message of total time is writen to standard error.

pbar

alias of SimpleProgressBar

get_str_timestamp()[source]
class SimpleTree(name=None, message=None)[source]

Bases: object

__init__(name=None, message=None)[source]
__repr__()[source]
is_leaf()[source]
leafs_names
get_leaf(name)[source]
add_message(message=None, toleaf=None, replace=False)[source]
add_message_to_leaf(message=None, toleaf=None, replace=False)[source]
add_leaf(name=None, message=None, toleaf=None)[source]
add_leaf_to_leaf(name=None, message=None, toleaf=None)[source]
print_simple_tree(st, prefix=None, multiple=False, concise=True)[source]