
1 changed files with 77 additions and 0 deletions
@ -0,0 +1,77 @@ |
|||
#!/usr/bin/env python3 |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
import re |
|||
import os |
|||
import pprint |
|||
|
|||
def create_paths_list(dirname, filenames): |
|||
paths = [] |
|||
for basename in filenames: |
|||
path = dirname + basename |
|||
paths.append(path) |
|||
return paths |
|||
|
|||
|
|||
def read_files(paths): |
|||
content = [] |
|||
for path in paths: |
|||
file_info = read_file(path) |
|||
content.append(file_info) |
|||
return content |
|||
|
|||
|
|||
def read_file(path): |
|||
with open(path) as f: |
|||
file_content = f.read() |
|||
item = {"path": path, |
|||
"content": file_content} |
|||
return item |
|||
|
|||
|
|||
def extract_functions(file_content): |
|||
pattr = re.compile("DYNAMIC_API.*?\);", re.DOTALL) |
|||
res = pattr.findall(file_content) |
|||
return res |
|||
|
|||
|
|||
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 |
|||
|
|||
# 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() |
Loading…
Reference in new issue