mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Format Python scripts with yapf.
We also add a very basic yapf configuration file. Most of the changes in this patch were performed automatically, but we broke one overly long string into multiple components on `src/make_dbg_constants.py`.
This commit is contained in:
parent
1f388e3f40
commit
fd56eddcfb
5 changed files with 39 additions and 14 deletions
|
@ -12,3 +12,8 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: shfmt
|
- id: shfmt
|
||||||
args: ["-w", "-i", "4", "-ci"]
|
args: ["-w", "-i", "4", "-ci"]
|
||||||
|
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-yapf
|
||||||
|
rev: v0.31.0
|
||||||
|
hooks:
|
||||||
|
- id: yapf
|
||||||
|
|
2
.style.yapf
Normal file
2
.style.yapf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[style]
|
||||||
|
column_limit=100
|
|
@ -53,11 +53,15 @@ namespace zeek::detail {\n
|
||||||
void init_global_dbg_constants () {
|
void init_global_dbg_constants () {
|
||||||
''' % inputfile
|
''' % inputfile
|
||||||
|
|
||||||
|
|
||||||
def outputrecord():
|
def outputrecord():
|
||||||
global init_str, enum_str
|
global init_str, enum_str
|
||||||
|
|
||||||
if dbginfo["names"]:
|
if dbginfo["names"]:
|
||||||
dbginfo["name_init"] = "const char * const names[] = {\n\t\t\t%s\n\t\t};\n" % ",\n\t\t\t".join(dbginfo["names"])
|
dbginfo["name_init"] = "const char * const names[] = {\n"\
|
||||||
|
"\t\t\t%s\n"\
|
||||||
|
"\t\t};\n" \
|
||||||
|
% ",\n\t\t\t".join(dbginfo["names"])
|
||||||
else:
|
else:
|
||||||
dbginfo["name_init"] = "const char * const names[] = { };\n"
|
dbginfo["name_init"] = "const char * const names[] = { };\n"
|
||||||
|
|
||||||
|
@ -68,16 +72,25 @@ def outputrecord():
|
||||||
|
|
||||||
enum_str += "\t%s,\n" % dbginfo["cmd"]
|
enum_str += "\t%s,\n" % dbginfo["cmd"]
|
||||||
|
|
||||||
|
|
||||||
def initdbginfo():
|
def initdbginfo():
|
||||||
return {"cmd": "", "name_init": "", "num_names": 0, "names": [],
|
return {
|
||||||
"resume": "false", "help": "", "repeatable": "false"}
|
"cmd": "",
|
||||||
|
"name_init": "",
|
||||||
|
"num_names": 0,
|
||||||
|
"names": [],
|
||||||
|
"resume": "false",
|
||||||
|
"help": "",
|
||||||
|
"repeatable": "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dbginfo = initdbginfo()
|
dbginfo = initdbginfo()
|
||||||
|
|
||||||
inputf = open(inputfile, "r")
|
inputf = open(inputfile, "r")
|
||||||
for line in inputf:
|
for line in inputf:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line or line.startswith("//"): # skip empty lines and comments
|
if not line or line.startswith("//"): # skip empty lines and comments
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fields = line.split(":", 1)
|
fields = line.split(":", 1)
|
||||||
|
@ -95,9 +108,9 @@ for line in inputf:
|
||||||
dbginfo[f1] = f2
|
dbginfo[f1] = f2
|
||||||
elif f1 == "names":
|
elif f1 == "names":
|
||||||
# put quotes around the strings
|
# put quotes around the strings
|
||||||
dbginfo[f1] = [ '"%s"' % n for n in f2.split() ]
|
dbginfo[f1] = ['"%s"' % n for n in f2.split()]
|
||||||
elif f1 == "help":
|
elif f1 == "help":
|
||||||
dbginfo[f1] = f2.replace('"', '\\"') # escape quotation marks
|
dbginfo[f1] = f2.replace('"', '\\"') # escape quotation marks
|
||||||
elif f1 in ("resume", "repeatable"):
|
elif f1 in ("resume", "repeatable"):
|
||||||
dbginfo[f1] = f2
|
dbginfo[f1] = f2
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -56,4 +56,5 @@ for k in stats:
|
||||||
num_covered += 1
|
num_covered += 1
|
||||||
|
|
||||||
if len(stats) > 0:
|
if len(stats) > 0:
|
||||||
print("%s/%s (%.1f%%) Zeek script statements covered." % (num_covered, len(stats), float(num_covered)/len(stats)*100))
|
print("%s/%s (%.1f%%) Zeek script statements covered." %
|
||||||
|
(num_covered, len(stats), float(num_covered) / len(stats) * 100))
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
import http.server as BaseHTTPServer
|
import http.server as BaseHTTPServer
|
||||||
|
|
||||||
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
||||||
|
|
||||||
|
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-type", "text/plain")
|
self.send_header("Content-type", "text/plain")
|
||||||
|
@ -34,17 +34,21 @@ class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
p = OptionParser()
|
p = OptionParser()
|
||||||
p.add_option("-a", "--addr", type="string", default="localhost",
|
p.add_option("-a",
|
||||||
|
"--addr",
|
||||||
|
type="string",
|
||||||
|
default="localhost",
|
||||||
help=("listen on given address (numeric IP or host name), "
|
help=("listen on given address (numeric IP or host name), "
|
||||||
"an empty string (the default) means INADDR_ANY"))
|
"an empty string (the default) means INADDR_ANY"))
|
||||||
p.add_option("-p", "--port", type="int", default=32123,
|
p.add_option("-p", "--port", type="int", default=32123, help="listen on given TCP port number")
|
||||||
help="listen on given TCP port number")
|
p.add_option("-m",
|
||||||
p.add_option("-m", "--max", type="int", default=-1,
|
"--max",
|
||||||
|
type="int",
|
||||||
|
default=-1,
|
||||||
help="max number of requests to respond to, -1 means no max")
|
help="max number of requests to respond to, -1 means no max")
|
||||||
options, args = p.parse_args()
|
options, args = p.parse_args()
|
||||||
|
|
||||||
httpd = BaseHTTPServer.HTTPServer((options.addr, options.port),
|
httpd = BaseHTTPServer.HTTPServer((options.addr, options.port), MyRequestHandler)
|
||||||
MyRequestHandler)
|
|
||||||
if options.max == -1:
|
if options.max == -1:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue