paradrop.lib.utils package


paradrop.lib.utils.addresses module


Check if this chute exists at all, a directory /sys/class/ieee80211/phyX must exist.


Looks at the key:networkInterfaces for the chute and determines what the gateway should be including the IP address and the internal interface name.

A tuple (gatewayIP, gatewayInterface) None if networkInterfaces doesn’t exist or there is an error

Takes a chute object and uses the key:networkInterfaces to return a list of the internal network interfaces that will exist in the chute (e.g., eth0, eth1, …)

A list of interface names None if networkInterfaces doesn’t exist or there is an error
getSubnet(ipaddr, netmask)[source]

Looks at the key:networkInterfaces for the chute and finds the WAN interface.

The dict from networkInterfaces None
incIpaddr(ipaddr, inc=1)[source]

Takes a quad dot format IP address string and adds the @inc value to it by converting it to a number.

Incremented quad dot IP string or None if error
isIpAvailable(ipaddr, chuteStor, name)[source]

Make sure this IP address is available.

Checks the IP addresses of all zones on all other chutes, makes sure subnets are not the same.


Return True if Valid, otherwise False.

isStaticIpAvailable(ipaddr, chuteStor, name)[source]

Make sure this static IP address is available.

Checks the IP addresses of all zones on all other chutes, makes sure not equal.

isWifiSSIDAvailable(ssid, chuteStor, name)[source]

Make sure this SSID is available.

maxIpaddr(ipaddr, netmask)[source]

Takes a quad dot format IP address string and makes it the largest valid value still in the same subnet.

Max quad dot IP string or None if error

paradrop.lib.utils.datastruct module

Utilities for reading from data structures.

getValue(struct, path, default=None)[source]

Read a value from the data structure.

Arguments: struct can comprise one or more levels of dicts and lists. path should be a string using dots to separate levels. default will be returned if the path cannot be traced.

Example: getValue({‘a’: [1, 2, 3]}, “a.1”) -> 2 getValue({‘a’: [1, 2, 3]}, “a.3”) -> None

paradrop.lib.utils.pd_storage module

class PDStorage(filename, saveTimer)[source]

Bases: object

ParaDropStorage class.

This class is designed to be implemented by other classes. Its purpose is to make whatever data is considered important persistant to disk.

The implementer can override functions in order to implement this class:
getAttr() : Get the attr we need to save to disk setAttr() : Set the attr we got from disk importAttr(): Takes a payload and returns the properly formatted data exportAttr(): Takes the data and returns a payload attrSaveable(): Returns True if we should save this attr



By default do nothing, but expect that this function could be overwritten


By default do nothing, but expect that this function could be overwritten


Attempts to load the data from disk. Returns True if success, False otherwise.


Saves the data to disk.

paradrop.lib.utils.pdos module

copy(a, b)[source]
copytree(a, b)[source]

shutil’s copytree is dumb so use distutils.


This function is required because if we need to pass a path to something like tarfile, we cannot overwrite the function to fix the path, so we need to expose it somehow.


This function checks if @mnt is actually mounted.

move(a, b)[source]
open(p, mode)[source]
oscall(cmd, get=False)[source]

This function performs a OS subprocess call. All output is thrown away unless an error has occured or if @get is True Arguments:

@cmd: the string command to run [get] : True means return (stdout, stderr)
None if not @get and no error (stdout, retcode, stderr) if @get or yes error
readFile(filename, array=True, delimiter='\n')[source]

Reads in a file, the contents is NOT expected to be binary. Arguments:

@filename: absolute path to file @array : optional: return as array if true, return as string if False @delimiter: optional: if returning as a string, this str specifies what to use to join the lines
A list of strings, separated by newlines None: if the file doesn’t exist
read_sys_file(path, default=None)[source]

Read a file and return the contents as a string.

This is best suited for files that store a single line of text such as files in /sys/.

Returns the default value if an error occurs.

remove(path, suppressNotFound=False)[source]
write(filename, data, mode='w')[source]

Writes out a config file to the specified location.

writeFile(filename, line, mode='a')[source]

