-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyzer.py
36 lines (32 loc) · 1.36 KB
/
analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import argparse
import os
import lizard
import json
#-------------------Setting/getting the args---------------------------------------------
parser = argparse.ArgumentParser(description="Arguments for CodeAnalytics-analyzer")
parser.add_argument('-p', type=str, required=True,
help='Required. The path to a repo containing code.')
args = parser.parse_args()
#-------------------Done setting/getting args--------------------------------------------
def main_function():
arr = [] # array containing every analyzed file
for subdir, dirs, files in os.walk(args.p): # go through every file within a given directory
for file in files:
file_path = subdir + os.sep + file
if file_path.endswith('.cpp') or file_path.endswith('.py') or file_path.endswith('.js') or file_path.endswith('.java'):
i = lizard.analyze_file(file_path)
print(i.function_list[0].__dict__)
my_json = json.dumps(i.function_list[0].__dict__, indent=4)
arr.append(my_json)
with open('data.json', 'w') as outfile:
outfile.write("[\n")
first = True
for item in arr:
if first == True:
first = False
else:
outfile.write(",\n")
outfile.write(item)
outfile.write("\n]")
if __name__ == "__main__":
main_function()