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

@ -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,16 +72,25 @@ 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()
inputf = open(inputfile, "r")
for line in inputf:
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
fields = line.split(":", 1)
@ -95,9 +108,9 @@ for line in inputf:
dbginfo[f1] = f2
elif f1 == "names":
# 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":
dbginfo[f1] = f2.replace('"', '\\"') # escape quotation marks
dbginfo[f1] = f2.replace('"', '\\"') # escape quotation marks
elif f1 in ("resume", "repeatable"):
dbginfo[f1] = f2
else: