for any info/changes follow me: @nickmilon

Hellas.Delphi module

This module contains classes and functions useful for pretty/color printing to console or logs it is named after Delphi the famous city where ancient Oracle of Delphi was located.

class Hellas.Delphi.Color[source]

Bases: object

some basic color handling for printing in color

Warning

This class will NOT work in windows OS unless complemented by library colorama

Example:
>>> cl = Color()
>>> cl.printc("this is red", "red")
colors = {'blue_br': (1, 34), 'normal': (0,), 'yellow': (0, 33), 'cyan': (0, 36), 'cyan_br': (1, 36), 'red_br': (1, 31), 'yellow_br': (1, 33), 'blue': (0, 34), 'gray_br': (0, 37), 'green_br': (1, 32), 'purple_br': (1, 35), 'gray_dk': (1, 30), 'purple': (0, 35), 'black': (0, 30), 'green': (0, 32), 'white': (1, 37), 'red': (0, 31)}
classmethod help()[source]

prints named colors

classmethod color_code(color)[source]

returns code for color :param tuple_or_code color: either a tuple as in colors.values or a string key to colors dictionary

classmethod color_switch_txt(color=(0, 31))[source]
classmethod color_txt(txt='', color=None)[source]
classmethod printc(txt, color=(0, 31))[source]

Print in color.

classmethod color_switch_print(color)[source]
class Hellas.Delphi.ColoredFormatter(fmt=None, datefmt=None)[source]

Bases: logging.Formatter

a logging formatter for printing in color works only in linux on an non linux system it returns plain text

color = <Hellas.Delphi.Color object>
clr_name = {'blue_br': (1, 34), 'normal': (0,), 'yellow': (0, 33), 'cyan': (0, 36), 'cyan_br': (1, 36), 'red_br': (1, 31), 'yellow_br': (1, 33), 'blue': (0, 34), 'gray_br': (0, 37), 'green_br': (1, 32), 'purple_br': (1, 35), 'gray_dk': (1, 30), 'purple': (0, 35), 'black': (0, 30), 'green': (0, 32), 'white': (1, 37), 'red': (0, 31)}
format(record)[source]
Hellas.Delphi.logging_format(verbose=2, style='txt')[source]

returns a format :parameter:

  • str style: defines style of output format (defaults to txt)
    • txt plain text
    • dict like text which can be casted to dict
class Hellas.Delphi.LoggingColorHandler(level=0, verbose=2)[source]

Bases: logging.StreamHandler

__init__(level=0, verbose=2)[source]
Hellas.Delphi.logger_multi(loggerName='', level_consol=10, level_file=10, filename=None, verbose=1, when='midnight', interval=1, backupCount=7)[source]
a logger that logs to file as well as as screen

see http://pythonhosted.org//logutils/ http://plumberjack.blogspot.gr/2010/10/supporting-alternative-formatting.html

Todo:
  • use new style formating for python > v3 i.e formatter = logging.Formatter(frmt.replace(” ”, “”), style=’{‘) #frmtC = frmt.translate(dict((ord(c), ‘’) for c in “’{},”))
Parameters:

see

Example:
>>> LOG = logger_double('', level_consol=logging.DEBUG, level_file=logging.DEBUG, verbose=3, filename="~

.log”)

Hellas.Delphi.auto_retry(exception_t, retries=3, sleepSeconds=1, back_of_factor=1, logger_fun=None)[source]

a generic auto-retry function @wrapper

Parameters:
  • exception_t (Exception) – exception (or tuple of exceptions) to auto retry
  • retries (int) – max retries before it raises the Exception (defaults to 3)
  • sleepSeconds (int_or_float) – base sleep seconds between retries (defaults to 1)
  • back_of_factor (int) – factor to back off on each retry (defaults to 1)
  • logger_fun (int) – loggerFun i.e. logger.info to log on each retry (defaults to None)
Hellas.Delphi.pp_obj(obj, indent=4, sort_keys=False, prn=True, default=None)[source]

pretty prints a (list tuple or dict) object