Libraries

This section contains source code documentation of hydratk.lib modules.

array

  • multidict

Multi-level dictionary

class hydratk.lib.array.multidict.MultiDict

Class MultiDict

Inherited from defaultdict

__init__()

Class constructor

Called when object is initialized

Parameters:none
__repr__()

Method overrides __repr__

Parameters:none
Returns:str
__weakref__

list of weak references to the object (if defined)

  • operation

Module for collection operations

hydratk.lib.array.operation.subdict(o_dict, subset)

Method gets sub dictionary

Parameters:
  • o_dict (dict) – original dictionary
  • subset (list) – requested subset key
Returns:

sub dictionary

Return type:

dict

console

  • cmdoptparser

Module for handling commandline input options based on argparse

class hydratk.lib.console.cmdoptparser.CmdOptParser(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)

Class CmdOptParses

Inherited from ArgumentParser

error(message)

Method raises error

Parameters:message (str) – message text
Returns:void
Raises:error – CmdOptParserError
set_default_opt_group(group_name)

Method sets default option group

Parameters:

group_name (str) – group name

Returns:

void

Raises:
  • error – CmdOptParserUndefined
  • error – TypeError
add_opt_group(group_name)

Method adds new option group

Parameters:name (str) – group name
Returns:void
Raises:error – TypeError
_add_opt(option, d_option=None, has_value=False, allow_multiple=False, opt_group='default')

Method adds new option

Parameters:
  • option (obj) – str or list, option
  • d_option (str) – target option
  • has_value (bool) – option value allowed
  • allow_multiple (bool) – multiple option occurences allowed
  • opt_group (str) – option group
Returns:

result

Return type:

bool

Raises:
  • error – CmdOptParserError
  • error – TypeError
add_opt(option, d_option=None, has_value=False, allow_multiple=False, opt_group='default')

Method adds new option

Parameters:
  • option (obj) – str or list, option
  • d_option (str) – target option
  • has_value (bool) – option value allowed
  • allow_multiple (bool) – multiple option occurences allowed
  • opt_group (str) – option group
Returns:

result

Return type:

bool

add_getopt_opt(short_opt, long_opt, opt_map={})

Method adds new option

Parameters:
  • short_opt (list) – short options
  • long_opt (list) – long options
  • opt_map (dict) – option mapping
Returns:

void

parse(opt_group='default', hide_undef=True)

Method adds new option

Parameters:
  • opt_group (str) – option group
  • hide_undef (bool) – hide undefined options
Returns:

options (dict), undefined options

Return type:

tuple

Raises:

error – CmdOptParserUndefined

_strip_opts(opts)

Method strips options without value

Parameters:opts (dict) – options
Returns:stripped options
Return type:dict
opt_defined(option_name)

Method checks if option is defined

Parameters:option_name (str) – option
Returns:result
Return type:bool
get_opt(option_name)

Method gets option

Parameters:option_name (str) – option
Returns:option, when defined bool: False, when not defined
Return type:dict
  • commandlinetool

Useful module for commandline input parameters handling

class hydratk.lib.console.commandlinetool.CommandlineTool

Class CommandLineTool

static set_translator(translator)

Method sets translator

Parameters:translator (obj) – Translator object
Returns:void
Raises:error – ValueError
static set_possible_commands(commands)

Commands setter method

Parameters:commands (list) – Possible commands to use
Returns:void
static set_possible_options(short_opt, long_opt)

Options setter method

Parameters:
  • short_opt (list) – Possible short options to use (getopt format)
  • long_opt (list) – Possible long options to use (getopt format)
Returns:

void

static set_help(title, cp_string, cmd_text, opt_text)

Method creates and returns a formated help text

Parameters:
  • title (str) – Title text
  • cp_string (str) – Copyright string
  • cmd_text (dict) – Text description for specified commands, format is [‘command’ : ‘description’]
  • opt_text (dict) – Text description for specified options, format is [‘short_opt’, ‘long_opt’ : ‘description’]
