pyserv.tui_helpers module¶
Pyserv TUI helper functions for picotui or similar.
- class pyserv.tui_helpers.TLogWatcher(folder, callback, extensions='log', tail_lines=0, sizehint=1048576)[source]¶
Bases:
LogWatcherOverride
open()to decode log lines- Parameters:
folder (str)
callback (Callable)
extensions (str)
tail_lines (int)
sizehint (int)
- classmethod open(file)[source]¶
Wrapper around open(). By default files are opened in binary mode and readlines() will return bytes on both Python 2 and 3. This means callback() will deal with a list of bytes. Can be overridden in order to deal with unicode strings instead, like this:
import codecs, locale return codecs.open(file, 'r', encoding=locale.getpreferredencoding(), errors='ignore')
- Parameters:
file (str)
- Return type:
IO
- pyserv.tui_helpers.dummy_callback(filename, lines)[source]¶
Logwatcher feeds a log display only, no need for line printing.
- Parameters:
filename (str)
lines (List[str | None])
- pyserv.tui_helpers.get_env(name)[source]¶
Get environment data from selected (daemon) name.
- Parameters:
name (str) – name of the daemon/server command
- Returns:
full env settings
- Return type:
Dict
- pyserv.tui_helpers.get_w_env(env)[source]¶
Get UI widget settings from env values.
- Parameters:
env (Dict) – default environ for selected daemon/server
- Returns:
core env settings
- Return type:
Dict
- pyserv.tui_helpers.host_check(ip)[source]¶
Check a remote host using IP address; returns remote MAC address if host is UP. Requires root or
setcapon POSIX platforms. Windows does not have this limitation.- Parameters:
ip (str) – IP address or resolvable hostname
- Returns:
MAC address string
- Return type:
str
- pyserv.tui_helpers.update_log_lines(fname, shorten=0, num_lines=10)[source]¶
Simpler version of
get_log_lines()using LogWatcher instead of Pygtail.- Parameters:
fname (str) – path to log file as a string
shorten (int) – split lines on spaces and keep the remainder
num_lines (int) – number of lines in tail output
- Returns:
available log lines up to num_lines
- Return type:
List[str | None]