-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.py
75 lines (69 loc) · 1.92 KB
/
cli.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
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
"""
A command line interface for running python programs and getting audio output
"""
import sys
from helpers import (
store_output,
sayFunc,
read_program,
build_trycatch,
)
import io
# pylint: disable=no-value-for-parameter
# pylint: disable=broad-except
# pylint: disable=import-outside-toplevel
def main(file):
"""
Cli for running python programs
"""
try:
assert file[-3:] == ".py"
except AssertionError:
sayFunc("File not ending in .py", 120)
sys.exit(1)
try:
with open(file, "rb") as source_file:
code = compile(source_file.read(), file, "exec")
print(code)
try:
exec(code)
output = 1
return output
except Exception as e:
print(e)
build_trycatch(file)
from test import test
line, text, name, error = test()
name = str(name).split("'")[1]
line -= 4
repeat = "R"
while repeat in ("r", "R"):
sayFunc(
"There is a error in your program. "
+ file
+ "The error is as follows. "
+ name
+ str(error),
100,
)
sayFunc("Line" + str(line) + "is. " + text, 130)
repeat = "l"
return error
except SyntaxError as err:
_, error, _ = sys.exc_info()
repeat = "R"
while repeat in ("r", "R"):
sayFunc(
"There is a error in your program. "
+ file
+ "The error is as follows. "
+ str(err),
100,
)
repeat = "l"
sayFunc(
"Line" + str(line) + "is. " + file_name.readlines()[err.lineno - 1], 130
)
return error
if __name__ == "__main__":
main("x.py")