Adds the following cfg (either str or list(str)) to this Chute’s current config file (just stored locally, not written to file.

paradrop.lib.utils.pdosq module

Quiet pdos module. Implements utility OS operations without relying on the output module. Therefore, this module can be used by output without circular dependency.


Recursive directory creation (like mkdir -p). Returns True if the path is successfully created, False if it existed already, and raises an OSError on other error conditions.

read_yaml_file(path, default=None)[source]

Read the contents of a file and interpret as YAML.

default: return value if the file cannot be read.


Remove a file or silently pass if the file does not exist.

This function has the same effect as os.remove but suppresses the error if the file did not exist. Notably, it must not be used to remove directories.

Returns True if a file was removed or False if no file was removed.

paradrop.lib.utils.uci module

class UCIConfig(filepath)[source]
Wrapper around the UCI configuration files.

These files are found under /etc/config/, and are used by OpenWrt to keep track of configuration for modules typically found in /etc/init.d/

The modules of interest and with current support are:
  • firewall
  • network
  • wireless
  • qos
  • This class should work with any UCI module but ALL others are UNTESTED!

New configuration settings can be added to the UCI file via addConfig().

Each UCI config file is expected to contain the following syntax:

config keyA [valueA]
option key1 value1 … list key2 value1 list key2 value2 … list key3 value1 list key3 value2
Based on the UCI file above, the config syntax would look like the following:

config is a list of tuples, containing 2 dict objects in each tuple:

  • tuple[0] describes the first line (config keyA [valueA])

    {‘type’: keyA, ‘name’: valueA} The value parameter is optional and if missing, then the ‘name’ key is also missing (rather than set to None).

  • tuple[1] describes the options associated with the settings (both ‘option’ and ‘list’ lines)

    {‘key1’: ‘value1’, …}

    If a list is present, it looks like the following:

    …, ‘key2’: [value1, value2, …], ‘key3’: [value1, value2, …]


So for the example above, the full config definition would look like:
C = {‘type’: ‘keyA’, ‘name’: ‘valueA’} O = {‘key1’: ‘value1’, ‘key2’: [‘value1’, ‘value2’], ‘key3’: [‘value1’, ‘value2’]} config = [(C, O)]
addConfig(config, options)[source]

Adds the tuple to our config.


Adds a list of tuples to our config


Puts a backup of this config to the location specified in @backupPath.

delConfig(config, options)[source]

Finds a match to the config input and removes it from the internal config data structure.


Adds a list of tuples to our config

existsConfig(config, options)[source]

Tests if the (config, options) is in the current config file.


Returns a list of call configs with the given title


Returns a list of call configs with the given title. Comments are ignored.


Reads in the config file.

restore(backupToken, saveBackup=True)[source]

Replaces real file (at /etc/config/) with backup copy from /tmp/-@backupToken location.

backupToken: The backup token appended at the end of the backup path saveBackup : A flag to keep a backup copy or delete it (default is keep backup)
save(backupToken='paradrop', internalid=None)[source]

Saves out the file in the proper format.

[backupPath] : Save a backup copy of the UCI file to the path provided.
Should be a token name like ‘backup’, it gets appended with a hyphen.
chuteConfigsMatch(chutePre, chutePost)[source]

Takes two lists of objects, and returns whether or not they are identical.


Split the UCI line into its whitespace-separated parts.

Returns a list of strings, with apostrophes removed.


Get the path to the system configuration file.

This function also attempts to create the configuration directory if it does not exist.

Typical filenames: network, wireless, qos, firewall, dhcp, etc.

isMatch(a, b)[source]
isMatchIgnoreComments(a, b)[source]
singleConfigMatches(a, b)[source]

Recursively convert all primitives in a data structure to strings.


Convert option value from in-memory representation to a suitable string.

In particular, boolean values are converted to ‘0’ or ‘1’.

paradrop.lib.utils.uhttp module

class UHTTPConnection(path)[source]

Bases: httplib.HTTPConnection

Subclass of Python library HTTPConnection that uses a unix-domain socket.



Module contents