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:
Benjamin Bannier 2021-11-24 23:01:26 +01:00
parent 1f388e3f40
commit fd56eddcfb
5 changed files with 39 additions and 14 deletions

View file

@ -12,3 +12,8 @@ repos:
hooks:
- id: shfmt
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
View file

@ -0,0 +1,2 @@
[style]
column_limit=100

View file

@ -53,11 +53,15 @@ namespace zeek::detail {\n
void init_global_dbg_constants () {
''' % inputfile
def outputrecord():
global init_str, enum_str
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:
dbginfo["name_init"] = "const char * const names[] = { };\n"
@ -68,9 +72,18 @@ def outputrecord():
enum_str += "\t%s,\n" % dbginfo["cmd"]
def initdbginfo():
return {"cmd": "", "name_init": "", "num_names": 0, "names": [],
"resume": "false", "help": "", "repeatable": "false"}
return {
"cmd": "",
"name_init": "",
"num_names": 0,
"names": [],
"resume": "false",
"help": "",
"repeatable": "false"
}
dbginfo = initdbginfo()

View file

@ -56,4 +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))
print("%s/%s (%.1f%%) Zeek script statements covered." %
(num_covered, len(stats), float(num_covered) / len(stats) * 100))

View file

@ -2,8 +2,8 @@
import http.server as BaseHTTPServer
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
@ -34,17 +34,21 @@ class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
if __name__ == "__main__":
from optparse import 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), "
"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,
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)
httpd = BaseHTTPServer.HTTPServer((options.addr, options.port), MyRequestHandler)
if options.max == -1:
httpd.serve_forever()
else: