paradrop.base package

Submodules

paradrop.base.cxbr module

Wamp utility methods.

class BaseClientFactory(factory, *args, **kwargs)[source]

Bases: autobahn.twisted.websocket.WampWebSocketClientFactory, twisted.internet.protocol.ReconnectingClientFactory

clientConnectionFailed(connector, reason)[source]

Called when a connection has failed to connect.

It may be useful to call connector.connect() - this will reconnect.

@type reason: L{twisted.python.failure.Failure}

clientConnectionLost(connector, reason)[source]

Called when an established connection is lost.

It may be useful to call connector.connect() - this will reconnect.

@type reason: L{twisted.python.failure.Failure}

initialDelay = 1
maxDelay = 60
class BaseSession(config=None)[source]

Bases: autobahn.twisted.wamp.ApplicationSession

Temporary base class for crossbar implementation

call(procedure, *args, **kwargs)[source]

Implements autobahn.wamp.interfaces.ICaller.call()

leave()[source]

Implements autobahn.wamp.interfaces.ISession.leave()

onJoin(**kwargs)[source]

Implements autobahn.wamp.interfaces.ISession.onJoin()

publish(topic, *args, **kwargs)[source]

Implements autobahn.wamp.interfaces.IPublisher.publish()

register(endpoint, procedure=None, options=None)[source]

Implements autobahn.wamp.interfaces.ICallee.register()

classmethod start(address, pdid, realm='paradrop', start_reactor=False, debug=False, extra=None, reconnect=True)[source]

Creates a new instance of this session and attaches it to the router at the given address and realm.

reconnect: The session will attempt to reconnect on connection failure
and continue trying indefinitely.
stockCall(procedure, *args, **kwargs)[source]
stockPublish(topic, *args, **kwargs)[source]
stockRegister(endpoint, procedure=None, options=None)[source]
stockSubscribe(handler, topic=None, options=None)[source]
subscribe(handler, topic=None, options=None)[source]

Implements autobahn.wamp.interfaces.ISubscriber.subscribe()

class BaseSessionFactory(config, deferred=None)[source]

Bases: autobahn.twisted.wamp.ApplicationSessionFactory

paradrop.base.exceptions module

Exceptions and their subclasses

TODO: Distill these down and make a heirarchy.

exception AuthenticationError[source]

Bases: paradrop.base.exceptions.PdServerException

exception ChuteNotFound[source]

Bases: paradrop.base.exceptions.ParadropException

exception ChuteNotRunning[source]

Bases: paradrop.base.exceptions.ParadropException

exception DeviceNotFoundException[source]

Bases: paradrop.base.exceptions.ParadropException

exception InteralException[source]

Bases: exceptions.Exception

exception InvalidCredentials[source]

Bases: paradrop.base.exceptions.PdServerException

exception ModelNotFound[source]

Bases: paradrop.base.exceptions.PdServerException

exception ParadropException[source]

Bases: exceptions.Exception

exception PdServerException[source]

Bases: exceptions.Exception

exception PdidError[source]

Bases: paradrop.base.exceptions.PdServerException

exception PdidExclusionError[source]

Bases: paradrop.base.exceptions.PdServerException

exception ServiceNotFound(name)[source]

Bases: paradrop.base.exceptions.ParadropException

paradrop.base.nexus module

Stateful, singleton, paradrop daemon command center. See docstring for NexusBase class for information on settings.

SETTINGS QUICK REFERENCE:

# assuming the following import from paradrop.base import nexus

nexus.core.info.version nexus.core.info.pdid

class AttrWrapper[source]

Bases: object

Simple attr interceptor to make accessing settings simple.

Stores values in an internal dict called contents.

Does not allow modification once _lock() is called. Respect it.

Once you’ve filled it up with the appropriate initial values, set onChange to assign

setOnChange(func)[source]
class NexusBase(stealStdio=True, printToConsole=True)[source]

Bases: object

Resolving these values to their final forms:

1 - module imported, initial values assigned(as written below) 2 - class is instatiated, passed settings to replace values 3 - instance chooses appropriate values based on current state(production or local)

Each category has its own method for initialization here (see: resolveNetwork, resolvePaths)
PDID = None
VERSION = 1
connect(**kwargs)[source]

Takes the given session class and attempts to connect to the crossbar fabric.

If an existing session is connected, it is cleanly closed.

getKey(name)[source]

Returns the given key or None

onInfoChange(key, value)[source]

Called when an internal setting is changed. Trigger a save automatically.

onStart()[source]
onStop()[source]
provision(pdid, pdserver='https://paradrop.org', wampRouter='wss://paradrop.org/ws')[source]
provisioned()[source]

Checks if this[whatever] appears to be provisioned or not

save()[source]

Ehh. Ideally this should happen asynchronously.

saveKey(key, name)[source]

Save the key with the given name. Overwrites by default

createDefaultInfo(path)[source]
resolveInfo(nexus, path)[source]

Given a path to the config file, load its contents and assign it to the config file as appropriate.

validateInfo(contents)[source]

Error checking on the read YAML file. This is a temporary method.

:
param contents:
the read - in yaml to check
:
type contents:
dict.
:
returns:
True if valid, else false
writeYaml(contents, path)[source]

Overwrites content with YAML representation at given path

paradrop.base.output module

Output mapping, capture, storange, and display.

Some of the methods and choice here may seem strange – they are meant to keep this file in

class BaseOutput(logType)[source]

Bases: object

Base output type class.

This class and its subclasses are registered with an attribute on the global ‘out’ function and is responsible for formatting the given output stream and returning it as a “log structure” (which is a dict.)

For example:
out.info(“Text”, anObject)

requires a custom object to figure out what to do with anObject where the default case will simply parse the string with an appropriate color.

Objects are required to output a dict that mininmally contains the keys message and type.

formatOutput(logDict)[source]

Convert a logdict into a custom formatted, human readable version suitable for printing to console.

class ExceptionOutput(logType)[source]

Bases: paradrop.base.output.BaseOutput

Handle vanilla exceptions passed directly to us using out.exception

class Level

Bases: enum.Enum

ERR = 6
FATAL = 8
HEADER = 1
INFO = 3
PERF = 4
SECURITY = 7
USAGE = 9
VERBOSE = 2
WARN = 5
class Output(**kwargs)[source]

Bases: object

Class that allows stdout/stderr trickery. By default the paradrop object will contain an @out variable (defined below) and it will contain 2 members of “err” and “fatal”.

Each attribute of this class should be a function which points to a class that inherits IOutput(). We call these functions “output streams”.

The way this Output class is setup is that you pass it a series of kwargs like (stuff=OutputClass()). Then at any point in your program you can call “paradrop.out.stuff(‘This is a string

‘)”.

This way we can easily support different levels of verbosity without the need to use some kind of bitmask or anything else. On-the-fly output creation is no longer supported due to the metadata and special processing added. It is still possible, but not implemented.

This is done by the __getattr__ function below, basically in __init__ we set any attributes you pass as args, and anything else not defined gets sent to __getattr__ so that it doesn’t error out.

endLogging()[source]

Ask the printing thread to flush and end, then return.

getLogsSince(target, purge=False)[source]

Reads all logs and returns their contents. The current log file is not touched. Removes old log files if ‘purge’ is set (though this is a topic for debate…)

The server will be most interested in this call, but it needs to register for new logs first, else there’s a good chance to see duplicates.

NOTE: don’t open all log files, check to open only the ones that might be relevant. This is certainly a bug and can cause memory issues.

Parameters:
  • target (float.) – seconds since the GMT epoch. Method returns logs that have timestamps later than this.
  • purge (bool.) – deletes the old log files (except today’s) if set
Returns:

a list of dictionaries containing log information. Not ordered.

handlePrint(logDict)[source]

All printing objects return their messages. These messages are routed to this method for handling.

Send the messages to the printer. Optionally display the messages. Decorate the print messages with metadata.

Parameters:logDict – a dictionary representing this log item. Must contain keys

message and type. :type logDict: dict.

logToConsole(newStatus)[source]
messageToString(message)[source]

Converts message dicts to a format suitable for printing based on the conversion rules laid out in in that class’s implementation.

Parameters:message (dict.) – the dict to convert to string
Returns:str
startLogging(filePath=None, stealStdio=False, printToConsole=True)[source]

Begin logging. The output class is ready to go out of the box, but in order to prevent mere imports from stealing stdio or console logging to vanish these must be manually turned on.

Parameters:
  • filePath (str) – if provided, begin logging to the given directory. If not provided, do not write out logs.
  • stealStdio (bool.) – choose to intercept stdio (including vanilla print statements) or allow it to passthrough
  • printToConsole (bool.) – output the results of all logging to the console. This is primarily a performance consideration when running in production
stealStdio(newStatus)[source]
class OutputRedirect(output, contentAppearedCallback, logType)[source]

Bases: object

Intercepts passed output object (either stdout and stderr), calling the provided callback method when input appears.

Retains the original mappings so writing can still happen. Performs no formatting.

flush()[source]
trueWrite(contents)[source]

Someone really does want to output

write(contents)[source]

Intercept output to the assigned target and callback with it. The true output is returned with the callback so the delegate can differentiate between captured outputs in the case when two redirecters are active.

class PrintLogThread(path, queue, name)[source]

