aquaduct.utils.clui module¶
Module comprises convieniences functions and definitios for different operations related to command line user interface.
-
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:
-
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:
-
gsep
(sep=’-‘, times=72, length=None)[source]¶ Generic separator.
Parameters: Returns: String separator.
Return type:
-
tsep
(line)[source]¶ Parameters: line (str) – Input line. Returns: Returns default gsep()
of length ofline
.
-
underline
(line)[source]¶ Parameters: line (str) – Input line. Returns: String made by concatenation of line
,os.linesep
, and output oftsep()
called withline
.Return type: str
-
thead
(line)[source]¶ Parameters: line (str) – Input line. Returns: String made by concatenation of output of tsep()
called withline
,line
,os.linesep
, and again output oftsep()
called withline
.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¶
-
ETA
()[source]¶ Returns ETA calculated on the basis of current number of iterations
current
and current timetcurrent
. If number of iterations is 0 returns?
. Time is formated wihtsmart_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 byETA()
.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.
-
update
(step)[source]¶ Updates number of current iterations
current
by one ifstep
is > 0. Otherwise number of current iterations is not updated. In boths cases time of current iterationtcurrent
is updated andshow()
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
-
pbar
¶ alias of
SimpleProgressBar