aboutsummaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/netif.py20
-rw-r--r--helpers/sysstatus.py30
-rw-r--r--helpers/tor.py4
-rw-r--r--helpers/util.py4
4 files changed, 57 insertions, 1 deletions
diff --git a/helpers/netif.py b/helpers/netif.py
index 77f710c..529444d 100644
--- a/helpers/netif.py
+++ b/helpers/netif.py
@@ -1,3 +1,7 @@
+"""
+Helper functions for working with network interfaces and network configuration
+(including WiFi).
+"""
import os
import augeas
@@ -6,7 +10,14 @@ from util import *
def parse_ip(ifname):
"""
- Example ip link show string:
+ Calls the ``ip`` command and parse the output to collect current status
+ information about a given network interface (specified by ifname argument).
+
+ Returns a dictionary, notably always including a 'state' string value.
+
+ If the interface can not be found at all, raises a KeyError.
+
+ Example ``ip link show`` string:
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
link/ether 00:12:34:56:78:90 brd ff:ff:ff:ff:ff:ff
@@ -47,6 +58,13 @@ def parse_ip(ifname):
def parse_iw(ifname):
"""
+ Calls the ``iw`` command and parse the output to collect current status
+ information about a given network interface (specified by ifname argument).
+
+ Returns a dictionary, notably always including a 'state' string value.
+
+ If the interface can not be found at all, raises a KeyError.
+
Example `iw dev wlan0 link` string (sic):
Connected to c0:25:06:51:22:9b (on wlan0)
diff --git a/helpers/sysstatus.py b/helpers/sysstatus.py
index 933f625..99c209b 100644
--- a/helpers/sysstatus.py
+++ b/helpers/sysstatus.py
@@ -1,3 +1,7 @@
+"""
+Helper code for agregating general system status information, and for reading
+in system log files.
+"""
import os
@@ -13,6 +17,23 @@ def get_system_status():
return d
def get_resources_status():
+ """
+ Example ``df -h /home`` output:
+
+ Filesystem Size Used Avail Use% Mounted on
+ /dev/mapper/xxxxx-root 231G 184G 35G 85% /
+
+ Example ``free -m`` output:
+
+ total used free shared buffers cached
+ Mem: 3862 2292 1570 0 104 689
+ -/+ buffers/cache: 1498 2364
+ Swap: 7983 202 7781
+
+ Example ``uptime`` output:
+
+ 21:38:55 up 7 days, 5:43, 11 users, load average: 0.60, 0.63, 0.63
+ """
d = dict()
disk_info = cli_read_lines('df -h /home')[1].split()
d['disk_used'] = disk_info[2]
@@ -55,6 +76,15 @@ def get_syslog():
return None
def get_process_list():
+ """
+ Example ``ps aux`` output:
+
+ USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
+ root 1 0.0 0.0 10636 676 ? Ss Sep08 0:05 init [2]
+ root 2 0.0 0.0 0 0 ? S Sep08 0:00 [kthreadd]
+ root 3 0.0 0.0 0 0 ? S Sep08 0:40 [ksoftirqd/0]
+ root 6 0.0 0.0 0 0 ? S Sep08 0:00 [migration/0]
+ """
plist = list()
first = True
for l in cli_read_lines('ps aux --sort -%mem')[1:]:
diff --git a/helpers/tor.py b/helpers/tor.py
index 438cb5d..d639ce2 100644
--- a/helpers/tor.py
+++ b/helpers/tor.py
@@ -1,3 +1,7 @@
+"""
+Helper code for interacting with Tor and modifying the Tor system
+configuration.
+"""
def get_tor_status():
d = dict()
diff --git a/helpers/util.py b/helpers/util.py
index 229d975..dc3b6c0 100644
--- a/helpers/util.py
+++ b/helpers/util.py
@@ -1,3 +1,7 @@
+"""
+Utility functions used by helper code to crudely grab the output of simple UNIX
+command line programs, plus a couple misc other functions.
+"""
import os