cleep.libs.internals package
cleep.libs.internals.cleepbackup module
- class CleepBackup(cleep_filesystem, crash_report)
Bases:
object
- CleepBackup allows you:
to backup cleep configuration files on filesystem (in /etc/cleep.bak directory)
to generate backup archive of configuration files
It uses rsync to backup files locally
- BACKUP_PATH = '/etc/cleep.bak/'
- CLEEP_PATH = '/etc/cleep/'
- backup()
Backup configuration files on filesystem
- Returns
True if backup completed sucessfully
- Return type
bool
- generate_archive()
Generate backup archive (zip format)
Warning
Caller is in charge of file deletion !
- Returns
generated archive fullpath
- Return type
string
cleep.libs.internals.cleepdoc module
cleep.libs.internals.cleepfilesystem module
cleep.libs.internals.cleepgithub module
- class CleepGithub(auth_string=None)
Bases:
object
Github release helper This class get releases from specified project and return content as dict
- GITHUB_RATE = 'https://api.github.com/rate_limit'
- GITHUB_URL = 'https://api.github.com/repos/%s/%s/releases'
- get_api_rate()
Get current api rate Api requests are limited on free usage of github. This method returns current rate
- Returns
general rate values:
{ limit (int): limit of requests remaining (int): number of requests processed reset (int): timestamp when rate is resetted to limit }
- Return type
dict
- get_release_assets_infos(release)
Return simplified structure of all release assets
- Parameters
release (dict) – release data as returned by get_releases function
- Returns
list of assets infos (name, url, size):
[ { name (string): asset name url (string): download url size (int): asset size }, ... ]
- Return type
list of dict
- Raises
Exception if input release is invalid –
- get_release_changelog(release)
Return changelog of specified release
- Parameters
release (dict) – release data as returned by get_releases function
- Returns
changelog of release. Can be empty string if no changelog specified.
- Return type
string
- Raises
Exception if version field not found or input release is invalid –
- get_release_version(release)
Return version of specified release
- Parameters
release (dict) – release data as returned by get_releases function
- Returns
version of release
- Return type
string
- Raises
Exception if version field not found or input release is invalid –
- get_releases(owner, repository, only_latest=False, only_released=True)
Get releases of specify project repository
- Parameters
owner (string) – name of owner
repository (string) – name of repository
only_latest (bool) – if True returns only latest release
only_released (bool) – if True returns only released releases
- Returns
list of releases. Format can be found here https://developer.github.com/v3/repos/releases/
- Return type
list
- is_released(release)
Return True if release is released (it means not prerelease or draft)
- Parameters
release (dict) – release data as returned by get_releases function
- Returns
True if release is released
- Return type
bool
- Raises
Exception if input release is invalid –
cleep.libs.internals.cleepresource module
cleep.libs.internals.console module
cleep.libs.internals.crashreport module
cleep.libs.internals.criticalresources module
cleep.libs.internals.download module
cleep.libs.internals.drivers module
cleep.libs.internals.event module
- class Event(params)
Bases:
object
Base event class
- EVENT_CHARTABLE = False
- EVENT_JOURNALIZABLE = False
- EVENT_NAME = ''
- EVENT_PARAMS = []
- EVENT_PROPAGATE = False
- get_chart_values(params)
Returns chart values
- Parameters
params (dict) – event parameters
- Returns
list of field+value or None if no value
[ { field (string): field name, value (any): value }, ... ]
- Return type
list
- render(params=None)
Render event to renderers
- Parameters
params (dict) – list of event parameters
- Returns
True if at least one event was renderered successfully
- Return type
bool
- send(params=None, device_id=None, to=None, render=True)
Push event message on bus.
- Parameters
params (dict) – event parameters.
device_id (string) – device id that send event. If not specified event cannot be monitored.
to (string) – event recipient. If not specified, event will be broadcasted. (to send to ui client set ‘rpc’)
render (bool) – also propagate event to renderer. False to disable it
- Raises
Exception if parameters are invalid –
- send_to_peer(peer_uuid, params=None, device_id=None)
Push event to peer through external bus
- Parameters
peer_uuid (string) – peer uuid
params (dict) – event parameters
- Raises
Exception if parameters are invalid –
cleep.libs.internals.eventsbroker module
- class EventsBroker(debug_enabled)
Bases:
object
Events broker The goal of this broker is to centralize events to reference all them all in the core. It is also used to check event content before posting them and make sure it is compatible with core.
- CORE_EVENTS_DIR = '../../events'
- MODULES_DIR = '../../modules'
- PYTHON_CLEEP_APPS_IMPORT_PATH = 'cleep.modules.'
- PYTHON_CLEEP_CORE_EVENTS_IMPORT_PATH = 'cleep.events.'
- configure(bootstrap)
Configure broker loading needed objects (formatters, events…)
- Parameters
bootstrap (dict) – bootstrap objects
- get_event_instance(event_name)
Return new event instance according to event name It also register event callers for event
- Parameters
event_name (string) – full event name (xxx.xxx.xxx)
- Returns
Event instance
- Raises
Exception if event not exists –
- get_module_events(module_name)
Return list of events handled by specified module
- Parameters
module_name (string) – module name
- Returns
list of events
- Return type
list
- Raises
Exception if module name does not exist –
- get_modules_events()
Return dict of modules events
- Returns
dict of events:
{ module1 (list): [event_name (string), event_name (string), ...], ... }
- Return type
dict
- get_used_events()
Return dict of used events
- Returns
dict of used events:
{ event1: { modules (list): list of modules that reference the event, profiles (list[Event]): list of profiles that references the event }, ... }
- Return type
dict
- is_event_renderable(event_name, renderer_name)
Check if specified event is renderable for specified renderer
- Parameters
event_name (string) – event name
renderer_name (string) – renderer name
- Returns
True if event is renderable for this renderer
- Return type
bool
- set_event_renderable(event_name, renderer_name, renderable)
Set event renderable or not for specified renderer
- Parameters
event_name (string) – event name
renderer_name (string) – renderer name
renderable (bool) – True if event is renderable
cleep.libs.internals.externalbus module
- class ExternalBus(on_message_received, on_peer_connected, on_peer_disconnected, debug_enabled, crash_report)
Bases:
object
ExternalBus base class
External bus is only based on event handling. This way of doing forces developper to handle async requests only. This also reduces bus complexity.
- This class provides:
peers list handling
base bus functions canvas (not implementation)
internal logger with debug enabled or not
- COMMAND_RESPONSE_EVENT = 'external.command.response'
- on_message_received(peer_id, message)
On message received event
- Parameters
peer_id (string) – peer identifier
message (MessageRequest) – request message
- run()
Run external bus process
Warning
Must be implemented
- run_once()
Run external bus process once
Warning
Must be implemented
- send_message(message, timeout=5.0, manual_response=None)
Send message (broadcast or to recipient) to outside
- Parameters
message (MessageRequest) – message request instance
timeout (float) – command timeout
manual_response (function) – function to call to send back command response
cleep.libs.internals.install module
cleep.libs.internals.installcleep module
cleep.libs.internals.installdeb module
cleep.libs.internals.installmodule module
cleep.libs.internals.profileformatter module
- class ProfileFormatter(params, event_name, profile)
Bases:
object
Base ProfileFormatter class Used to format profile with specified event parameters
- format(event_params)
Format event
- Parameters
event_params (dict) – list of event parameters as received from internal bus. Can be None.
- Returns
Profile instance filled with appropriate values
cleep.libs.internals.profileformattersbroker module
- class ProfileFormattersBroker(debug_enabled)
Bases:
object
ProfileFormatters broker is in charge of centralizing all formatters It also ensures formatters use exiting events
- MODULES_DIR = '../../modules'
- PYTHON_CLEEP_IMPORT_PATH = 'cleep.modules.'
- configure(bootstrap)
Configure broker
- Parameters
bootstrap (dict) – bootstrap objects
- get_renderers()
Returns list of renderers (aka module)
- Returns
list of renderers:
[ module_name (string), ... ]
- Return type
list
- get_renderers_formatters(event_name)
Return all event formatters by modules that are loaded
- Parameters
event_name (string) – event name to search formatters for
- Returns
Formatter instances for specified event for each modules that implements it or empty dict if no formatter for this event:
{ module name (string): formatter instance (ProfileFormatter) ... }
- Return type
dict
- get_renderers_profiles()
Return list of profiles handled by renderers
- Returns
dict of profile handled by renderers:
{ module_name (string): [ profile_name (string), ... ], ... }
- Return type
dict
- register_renderer(module_name, module_profiles)
Register new renderer
- Parameters
module_name (string) – name of renderer (module name)
module_profiles (list<RendererProfile>) – list of profiles supported by module
- Raises
cleep.libs.internals.readwrite module
cleep.libs.internals.rendererprofile module
cleep.libs.internals.sun module
cleep.libs.internals.task module
cleep.libs.internals.taskfactory module
cleep.libs.internals.tools module
- cidr_to_netmask(cidr)
Convert cidr to netmask
- Parameters
cidr (int) – cidr value
- Returns
netmask (ie 255.255.255.0)
- Return type
string
- compare_compat_string(compat_str, current_versions)
Compare compat string checking if specified compat string is in version range for all modules
- Parameters
compat_str (string) – compat string to compare. It looks like <module><operator><version>,…
current_versions (dict) –
dict of current modules versions:
{ module name (string): module version (string) ... }
- Returns
True if compat string is compatible with specified current versions
- Return type
bool
- compare_versions(old_version, new_version, strict=True)
Compare specified version and return True if new version is strictly greater than old one Version must contains 3 digits otherwise comparison will be rejected
- Parameters
old_version (string) – old version
new_version (string) – new version
strict (bool) – True to perform strict check (<). False to perform a permissive check (<=)
- Returns
True if new version available
- Return type
bool
- dbm_to_percent(dbm)
Convert dbm signal level to percentage
Note
Article here https://www.adriangranados.com/blog/dbm-to-percent-conversion
- Parameters
dbm (int) – dbm value
- Returns
percentage value
- Return type
int
- file_to_base64(path)
Convert specified file to base64 string
- Parameters
path (string) – path to file
- Returns
base64 encoded file content
- Return type
string
- Raises
Exception of all kind if something wrong occured –
- full_split_path(path)
Split path completely /home/test/test.txt => [‘/’, ‘home’, ‘test’, ‘test.py’]
Note
code from https://www.safaribooksonline.com/library/view/python-cookbook/0596001673/ch04s16.html
- Returns
list of path parts
- Return type
list
- hr_bytes(num)
Human readable bytes value
- Parameters
n (int) – bytes
- Returns
human readable bytes value
- Return type
string
- hr_uptime(uptime)
Human readable uptime (in days/hours/minutes/seconds)
- Parameters
uptime (int) – uptime value
- Returns
human readable string
- Return type
string
- install_trace_logging_level()
Install custom log level TRACE for library debugging principaly Credits https://gist.github.com/numberoverzero/f803ebf29a0677b6980a5a733a10ca71
- install_unhandled_exception_handler(crash_report)
Overwrite default exception handler to log errors @see https://stackoverflow.com/a/16993115
- Parameters
crash_report (CrashReport) – crash report instance
- is_core_lib(path)
Check if specified lib is a core library (provided by cleep)
- Parameters
path (string) – lib path
- Returns
True if lib is core lib, False otherwise
- Return type
bool
- netmask_to_cidr(netmask)
Convert netmask to cidr format
Note
code from https://stackoverflow.com/a/43885814
- Parameters
netmask (string) – netmask address
- Returns
cidr value
- Return type
int
- raspberry_pi_infos()
Returns infos about current raspberry pi board
- Returns
raspberry pi board infos:
{ date (string): release date model (string): raspberry pi model pcbrevision (string): PCB revision ethernet (bool): True if ethernet is natively available on board wireless (bool): True if wifi is natively available on board, audio (bool): True if audio is natively available on board gpiopins (int): number of pins available on board memory (string): memory amount notes (string): notes on board revision (string): raspberry pi revision }
- Return type
dict
- Raises
Exception if platform is not ARM –
- wpa_passphrase(ssid, password)
Python implementation of wpa_passphrase linux utility It generates wpa_passphrase for wifi network connection
Note
Copied from https://github.com/julianofischer/python-wpa-psk-rawkey-gen/blob/master/rawkey-generator.py
- Parameters
ssid (string) – network ssid
password (string) – password
- Returns
generated psk
- Return type
string