Bases: threading.Thread

All file printing access from one thread.

Receives information when its placed on the passed queue. Called from one location: Output.handlePrint.

Does not close the file: this happens in Output.endLogging. This simplifies the operation of this class, since it only has to concern itself with the queue.

The path must exist before DailyLog runs for the first time.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class TwistedException(logType)[source]

Bases: paradrop.base.output.BaseOutput

class TwistedOutput(logType)[source]

Bases: paradrop.base.output.BaseOutput

blacklist = ['Starting factory', 'Stopping factory', 'Log opened']
parseLogPrefix(tb)[source]

Takes a traceback returned by ‘extract_tb’ and returns the package, module, and line number

silentLogPrefix(stepsUp)[source]

logPrefix v2– gets caller information silently (without caller intervention) The single parameter reflects how far up the stack to go to find the caller and depends how deep the direct caller to this method is wrt to the target caller

NOTE: Some calls cannot be silently prefixed (getting into the twisted code is a great example)

Parameters:stepsUp – the number of steps to move up the stack for the caller

paradrop.base.pdutils module

lib.utils.output. Helper for formatting output from Paradrop.

class Timer(key='', verbose=True)[source]

Bases: object

A timer object for simple benchmarking.

Usage:
with Timer(key=’Name of this test’) as t:
do.someCode(thatTakes=aWhile)

Once the code finishes executing the time is output.

check(pkt, pktType, keyMatches=None, **valMatches)[source]

This function takes an object that was expected to come from a packet (after it has been JSONized) and compares it against the arg requirements so you don’t have to have 10 if() statements to look for keys in a dict, etc..

Args:

@pkt : object to look at @pktType : object type expected (dict, list, etc..) @keyMatches : a list of minimum keys found in parent level of dict, expected to be an array @valMatches : a dict of key:value pairs expected to be found in the parent level of dict

the value can be data (like 5) OR a type (like this value must be a @list@).
Returns:
None if everything matches, otherwise it returns a string as to why it failed.
convertUnicode(elem)[source]

Converts all unicode strings back into UTF-8 (str) so everything works. Call this function like:

json.loads(s, object_hook=convertUnicode)
class dict2obj(aDict=None, **kwargs)[source]

Bases: object

explode(pkt, *args)[source]

This function takes a dict object and explodes it into the tuple requested.

It returns None for any value it doesn’t find.

The only error it throws is if args is not defined.

Example:
pkt = {‘a’:0, ‘b’:1} 0, 1, None = pdcomm.explode(pkt, ‘a’, ‘b’, ‘c’)
jsonPretty(j)[source]

Returns a string of a JSON object in ‘pretty print’ format fully indented, and sorted.

stimestr(x=None)
timedur(x)[source]

Print consistent string format of seconds passed. Example: 300 = ‘5 mins’ Example: 86400 = ‘1 day’ Example: 86705 = ‘1 day, 5 mins, 5 sec’

timeflt()
timeint()
timestr(x=None)
urlDecodeMe(elem)[source]

Converts any values that would cause JSON parsing to fail into URL percent encoding equivalents. This function can be used for any valid JSON type including str, dict, list. Returns:

Same element properly decoded.
urlEncodeMe(elem, safe=' ')[source]

Converts any values that would cause JSON parsing to fail into URL percent encoding equivalents. This function can be used for any valid JSON type including str, dict, list. Returns:

Same element properly encoded.

paradrop.base.settings module

This file contains any settings required by ANY and ALL modules of the paradrop system. They are defaulted to some particular value and can be called by any module in the paradrop system with the following code:

from paradrop import settings print(settings.STUFF)

These settings can be overriden by a KYE:VALUE array

If settings need to be changed, they should be done so by the initialization code (such as pdfcd, pdfc_config, etc…)

This is done by calling the following function:
settings.updateSettings(settings_array)
iterate_module_attributes(module)[source]

Iterate over the attributes in a module.

This is a generator function.

Returns (name, value) tuples.

loadSettings(mode='local', slist=[])[source]

Take a list of key:value pairs, and replace any setting defined. Also search through the settings module and see if any matching environment variables exist to replace as well.

Parameters:slist (array.) – the list of key:val settings
Returns:None
load_from_file(path)[source]

Load settings from an INI file.

This will check the configuration file for a lowercase version of all of the settings in this module. It will look in a section called “base”.

The example below will set PORTAL_SERVER_PORT.

[base] portal_server_port = 4444
parseValue(key)[source]

Attempts to parse the key value, so if the string is ‘False’ it will parse a boolean false.

Parameters:key (string) – the key to parse
Returns:the parsed key.
updatePaths(configHomeDir, runtimeHomeDir='/var/run/paradrop')[source]

Module contents