Browse Source

add json output format and simply list functions

master
heck 5 years ago
parent
commit
9127f98e1b
  1. 50
      gen/extract.py

50
gen/extract.py

@ -4,6 +4,8 @@
import re import re
import os import os
import pprint import pprint
import json
def create_paths_list(dirname, filenames): def create_paths_list(dirname, filenames):
paths = [] paths = []
@ -35,43 +37,53 @@ def extract_functions(file_content):
return res return res
def process(header, out_dir):
# Process and create data structure
print("processing path: " + header.get("path") + "...")
basename = os.path.basename(header.get("path"))
# strip suffix, will be added output format dependently
basename_minus_suffix = re.sub("\..*$",'',basename)
# add outpath
outpath = out_dir + basename_minus_suffix
header["outpath"] = outpath
# add functions
functions = extract_functions(header.get("content"))
header["functions"] = functions
return header
def write_json(header):
header["outpath"] += ".json"
with open(header.get("outpath"), "w+") as f:
json.dump(header, f, indent=4)
def main(): def main():
# Input # Input
prefix = r"/Users/heck/local-default/" prefix = r"/Users/heck/local-default/"
filenames = ["pEpEngine.h", filenames = ["pEpEngine.h",
"keymanagement.h"] "keymanagement.h"]
# Output # Output
out_dir = "data/" out_dir = "data/"
basename = prefix + r"include/pEp/" basename = prefix + r"include/pEp/"
# Create out dir
if not os.path.isdir(out_dir): if not os.path.isdir(out_dir):
os.makedirs(out_dir) os.makedirs(out_dir)
# Parse input
paths = create_paths_list(basename, filenames) paths = create_paths_list(basename, filenames)
headers = read_files(paths) headers = read_files(paths)
# Process and create data structure
for header in headers: for header in headers:
print("processing path: " + header.get("path") + "...") # Process
basename = os.path.basename(header.get("path")) header = process(header, out_dir)
# Output
# add outpath write_json(header)
outpath = out_dir + basename
header["outpath"] = outpath
# add functions
functions = extract_functions(header.get("content"))
header["functions"] = functions
# Output
for header in headers:
with open(header.get("outpath"), "w+") as f:
pprint.pp(header)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save