diff options
author | ficus <ficus@robocracy.org> | 2012-09-14 20:10:43 +0200 |
---|---|---|
committer | ficus <ficus@robocracy.org> | 2012-09-14 20:10:43 +0200 |
commit | a304d7a56563b16ca98d9b45ebed521c52f6347c (patch) | |
tree | da88f01977c08d9a149c3e767f1a7e62981500b9 /helpers/util.py | |
download | tui-a304d7a56563b16ca98d9b45ebed521c52f6347c.tar.gz tui-a304d7a56563b16ca98d9b45ebed521c52f6347c.zip |
backup WIP
Diffstat (limited to 'helpers/util.py')
-rw-r--r-- | helpers/util.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/helpers/util.py b/helpers/util.py new file mode 100644 index 0000000..46030bf --- /dev/null +++ b/helpers/util.py @@ -0,0 +1,24 @@ + +import os + +def cli_read(cmd): + p = os.popen(cmd) + return ''.join(p.readlines()) + +def cli_read_lines(cmd): + p = os.popen(cmd) + return p.readlines() + +def fs_read(path): + with open(path, 'r') as f: + return '\n'.join(f.readlines()).strip() + +def prefix_to_ipv4_mask(prefixlen): + assert(prefixlen >= 0) + assert(prefixlen <= 32) + mask = (0xFFFFFFFF & (0xFFFFFFFF << (32 - prefixlen))) + a = (0xFF000000 & mask) >> 24 + b = (0x00FF0000 & mask) >> 16 + c = (0x0000FF00 & mask) >> 8 + d = (0x000000FF & mask) + return '%d.%d.%d.%d' % (a, b, c, d) |