Commit 767eb1d8 authored by Ad Schellevis's avatar Ad Schellevis

style fix delete_table.py

parent 9b0c0719
......@@ -33,19 +33,21 @@ import tempfile
import subprocess
import os
import sys
import ujson
result = []
if len(sys.argv) > 2:
if __name__ == '__main__':
result = []
if len(sys.argv) > 2:
# always validate if the item is in the pf table before trying to delete
with tempfile.NamedTemporaryFile() as output_stream:
# delete an entry from a pf table
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'show'], stdout=output_stream, stderr=open(os.devnull, 'wb'))
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'show'],
stdout=output_stream, stderr=open(os.devnull, 'wb'))
output_stream.seek(0)
if sys.argv[2].strip() == 'ALL':
if len(output_stream.read().strip().split('\n')) > 0:
# delete all entries from a pf table
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'flush'], stdout=output_stream, stderr=open(os.devnull, 'wb'))
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'flush'],
stdout=output_stream, stderr=open(os.devnull, 'wb'))
else:
for line in output_stream.read().strip().split('\n'):
if line.strip() == sys.argv[2].strip():
......
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