-
Notifications
You must be signed in to change notification settings - Fork 0
/
opscript.py
56 lines (41 loc) · 1.1 KB
/
opscript.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
import parser
import os
import time
import sys
def current_milli_time():
return round(time.time() * 1000)
def show_help_page():
print("""
OPScript Help
* python opscript.py run <file>
* python opscript.py build <file>
Arguments:
-h | Shows this help menu
-d | Enables debug mode
""")
exit()
if len(sys.argv) == 1 or "-h" in sys.argv:
show_help_page()
parser.DEBUG = "-d" in sys.argv
if sys.argv[1] == "run":
mode = "run"
elif sys.argv[1] == "build":
mode = "build"
else:
show_help_page()
file = sys.argv[2]
if not os.path.exists(file):
print("The file you specified does not exist.")
exit()
# Read and parse the OPScript file we want to build
with open(file, "r") as f:
script = f.read()
code = parser.parse(script)
# Build the go code into an exe
build_name = f"{current_milli_time()}"
with open(f"{build_name}.go", "w") as f:
f.write(code)
os.system(f"go {mode} {build_name}.go")
os.remove(f"{build_name}.go")
if mode == "build":
print(f"File saved as {build_name}.exe")