paradrop.lib.utils package¶
Submodules¶
paradrop.lib.utils.addresses module¶
-
checkPhyExists
(radioid)[source]¶ Check if this chute exists at all, a directory /sys/class/ieee80211/phyX must exist.
-
getGatewayIntf
(ch)[source]¶ Looks at the key:networkInterfaces for the chute and determines what the gateway should be including the IP address and the internal interface name.
- Returns:
- A tuple (gatewayIP, gatewayInterface) None if networkInterfaces doesn’t exist or there is an error
-
getInternalIntfList
(ch)[source]¶ 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, …)
- Returns:
- A list of interface names None if networkInterfaces doesn’t exist or there is an error
-
getWANIntf
(ch)[source]¶ Looks at the key:networkInterfaces for the chute and finds the WAN interface.
- Returns:
- 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.
- Returns:
- 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.
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
paradrop.lib.utils.pdos module¶
-
basename
(x)¶
-
fixpath
(p)[source]¶ 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.
-
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)- Returns:
- 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- Returns:
- A list of strings, separated by newlines None: if the file doesn’t exist
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.
-
makedirs
(p)[source]¶ 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.
-
safe_remove
(path)[source]¶ 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)]
-
delConfig
(config, options)[source]¶ Finds a match to the config input and removes it from the internal config data structure.
-
existsConfig
(config, options)[source]¶ Tests if the (config, options) is in the current config file.
-
getConfigIgnoreComments
(config)[source]¶ Returns a list of call configs with the given title. Comments are ignored.
-
restore
(backupToken, saveBackup=True)[source]¶ Replaces real file (at /etc/config/) with backup copy from /tmp/-@backupToken location.
- Arguments:
- 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)
-
chuteConfigsMatch
(chutePre, chutePost)[source]¶ Takes two lists of objects, and returns whether or not they are identical.
-
getLineParts
(line)[source]¶ Split the UCI line into its whitespace-separated parts.
Returns a list of strings, with apostrophes removed.
paradrop.lib.utils.uhttp module¶
-
class
UHTTPConnection
(path)[source]¶ Bases:
httplib.HTTPConnection
Subclass of Python library HTTPConnection that uses a unix-domain socket.
Source: http://7bits.nl/blog/posts/http-on-unix-sockets-with-python