From 767eb1d882cc74271b3609dc36e7d13c5fee8ea0 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 6 Sep 2015 19:02:43 +0200 Subject: [PATCH] style fix delete_table.py --- src/opnsense/scripts/filter/delete_table.py | 38 +++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/opnsense/scripts/filter/delete_table.py b/src/opnsense/scripts/filter/delete_table.py index ebd43b88c..17d48efc8 100755 --- a/src/opnsense/scripts/filter/delete_table.py +++ b/src/opnsense/scripts/filter/delete_table.py @@ -33,22 +33,24 @@ import tempfile import subprocess import os import sys -import ujson -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')) - 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')) - else: - for line in output_stream.read().strip().split('\n'): - if line.strip() == sys.argv[2].strip(): - result = [] - subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'delete', line.strip()], - stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb')) +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')) + 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')) + else: + for line in output_stream.read().strip().split('\n'): + if line.strip() == sys.argv[2].strip(): + result = [] + subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'delete', line.strip()], + stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'))