-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (82 loc) · 3.14 KB
/
main.py
File metadata and controls
93 lines (82 loc) · 3.14 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from generatorfind.discern2 import Discern2
from generatorfind.folderCalls import FolderCalls
from generatorfind.ast_to_csv import AstToCsv
from generatorfind.sourcemap import Sourcemap
from generatorfind import labeller
import sys, os, time
import click
'''
Discern2 is used when we only work with one file,
and FolderCalls is for folders
'''
@click.command()
@click.argument('name', nargs = 1)
@click.option('--ast', is_flag = True, help='This generates a .csv file with the AST')
@click.option('--sourcemap', is_flag = True, help = "This generates the sourcemap of our folder")
@click.option('--calls', is_flag = True)
@click.option('--label', help = 'Enter the path of the file with the information about the generator')
def main(name, ast, sourcemap, calls, label):
start = time.time()
if ast:
if isOnePythonFile(name):
raise Exception('We can only generate ASTs of full projects')
else:
generate_ast = AstToCsv(name)
generate_ast.main()
if sourcemap:
if isOnePythonFile(name):
raise Exception('We can only generate ASTs of full projects')
else:
generate_ast = Sourcemap(name)
generate_ast.main()
if calls:
if isOnePythonFile(name):
# name is a python file name
processPythonFile(name)
else:
# name is a folder
processFolder(name)
if label:
labeller.main(name, label)
printExecTime(start)
def isOnePythonFile(param):
return param.endswith('.py')
def processPythonFile(name):
print("***************************************\n")
print("***Estamos trabajando con DISCERN2.***\n")
print("***************************************\n")
ls = getFilePathsFromParam2()
script = Discern2(name, ls)
script._generatorfind()
script.assign_call_find()
print('->LOS ASSIGNS SON LOS SIGUIENTES: ', script.assigns)
print('\n-> LOS GENERATORS SON LOS SIGUIENTES: ', script.generators)
print('\n-> LOS CALLS QUE HEMOS ENCONTRADO SON LOS SIGUIENTES: \n', script.calls)
print('\n SOURCEMAP: ', script._mapeo())
print('---------------------------------------------------------------------------------------------\n')
def processFolder(name):
print("***************************************\n")
print("***Estamos trabajando con FOLDER Y DISCERN2.***\n")
print("***************************************\n")
script = FolderCalls(name)
script.files_with_generators()
print('Los calls son: ')
print(script.callsites())
def getFilePathsFromParam2():
ls = sys.argv[2:]
for i in range(len(ls)):
ls[i] = os.path.abspath(ls[i])
return ls
def printExecTime(start):
end = time.time()
print("---------")
tiempoej = end-start
if tiempoej > 60:
tiempoejmin = tiempoej // 60
tiempoejsec = tiempoej % 60
print('Execution time:', tiempoejmin, 'min and ', tiempoejsec, 'seconds.')
else:
print('Execution time:', end-start, 'seconds.')
print('-----------------------------------------------------------------------------------------------------\n')
if __name__ == '__main__':
main()