mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Swap pre-commit yapf for ruff/ruff-format, fix findings
This commit is contained in:
parent
b02f812e26
commit
49f82b325b
9 changed files with 110 additions and 81 deletions
|
@ -6,28 +6,26 @@ if len(sys.argv) != 2:
|
|||
print("Expected one argument containing the file to clean")
|
||||
sys.exit(-1)
|
||||
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
|
||||
with open(sys.argv[1]) as f:
|
||||
files = {}
|
||||
cur_file = ''
|
||||
cur_file = ""
|
||||
lines = f.readlines()
|
||||
|
||||
for line in lines:
|
||||
|
||||
if line == 'end_of_record':
|
||||
cur_file = ''
|
||||
if line == "end_of_record":
|
||||
cur_file = ""
|
||||
continue
|
||||
|
||||
parts = line.split(':', 1)
|
||||
if parts[0] == 'SF':
|
||||
parts = line.split(":", 1)
|
||||
if parts[0] == "SF":
|
||||
cur_file = parts[1].strip()
|
||||
while cur_file.find('src/zeek/') != -1:
|
||||
cur_file = cur_file.replace('src/zeek/', 'src/', 1)
|
||||
while cur_file.find("src/zeek/") != -1:
|
||||
cur_file = cur_file.replace("src/zeek/", "src/", 1)
|
||||
|
||||
if cur_file not in files:
|
||||
files[cur_file] = {}
|
||||
elif parts[0] == 'DA':
|
||||
da_parts = parts[1].split(',')
|
||||
elif parts[0] == "DA":
|
||||
da_parts = parts[1].split(",")
|
||||
line = int(da_parts[0])
|
||||
count = int(da_parts[1])
|
||||
|
||||
|
@ -35,13 +33,12 @@ with open(sys.argv[1], 'r') as f:
|
|||
files[cur_file][line] = count
|
||||
|
||||
for name in files:
|
||||
|
||||
print('TN:')
|
||||
print('SF:{}'.format(name))
|
||||
print("TN:")
|
||||
print(f"SF:{name}")
|
||||
|
||||
das = list(files[name].keys())
|
||||
das.sort()
|
||||
|
||||
for da in das:
|
||||
print('DA:{},{}'.format(da, files[name][da]))
|
||||
print('end_of_record')
|
||||
print(f"DA:{da},{files[name][da]}")
|
||||
print("end_of_record")
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
# that are not part of the distribution and which should not count towards
|
||||
# the coverage calculation.
|
||||
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
|
||||
stats = {}
|
||||
inputglob = sys.argv[1]
|
||||
|
@ -20,7 +20,7 @@ outputfile = sys.argv[2]
|
|||
scriptdir = os.path.abspath(sys.argv[3])
|
||||
|
||||
for filename in glob.glob(inputglob):
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename) as f:
|
||||
for line in f.read().splitlines():
|
||||
parts = line.split("\t")
|
||||
exec_count = int(parts[0])
|
||||
|
@ -34,7 +34,7 @@ for filename in glob.glob(inputglob):
|
|||
srclines = srclines.split()[1]
|
||||
# For sorting purposes (so that line numbers get sorted correctly),
|
||||
# construct a specially-formatted key string.
|
||||
sortkey = filepath + ", line " + ("%6s" % srclines.split("-")[0])
|
||||
sortkey = filepath + ", line " + ("{:<6s}".format(srclines.split("-")[0]))
|
||||
location = filepath + ", line " + srclines
|
||||
desc = parts[2]
|
||||
# Keying by location + desc may result in duplicate data
|
||||
|
@ -46,9 +46,9 @@ for filename in glob.glob(inputglob):
|
|||
else:
|
||||
stats[key] = [exec_count, location, desc, sortkey]
|
||||
|
||||
with open(outputfile, 'w') as f:
|
||||
with open(outputfile, "w") as f:
|
||||
for k in sorted(stats, key=lambda i: stats[i][3]):
|
||||
f.write("%s\t%s\t%s\n" % (stats[k][0], stats[k][1], stats[k][2]))
|
||||
f.write(f"{stats[k][0]}\t{stats[k][1]}\t{stats[k][2]}\n")
|
||||
|
||||
num_covered = 0
|
||||
for k in stats:
|
||||
|
@ -56,5 +56,5 @@ for k in stats:
|
|||
num_covered += 1
|
||||
|
||||
if len(stats) > 0:
|
||||
print("%s/%s (%.1f%%) Zeek script statements covered." %
|
||||
(num_covered, len(stats), float(num_covered) / len(stats) * 100))
|
||||
pct = float(num_covered) / len(stats) * 100
|
||||
print(f"{num_covered}/{len(stats)} ({pct:.1f}%) Zeek script statements covered.")
|
||||
|
|
|
@ -4,7 +4,6 @@ import http.server as BaseHTTPServer
|
|||
|
||||
|
||||
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
|
@ -34,19 +33,32 @@ class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
|
||||
if __name__ == "__main__":
|
||||
from optparse import OptionParser
|
||||
|
||||
p = OptionParser()
|
||||
p.add_option("-a",
|
||||
"--addr",
|
||||
type="string",
|
||||
default="localhost",
|
||||
help=("listen on given address (numeric IP or host name), "
|
||||
"an empty string (the default) means INADDR_ANY"))
|
||||
p.add_option("-p", "--port", type="int", default=32123, help="listen on given TCP port number")
|
||||
p.add_option("-m",
|
||||
"--max",
|
||||
type="int",
|
||||
default=-1,
|
||||
help="max number of requests to respond to, -1 means no max")
|
||||
p.add_option(
|
||||
"-a",
|
||||
"--addr",
|
||||
type="string",
|
||||
default="localhost",
|
||||
help=(
|
||||
"listen on given address (numeric IP or host name), "
|
||||
"an empty string (the default) means INADDR_ANY"
|
||||
),
|
||||
)
|
||||
p.add_option(
|
||||
"-p",
|
||||
"--port",
|
||||
type="int",
|
||||
default=32123,
|
||||
help="listen on given TCP port number",
|
||||
)
|
||||
p.add_option(
|
||||
"-m",
|
||||
"--max",
|
||||
type="int",
|
||||
default=-1,
|
||||
help="max number of requests to respond to, -1 means no max",
|
||||
)
|
||||
options, args = p.parse_args()
|
||||
|
||||
httpd = BaseHTTPServer.HTTPServer((options.addr, options.port), MyRequestHandler)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue