diff --git a/gen/extract.py b/gen/extract.py index c01c504..16d103a 100755 --- a/gen/extract.py +++ b/gen/extract.py @@ -4,6 +4,8 @@ import re import os import pprint +import json + def create_paths_list(dirname, filenames): paths = [] @@ -35,43 +37,53 @@ def extract_functions(file_content): 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(): # Input prefix = r"/Users/heck/local-default/" filenames = ["pEpEngine.h", "keymanagement.h"] - # Output out_dir = "data/" basename = prefix + r"include/pEp/" - # Create out dir if not os.path.isdir(out_dir): os.makedirs(out_dir) - # Parse input paths = create_paths_list(basename, filenames) headers = read_files(paths) - # Process and create data structure for header in headers: - print("processing path: " + header.get("path") + "...") - basename = os.path.basename(header.get("path")) - - # add outpath - outpath = out_dir + basename - header["outpath"] = outpath + # Process + header = process(header, out_dir) + # Output + write_json(header) - # 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__": main()