mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-18 10:35:27 +00:00
style fix delete_table.py
This commit is contained in:
parent
9b0c0719d8
commit
767eb1d882
@ -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'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user