Returns:

void

static print_short_help()

Method prints short help

Parameters:none
Returns:void
static print_help()

Method prints long help

Parameters:none
Returns:void
static get_command_options_desc(command)

Method creates and returns a formated help text

Parameters:command (str) – command text
Returns:help text
Return type:str
static get_input_command()

Method returns passed action command parameter

Parameters:none
Returns:string command bool: false if no valid command was used
Return type:str
static get_input_options(opt_dict)

Method returns passed action command parameter

Parameters:opt_dict (dict) – options
Returns:result dictionary with short and long input options
Return type:dict
Raises:error – CmdOptParserError
static get_input_option(opt)

Method gets option value

Parameters:opt (str) – option
Returns:result
Return type:bool
Raises:error – CmdOptParserError
static create_short_help()

Method creates short help text

Parameters:none
Returns:help text
Return type:str
static create_help()

Method creates and returns a formated help text

Parameters:none
Returns:result help text
Return type:str
static parse_shell_text(result)

Method adds special characters for shell print

Parameters:result (str) – text
Returns:shell text
Return type:str
  • shellexec

This code is a part of Hydra Toolkit library

hydratk.lib.console.shellexec.shell_exec(command, get_output=False)

Method executes shell command and returns output

Parameters:
  • command (str) – command
  • get_output (bool) – get output
Returns:

int command return code or tuple (return_code, stout, stderr)

cycles

  • loop

Module with functions for cyclic data manipulation and verification

hydratk.lib.cycles.loop.do_until(call, until_call_result, delay=1, until_max_attempts=10, until_duration=None, until_exact_time=None)

Function emulates do..until condition loop

Parameters:
  • call (tuple) – function call in format (callable, param1, param2 ..)
  • until_call_result (mixed) – function call result stop loop value
  • delay (mixed) – int, float, None - delay between cycles
  • until_max_attempts (mixed) – int, None - max call attempts stop loop value
  • until_duration (mixed) – int, float, None - callback repeating duration limit stop loop value
  • until_exact_time (mixed) – int, float, None - callback repeating till exact time stop loop value
Returns:

void

Raises:

error – ValueError

Example:

from hydratk.lib.cycles.loop import do_until
import random

def test(x,y):
    rv = random.randint(x,y)
    print("Random value {0}".format(rv))
    return rv

do_until(
   call               = (test,0,5),
   delay              = None,
   until_call_result  = 1,
   until_max_attempts = 30,
   until_duration     = 10
)

data

  • share

Module with shared objects

class hydratk.lib.data.share.My

Class My

pocket

pocket property getter

piles

piles property getter

pile(pile_id=None)

Method creates new pile

Parameters:pile_id (str) – pile identifier
Returns:Pile
Return type:obj
Raises:error – ValueError
drop_pile(pile_id)

Method drops pile

Parameters:pile_id (str) – pile identifier
Returns:result
Return type:bool
Raises:error – ValueError
__weakref__

list of weak references to the object (if defined)

class hydratk.lib.data.share.Pocket

Class Pocket

show()

Method prints pocket content

Args:

Returns:void
content

content property getter, setter

fill(data={})

Method fills pocket with data

Parameters:data (obj) – data
Returns:void
purge()

Method purges pocket

Parameters:none
Returns:void
__weakref__

list of weak references to the object (if defined)

  • shmm

Module with shared memory tools and managers for parallel data processing and synchronization

database

  • dbo

Complex database interface inspired by PHP PDO

class hydratk.lib.database.dbo.dbo.DBO(dsn, username=None, password=None, options={}, autoconnect=True)

Class DBO

__init__(dsn, username=None, password=None, options={}, autoconnect=True)

Class constructor

Called when object is initialized

Parameters:
  • dsn (str) – format: dbdriver:db_string
  • username (str) – username
  • password (str) – password
  • options (dict) – driver specific options
Returns:

object on success

Return type:

DBO

Raises:

exception – DBOException

