Commit 9d4b6038 authored by Ad Schellevis's avatar Ad Schellevis

style fix pfinfo.py

parent c60b9873
...@@ -35,18 +35,19 @@ import os ...@@ -35,18 +35,19 @@ import os
import sys import sys
import ujson import ujson
result=collections.OrderedDict() if __name__ == '__main__':
for stattype in ['info', 'memory', 'timeouts', 'Interfaces']: result = collections.OrderedDict()
with tempfile.NamedTemporaryFile() as output_stream: for stattype in ['info', 'memory', 'timeouts', 'Interfaces']:
subprocess.call(['/sbin/pfctl','-vvs'+stattype], stdout=output_stream, stderr=open(os.devnull, 'wb')) with tempfile.NamedTemporaryFile() as output_stream:
output_stream.seek(0) subprocess.call(['/sbin/pfctl', '-vvs'+stattype], stdout=output_stream, stderr=open(os.devnull, 'wb'))
result[stattype] = output_stream.read().strip() output_stream.seek(0)
result[stattype] = output_stream.read().strip()
# handle command line argument (type selection)
if len(sys.argv) > 1 and sys.argv[1] == 'json': # handle command line argument (type selection)
print(ujson.dumps(result)) if len(sys.argv) > 1 and sys.argv[1] == 'json':
else: print(ujson.dumps(result))
# output plain else:
for stattype in result: # output plain
print ('------------------------- %s -------------------------' % (stattype) ) for stattype in result:
print (result[stattype]) print ('------------------------- %s -------------------------' % stattype)
print (result[stattype])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment