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
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
– CmdOptParserUndefinederror
– 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: Returns: result
Return type: Raises: error
– CmdOptParserErrorerror
– TypeError
-
add_opt
(option, d_option=None, has_value=False, allow_multiple=False, opt_group='default')¶ Method adds new option
Parameters: Returns: result
Return type:
-
add_getopt_opt
(short_opt, long_opt, opt_map={})¶ Method adds new option
Parameters: Returns: void
-
parse
(opt_group='default', hide_undef=True)¶ Method adds new option
Parameters: Returns: options (dict), undefined options
Return type: Raises: error
– CmdOptParserUndefined
-
_strip_opts
(opts)¶ Method strips options without value
Parameters: opts (dict) – options Returns: stripped options 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: Returns: void
-
static
set_help
(title, cp_string, cmd_text, opt_text)¶ Method creates and returns a formated help text
Parameters: 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
- shellexec
This code is a part of Hydra Toolkit library
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
– ValueErrorExample:
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¶
Module with shared objects
Class My
pocket property getter
piles property getter
Method creates new pile
Parameters: pile_id (str) – pile identifier Returns: Pile Return type: obj Raises: error
– ValueError
Method drops pile
Parameters: pile_id (str) – pile identifier Returns: result Return type: bool Raises: error
– ValueError
list of weak references to the object (if defined)
Class Pocket
Method prints pocket content
Args:
Returns: void
content property getter, setter
Method fills pocket with data
Parameters: data (obj) – data Returns: void
Method purges pocket
Parameters: none – Returns: void
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: Returns: object on success
Return type: 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)
-
-
exception
hydratk.lib.database.dbo.dbo.
DBOException
¶ Class DBOException
-
__weakref__
¶ list of weak references to the object (if defined)
-
- 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: 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: 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
-
__weakref__
¶ list of weak references to the object (if defined)
-
__str__
()¶ Method overried __str__
Parameters: none – Returns: str
-
- 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: Returns: cursor
Return type:
-
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
-
erase_database
()¶ Method drops database
Parameters: none – Returns: void
-
debugging¶
- firepot
Raw implementation of FireLogger protocol for debugging purposes
-
class
hydratk.lib.debugging.firepot.
FirePot
¶ Class FirePot
-
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
-
__weakref__
¶ list of weak references to the object (if defined)
-
static
- simpledebug
Simplified core debugger functionality
-
hydratk.lib.debugging.simpledebug.
dmsg
(msg, level=1, channel=[1, 10])¶ Function writes debug message
Parameters: 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:
-
_wrap_fn
(*args, **kwargs)¶ Method wraps functionality
Parameters: Returns: callback result
Return type: Raises: error
– Exception
-
_wrap_fn_dproxy
(*args, **kwargs)¶ Method wraps functionality via proxy
Parameters: 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: 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 property getter
-
async
¶ async property getter
-
set_fn
(fn_name)¶ Method sets functionality
Parameters: fn_name (str) – functionality name Returns: void Raises: error
– TypeError
-
__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:
-
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: Raises: error
– KeyErrorerror
– TypeError
-
reg_cb
(fn_id, callback, options=None)¶ Method registers callback
Parameters: Returns: void
Raises: error
– TypeErrorerror
– ValueError
-
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:
-
__weakref__
¶ list of weak references to the object (if defined)
-
- inputerror
Class for input error exception
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 managera
Parameters: none – Returns: list of string Return type: list
-
hydratk.lib.install.command.
is_installed
(app)¶ Method checks if system application is installed
Parameters: app (str) – application Returns: result Return type: bool
-
hydratk.lib.install.command.
install_pck
(pckm, pck)¶ Method installs system package from repository
Parameters: 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: Returns: none
-
hydratk.lib.install.command.
move_file
(src, dst)¶ Method moves file
Parameters: Returns: none
-
hydratk.lib.install.command.
remove
(src, recursive=True)¶ Method removes file or directory
Parameters: Returns: none
-
hydratk.lib.install.command.
set_rights
(path, rights, recursive=True)¶ Method sets access rights
Parameters: 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: Returns: none
-
hydratk.lib.install.task.
run_post_install
(argv, cfg)¶ Function run post-install tasks
Parameters: Returns: none
-
hydratk.lib.install.task.
check_libs
(lib_inst, lib_check)¶ Function checks installed library dependencies
Parameters: Returns: missing libraries
Return type:
-
hydratk.lib.install.task.
install_libs
(cfg, profiles, *args)¶ Function installs system libraries
Parameters: Returns: none
-
hydratk.lib.install.task.
install_modules
(cfg, profiles, *args)¶ Method install python modules
Parameters: 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: Returns: none
-
hydratk.lib.install.uninstall.
uninstall_lib
(lib_id, files, mods)¶ Method uninstalls library
Parameters: Returns: none
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: Returns: text
Return type:
-
hydratk.lib.string.operation.
str_split
(string, split_length=1)¶ Method splits string to substrings
Parameters: Returns: list of strings
Return type:
-
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
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: Returns: result
Return type:
- 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', acquire_lock=False, wait_lock_timeout=5)¶ Methods reads file content
Parameters: Returns: content
Return type:
-
hydratk.lib.system.fs.
file_put_contents
(filename, data, mode='w')¶ Methods writes content to file
Parameters: 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
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
-
lmsg
(lang, key, *args)¶ Methods resolves langtext
Parameters: Returns: resolved langtext
Return type:
-
msg
(key, *args)¶ Methods resolves langtext according to debug level
Parameters: - key (str) – langtext
- args (ags) – langtext arguments
Returns: resolved langtext
Return type:
-
add_msg
(msg, id='')¶ Methods adds new messages
Parameters: Returns: count of added messages
Return type:
-