driver_name

driver_name property getter

_import_dbo_driver(dbo_driver)

Method import DBO driver

Parameters:dbo_driver (str) – DBO driver
Returns:module
Return type:obj
_get_driver_from_dsn(dsn)

Method gets DB driver from dsn

Parameters:dsn (str) – dsn
Returns:DB driver
Return type:str
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
__weakref__

list of weak references to the object (if defined)

class hydratk.lib.database.dbo.dbo.DBOException

Class DBOException

  • dbodriver

This code is part of Hydra Toolkit library

class hydratk.lib.database.dbo.dbodriver.DBODriver(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class DBODriver

__metaclass__

alias of ABCMeta

dbcon

dbcon property getter

cursor

cursor property getter

__init__(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class constructor

Called when object is initialized

Parameters:
  • dsn (str) – dsn
  • username (str) – username
  • password (str) – password
  • driver_options (dict) – driver options
  • autoconnect (bool) – connect to DB within object creation
Raises:

exception – Exception

_parse_dsn(dsn)

Method parses driver specific dsn string

Parameters:dsn (string) – driver specific dsn format
Raises:exception – DBODriverException
dict_factory(cursor, row)

Method transforms database row to dictionary

Parameters:
  • cursor (obj) – database cursor
  • row (obj) – database row
Returns:

dict

__weakref__

list of weak references to the object (if defined)

class hydratk.lib.database.dbo.dbodriver.DBODriverStatement

Class DBODriverStatement

__metaclass__

alias of ABCMeta

__weakref__

list of weak references to the object (if defined)

exception hydratk.lib.database.dbo.dbodriver.DBODriverException(msg)

Class DBODriverException

message

message propery getter

call_path

call_path property getter

file

file property getter

line

line property getter

func

func property getter

module

module propery getter

parent_exc

parent_exc property getter, setter

__init__(msg)

Class constructor

Called when object is initialized

Parameters:msg (str) – message
__weakref__

list of weak references to the object (if defined)

__str__()

Method overried __str__

Parameters:none
Returns:str
get_trace(level)

Method gets traceback

Parameters:level (int) – trace level
Returns:traceback
Return type:dict
  • sqlite

DBO SQlite driver

class hydratk.lib.database.dbo.drivers.sqlite.driver.DBODriver(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class DBODriver

_detect_mode(dsn)

Method detects if is running in memory or file mode

Parameters:dsn (str) – dsn
Returns:result
Return type:bool
_parse_dsn(dsn)

Method parses dsn

Parameters:dsn (str) – dsn
Returns:True
Return type:bool
Raises:exception – Exception
_apply_driver_options(driver_options)

Method sets driver options

Parameters:driver_option (dict) – driver options
Returns:void
connect()

Method connects to database

Parameters:none
Returns:void
close()

Method disconnects from database

Parameters:none
Returns:void
Raises:exception – DBODriverException
commit()

Method commits transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
execute(sql, *parameters)

Method executes query

Parameters:
  • sql (str) – SQL query
  • parameters (args) – query parameters
Returns:

cursor

Return type:

obj

rollback()

Method rollbacks transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
table_exists(table_name)

Method checks if table exists

Parameters:table_name (str) – table
Returns:result
Return type:bool
database_exists()

Method checks if database exists

Parameters:none
Returns:result
Return type:bool
remove_database()

Method deletes database file

Parameters:none
Returns:result
Return type:bool
erase_database()

Method drops database

Parameters:none
Returns:void
result_as_dict(state)

Method enables query result in dictionary form

Parameters:state (bool) – enable dictionary
Returns:void
Raises:error – TypeError

debugging

  • firepot

Raw implementation of FireLogger protocol for debugging purposes

class hydratk.lib.debugging.firepot.FirePot

Class FirePot

static enable(state)

Method set enable

Parameters:state (bool) – enable state
Returns:void
static enabled()

Method gets enable

Parameters:none
Returns:enable
Return type:bool
static log(*args)

Method adds log record

Parameters:args (args) – arguments
Returns:result
Return type:bool
static flush_items()

Method flushes items

Parameters:none
Returns:void
static get_headers()

Method gets log headers

Parameters:none
Returns:headers
Return type:dict
__weakref__

list of weak references to the object (if defined)

  • simpledebug

Simplified core debugger functionality

hydratk.lib.debugging.simpledebug.dmsg(msg, level=1, channel=[1, 10])

Function writes debug message

Parameters:
  • msg (str) – message
  • level (int) – debug level
  • channel (list) – debug channel
Returns:

void

hydratk.lib.debugging.simpledebug.wmsg(msg)

Function writes warning message

Parameters:msg (str) – message
Returns:void

dynamic

  • callback

Function callback management

class hydratk.lib.dynamic.callback.CallBackProcessor(cbm, cb_dict, cb_dproxy)

Class CallBackProcessor

__init__(cbm, cb_dict, cb_dproxy)

Class constructor

Called when object is initialized

Parameters:
  • cbm (obj) – callback manager
  • cb_dict (dict) – callback dictionary
  • cb_dproxy (obj) – callback dictionary proxy, DictProxy
_wrap_fn(*args, **kwargs)

Method wraps functionality

Parameters:
  • args (list) – list arguments
  • kwargs (dict) – key value arguments
Returns:

callback result

Return type:

obj

Raises:

error – Exception

_wrap_fn_dproxy(*args, **kwargs)

Method wraps functionality via proxy

Parameters:
  • args (list) – list arguments
  • kwargs (dict) – key value arguments
Returns:

void

Raises:

error – Exception

__getattr__(fn_id)

Method gets attribute

Parameters:fn_id (str) – functionality id
Returns:wrap method
Return type:obj
Raises:error – NameError
__weakref__

list of weak references to the object (if defined)

class hydratk.lib.dynamic.callback.CallBack(fn_id, callback, options=None)

Class CallBack

__init__(fn_id, callback, options=None)

Class constructor

Called when object is initialized

Parameters:
  • fn_id (str) – functionality id
  • callback (obj) – callback, tuple|str|callable
  • options (obj) – not used
Raises:

error – TypeError

args

args property getter

kwargs

kwargs property getter

fn_id

fn_id property getter

fn

fn property getter

obj

obj property getter

shared

shared property getter

async

async property getter

set_fn(fn_name)

Method sets functionality

Parameters:fn_name (str) – functionality name
Returns:void
Raises:error – TypeError
set_obj(obj)

Method sets object

Parameters:obj (obj) – object
Returns:void
__weakref__

list of weak references to the object (if defined)

class hydratk.lib.dynamic.callback.CallBackManager(cb_dict=None, cb_dproxy=None)

Class CallBackManager

__init__(cb_dict=None, cb_dproxy=None)

Class constructor

Called when object is initialized

Parameters:
  • cb_dict (dict) – callback dictionary
  • cb_dproxy (obj) – callback dictionary proxy
sync_handler

sync_handler property getter

set_sync_handler(sh_obj)

Method sets synchronous handler

Parameters:sh_obj (obj) – sync handler object
Returns:void
async_handler

async_handler property getter

set_async_handler(ah_obj)

Method sets asynchrnonous handler

Parameters:ah_obj (obj) – async handler object
Returns:void
set_cb_dict(cb_dict)

Method sets callback dictionary

Parameters:cb_dict (dict) – callback dictionary
Returns:void
Raises:error – TypeError
set_cb_dproxy(cb_dproxy)

Method sets callback dictionary proxy

Parameters:cb_dproxy (obj) – callback dictionary proxy (DictProxy)
Returns:void
Raises:error – TypeError
create_cb_dproxy()

Method creates callback dictionary proxy

Parameters:none
Returns:void
run

run property getter

__weakref__

list of weak references to the object (if defined)

get_cb(fn_id)

Method gets callback

Parameters:

fn_id (str) – functionality id

Returns:

dict if callback registered in cb dictionary DictProxy if callback registered in cb dictionary proxy

Return type:

obj

Raises:
  • error – KeyError
  • error – TypeError
reg_cb(fn_id, callback, options=None)

Method registers callback

Parameters:
  • fn_id (str) – functionality id
  • callback (obj) – callback, tuple|str|callable
  • options (dict) – callback options
Returns:

void

Raises:
  • error – TypeError
  • error – ValueError
update_cb(cb_obj)

Method updates callback

Parameters:cb_obj (obj) – callback
Returns:void
class hydratk.lib.dynamic.callback.SyncCallBackHandler

Class SyncCallBackHandler

__weakref__

list of weak references to the object (if defined)

cb_run(cb_obj)

Method runs callback

Parameters:cbo (obj) – callback object
Returns:void
class hydratk.lib.dynamic.callback.AsyncCallBackHandler

Class AsyncCallBackHandler

__weakref__

list of weak references to the object (if defined)

cb_run(cb_obj)

Method runs callback

Parameters:cbo (obj) – callback object
Returns:void

exceptions

  • dependencyerror

Class for dependency error exception

exception hydratk.lib.exceptions.dependencyerror.DependencyError(error_num, args, msg)

Class DependencyError

__init__(error_num, args, msg)

Class constructor

Called when object is initialized

Parameters:
  • error_num (int) – number
  • args (list) – arguments
  • msg (str) – message
__weakref__

list of weak references to the object (if defined)

  • inputerror

Class for input error exception

exception hydratk.lib.exceptions.inputerror.InputError(error_num, args, msg)

Class InputError

__init__(error_num, args, msg)

Class constructor

Called when object is initialized

Parameters:
  • error_num (int) – number
  • args (list) – arguments
  • msg (str) – message
__weakref__

list of weak references to the object (if defined)

install

  • command

HydraTK installation commands

hydratk.lib.install.command.is_install_cmd(argv)

Method checks if installation is requested

Parameters:argv (list) – command arguments
Returns:result
Return type:bool
hydratk.lib.install.command.get_pck_manager()

Method returns system package manager

Supported: apt-get, yum

Parameters:none
Returns:list of string
Return type:list
hydratk.lib.install.command.is_installed(app)

Method checks if system application is installed

:param app:: application

:type app:: str

Returns:result
Return type:bool
hydratk.lib.install.command.install_pck(pckm, pck)

Method installs system package from repository

Parameters:pckm (str) – package manager

:param pck:: package

:type pck:: str

Returns:none
hydratk.lib.install.command.create_dir(dst)

Method creates directory

Parameters:dst (str) – destination path
Returns:none
hydratk.lib.install.command.copy_file(src, dst)

Method copies file

Parameters:
  • src (str) – source path
  • dst (str) – destination path
Returns:

none

hydratk.lib.install.command.move_file(src, dst)

Method moves file

Parameters:
  • src (str) – source path
  • dst (str) – destination path
Returns:

none

hydratk.lib.install.command.remove(src, recursive=True)

Method removes file or directory

Parameters:
  • src (str) – source path
  • recursive (bool) – recursive deletion
Returns:

none

hydratk.lib.install.command.set_rights(path, rights, recursive=True)

Method sets access rights

Parameters:
  • path (str) – directory/file path
  • rights (str) – access rights
  • recursive (bool) – set recursive rights
Returns:

none

hydratk.lib.install.command.install_pip(module)

Method installs python module via pip

Parameters:module (str) – python module
Returns:none
hydratk.lib.install.command.uninstall_pip(module)

Method uninstalls python module via pip

Parameters:module (str) – python module
Returns:none
  • task

HydraTK common installation tasks

hydratk.lib.install.task.run_pre_install(argv, cfg)

Function run pre-install tasks

Parameters:
  • argv (list) – command arguments
  • cfg (dict) – configuration
Returns:

none

hydratk.lib.install.task.run_post_install(argv, cfg)

Function run post-install tasks

Parameters:
  • argv (list) – command arguments
  • cfg (dict) – configuration
Returns:

none

hydratk.lib.install.task.check_libs(pkcm, lib_inst, lib_check)

Function checks installed library dependencies

Parameters:
  • argv (list) – command arguments
  • cfg (dict) – configuration
Returns:

missing libraries

Return type:

list

hydratk.lib.install.task.install_libs(cfg, profiles, *args)

Function installs system libraries

Parameters:
  • cfg (dict) – configuration
  • profiles (list) – module profiles
Returns:

none

hydratk.lib.install.task.install_modules(cfg, profiles, *args)

Method install python modules

Parameters:
  • cfg (dict) – configuration
  • profiles (list) – module profiles
Returns:

none

hydratk.lib.install.task.create_dirs(cfg, *args)

Method creates directories

Parameters:cfg (dict) – configuration
Returns:none
hydratk.lib.install.task.copy_files(cfg, *args)

Method copies data files

Parameters:cfg (dict) – configuration
Returns:none
hydratk.lib.install.task.set_access_rights(cfg, *args)

Method sets access rights

Parameters:cfg (dict) – configuration
Returns:none
hydratk.lib.install.task.set_config(cfg, *args)

Method sets configuration file

Parameters:cfg (dict) – configuration
Returns:none
hydratk.lib.install.task.set_manpage(cfg, *args)

Method sets manual page

Parameters:cfg (dict) – configuration
Returns:none
hydratk.lib.install.task.get_profiles(argv)

Method gets module profiles

Parameters:argv (list) – input arguments
Returns:profiles
Return type:list
  • uninstall

HydraTK uninstallation tasks

hydratk.lib.install.uninstall.run_uninstall()

Method runs installation script

Parameters:none
Returns:none
hydratk.lib.install.uninstall.uninstall_ext(ext_id, files, mods)

Method uninstalls extension

Parameters:
  • ext_id (str) – extension id
  • files (list) – extension files
  • mods (list) – dependent modules
Returns:

none

hydratk.lib.install.uninstall.uninstall_lib(lib_id, files, mods)

Method uninstalls library

Parameters:
  • lib_id (str) – library id
  • files (list) – library files
  • mods (list) – dependent modules
Returns:

none

hydratk.lib.install.uninstall._get_dependencies(dependencies)

Method gets dependent modules

Parameters:dependencies (dict) – dependent modules
Returns:list

number

  • conversion

Module for number conversions

hydratk.lib.number.conversion.int2bool(intvar)

Method converts number to bool

Parameters:intvar (int) – number
Returns:result
Return type:bool

string

  • operation

Module for string operations

hydratk.lib.string.operation.mreplace(text, dic)

Replace in ‘text’ all occurences of any key in the given dictionary by its corresponding value. Returns the new string.

Parameters:
  • text (str) – text
  • dic (dict) – key - search, value - replace
Returns:

text

Return type:

str

hydratk.lib.string.operation.str_split(string, split_length=1)

Method splits string to substrings

Parameters:
  • string (str) – original string
  • split_length (int) – substrin length
Returns:

list of strings

Return type:

list

hydratk.lib.string.operation.strip_accents(text)

Function strip accents from input text

Parameters:text (str) – Input text string
Returns:text
Return type:str
  • prettify

Module for string pretty formatting

hydratk.lib.string.prettify.xml_prettify(xml_str)

Method reformats xml to use indentation

Parameters:xml_str (str) – raw xml
Returns:indented xml
Return type:str

system

  • auth

Module for user authentication

hydratk.lib.system.auth.check_auth(user, password)

Perform authentication against the local systme.

This function will perform authentication against the local system’s /etc/shadow or /etc/passwd database for a given user and password.

Parameters:
  • user (str) – The username to perform authentication with
  • password (str) – The password (plain text) for the given user
Returns:

result

Return type:

bool

  • config

A useful module for configuration defaults

hydratk.lib.system.config.update_htk_vars()

Function updates HTK config variables

Returns:none
hydratk.lib.system.config.is_virtualized()

Function determines if there’s virtualized Python environment

Returns:result
Return type:Bool
hydratk.lib.system.config.get_supported_os()

Function returns supported os string

Returns:os string
Return type:str
  • fs

Module for operation with file system

hydratk.lib.system.fs.rmkdir(path)

Method creates directory

Parameters:path (str) – directory path
Returns:result
Return type:bool
Raises:exeception – Exception
hydratk.lib.system.fs.file_get_contents(filename, mode='r')

Methods reads file content

Parameters:
  • filename (str) – filename including path
  • mode (str) – file mode
Returns:

content

Return type:

str

hydratk.lib.system.fs.file_put_contents(filename, data)

Methods writes content to file

Parameters:
  • filename (str) – filename including path
  • data (str) – content
Returns:

void

  • io

Useful module for controlled input output

hydratk.lib.system.io.cprint(data)

Methods sends data as debug message

Parameters:data (str) – message
Returns:void
hydratk.lib.system.io.rprint(*args)

Methods writes raw data to the stdio

Parameters:*args (str) – data
Returns:void
  • mtime

Module for time unit operations

hydratk.lib.system.mtime.microtime(get_as_float=False)

Methods returns current time including microseconds

Parameters:get_as_float (bool) – return time as float
Returns:if get_as_flost str: if not get_as_float
Return type:float
  • utils

A useful module for misc utils

class hydratk.lib.system.utils.Utils

Class Utils

static module_version(module)

Methods gets module version

Parameters:module (str) – full module name
Returns:version
Return type:str
static module_loaded(module)

Methods checks if module is already loaded

Parameters:module (str) – full module name
Returns:resukt
Return type:bool
static module_exists(module_name)

Methods checks if module exists

Parameters:module (str) – full module name
Returns:result
Return type:bool
static module_version_ok(min_version, cur_version)

Methods checks if module is version compliant

Parameters:
  • min_version (str) – minimum module version
  • cur_version (str) – current module version
Returns:

result

Return type:

bool

translation

  • translator

A useful module for application multilanguagee support

class hydratk.lib.translation.translator.Translator(messages='')

Class Translator

__init__(messages='')

Class constructor

Called when object is initialized

Parameters:messages (dict) – message dictionary
Raises:error – ValueError
msg_mod

msg_mod property getter, setter

help_mod

help_mod property getter, setter

set_help_mod(help_module)

Methods sets help module

Parameters:help_module (str) – help module
Returns:void
register_messages(messages)

Methods registers langtexts

Parameters:messages (dict) – langtexts
Returns:True
Return type:bool
Raises:error – ValueError
set_debug_level(level)

Methods sets debug level

Parameters:level (int) – debug level, default 1
Returns:void
set_language(lang)

Methods sets language

Parameters:lang (str) – language
Returns:void
get_language()

Methods gets language

Parameters:none
Returns:language
Return type:str
lmsg(lang, key, *args)

Methods resolves langtext

Parameters:
  • lang (str) – language
  • key (str) – langtext
  • args (ags) – langtext arguments
Returns:

resolved langtext

Return type:

str

msg(key, *args)

Methods resolves langtext according to debug level

Parameters:
  • key (str) – langtext
  • args (ags) – langtext arguments
Returns:

resolved langtext

Return type:

str

add_msg(msg, id='')

Methods adds new messages

Parameters:
  • msg (obj) – dict (identified by key) or str, messages
  • id (str) – message identifier
Returns:

count of added messages

Return type:

int

add_help(help)

Methods adds new help texts

Parameters:help (obj) – help object
Returns:count of added help texts
Return type:int
lang_add_msg(msg, lang)

Methods adds new langtexts

Parameters:
  • msg (dict) – langtexts
  • lang (str) – language
Returns:

count of added langtexts

Return type:

int

Raises:

error – ValueError