11 argp
= argparse
.ArgumentParser(description
="Query a function database")
12 argp
.add_argument("file_or_dir", help="function database file (YAML) or project directory")
13 argp
.add_argument("--select", help="fields to select")
14 argp
.add_argument("--where", help="condition of rows to select")
15 argp
.add_argument("--sort", action
="store_true", help="sort resultset")
16 argp
.add_argument("--html", action
="store_true", help="output HTML")
17 args
= argp
.parse_args()
19 if not args
.select
and not args
.where
:
20 argp
.error("At least one of --select or --where should be given")
22 if os
.path
.isdir(args
.file_or_dir
):
23 args
.file_or_dir
+= "/funcdb.yaml"
25 with
open(args
.file_or_dir
) as f
:
26 FUNC_DB
= yaml
.load(f
)
30 #print("where", props)
31 if args
.where
is None:
34 res
= eval(args
.where
, None, props
)
40 #print("select", props)
41 if args
.select
== "*":
43 res
= eval("(" + args
.select
+ ",)", None, props
)
47 for addr
, props
in FUNC_DB
.items():
50 if "calls_indir" not in props
:
51 props
["calls_indir"] = []
53 res
.append(select(props
))
59 print("<html><body><table border='1' cellspacing='0'>")
62 if isinstance(row
, dict):
64 print("<tr><td>" + row
+ "</td></tr>")
68 row
= [str(x
) for x
in row
]
70 print("<tr><td>" + "</td><td>".join(row
) + "</td></tr>")
75 print("</table></body></html>")