Skip to main content

Helper classes for Jarvis applications

Project description

This package contains helper classes for open-jarvis applications.

Classes

Colors

Colors
	.PURPLE = '\033[95m'
	.BLUE 	= '\033[94m'
	.CYAN 	= '\033[96m'
	.GREEN 	= '\033[92m'
	.YELLOW = '\033[93m'
	.RED 	= '\033[91m'
	.END 	= '\033[0m'
	.RESET	= '\033[0m'

	.WARNING= YELLOW
	.ERROR	= RED

Exiter

def on_exit(args):
	print("exiting... perform actions here!")

Exiter(on_exit, [args, ...]) 	# initializes an Exiter who executes the given function
								# when the script receives a SIGTERM or SIGINT signal

Jarvis

Jarvis MQTT API wrapper

Jarvis(host="127.0.0.1", port=1883, client_id="mqtt_jarvis")
	.register()
	.get_devices()
	.get_property(key, target_token=None)
	.set_property(target_token, key, value)
	.instant_ask(typ, name, infos, options)
	.instant_answer(target_token, typ, option_index, description)
	.instant_scan(target_token=None, typ=None)
	.instant_delete(target_token)

Logger

Provides a uniform interface for logging files

Logger(referer: str) # the referer is a string describing from which program the log message originated (eg. your script name)
	.console_on() # turn on console logging
	.console_off() # turn off console logging

	.new_group() # turn on grouping and create a new logging group (only for fast RAM logging)
	.enable_fast() # enable fast RAM logging
	.disable_fast() # disable fast RAM logging
	.clear_fast() # clear fast RAM logging data
	.get_fast()	 # get fast RAM logs

	.i(tag, message) # create an info message
	.e(tag, message) # create an error message
	.w(tag, message) # create a warning message
	.s(tag, message) # create a success message
	.c(tag, message) # create a critical message

	.exception(tag, exception=None) # log the last exception

MQTT

MQTT(host=127.0.0.1, port=1883, client_id=[random])
	.on_connect(callback[client, userdata, flags, rc]) # on connect event
	.on_message(callback[client, userdata, message]) # on message callback: topic = message.topic, data = message.payload.decode()
	.publish(topic, payload) # public a str message under str topic
	.subscribe(topic) # subscribe to a topic (# = all)

SetupTools

SetupTools
	.do_action(print_str, shell_command, show_output=True, on_fail="failed!", on_success="done!", exit_on_fail=True): # run a shell command
	.regex_replace_in_file(file_path, from_regex, to_string) # replace regex in file
	.is_root() # check if has root access
	.get_python_version() # get the executing python version
	.check_python_version(version): # make sure get_python_version() == version, exit on fail
	.check_root() # make sure is_root() == True, exit on fail
	.get_default_installation_dir(default_dir) # ask for the default Jarvis installation directory, return either default_dir or a new directory
	.get_default_user(default_user) # ask for the default user, return either default_user or a new username

Database

Database(username: str, password: str, name: str, hostname: str = "127.0.0.1", port: int = 5984)
	.table(name: str, pure: bool = False) -> Table # get a table, create the table if it doesn't exist yet
	.up # returns True if the server is up and running, else False

Table
	.get(id: str) # get a document using its id
	.all() # get all documents
	.insert(document: dict) # insert a document
	.filter(filter: lamdba|dict) -> DocumentList # filter all entries either using a lambda function or a dictionary
	.delete() # drop the table

DocumentList
	.update(new_document: dict) # update a list of documents
	.delete() # delete all selected documents
	.found # check if a previous function returned entries

# Examples:
#  Find all documents containing a "hello": "world" key-value pair and delete it
Database("test", "test", "test").table("test").filter({"hello":"world"}).delete()
#  Find all documents containing a "hello": "world" key-value pair and update it
Database("test", "test", "test").table("test").filter({"hello":"world"}).update({"hello2":"world2", "this": "is a second key value pair"})

Config

Config # utilizes the Database class to store configurations.
       # ONLY STORE INFORMATION, THAT SHOULD BE ACCESSIBLE FOR JARVIS SUBPROGRAMS!
	.set(key:str, value:object) # set a key and give it a value
	.get(key:str, or_else:object) # get a key, if not available return the or_else object

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open-jarvis-0.0.34.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

open_jarvis-0.0.34-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file open-jarvis-0.0.34.tar.gz.

File metadata

  • Download URL: open-jarvis-0.0.34.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for open-jarvis-0.0.34.tar.gz
Algorithm Hash digest
SHA256 334b449102c0bc25f0bda70651b6fec4e0a3dcb0b7206d0d794c3430ea34a692
MD5 0721d3fe4aeba3d3e0fc5a9f4d50d96f
BLAKE2b-256 3a8582697ab28a4b1489baf76e4afd71401982fb4d3d90627ef23b8a841282ce

See more details on using hashes here.

File details

Details for the file open_jarvis-0.0.34-py3-none-any.whl.

File metadata

  • Download URL: open_jarvis-0.0.34-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for open_jarvis-0.0.34-py3-none-any.whl
Algorithm Hash digest
SHA256 37cf3bdcb82a93076a035845405dbecee5b866d7b989c4dcf1c69a143833a3c2
MD5 a2fa75c37a042aa4f3f2948aa1df9e13
BLAKE2b-256 c0585e4c7b7d562243e168b99921326fa028b59b56abb600483321ca5d5a9e1d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page