-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter.py
56 lines (42 loc) · 1.13 KB
/
interpreter.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
import os, json, sys, subprocess
if len(sys.argv)==2:
pass
else: os._exit(0)
file_name = sys.argv[1]
try: file = open(file_name, "r", encoding="utf-8")
except FileNotFoundError:
print("File not found.")
os._exit(0)
print("")
venv = {}
for line in file:
if line=="#!/bin/bash":
os.system("@echo off")
if "#" in line:
os.system(line.split("#")[0])
if "export" in line:
exports = line.split("export")[1].split("=")
venv[exports[0]] = exports[1]
os.system(
f"set {exports[0]}={exports[1]}"
)
elif "$" in line:
imports = line.split("$")[1].split("\n")
if len(imports) == 1:
execCode = line.split('$')[0] + venv[str(imports[0])]
print(execCode)
os.system(
execCode
)
else:
execCode = line.split('$')[0] + venv[str(imports[0])]
os.system(
execCode
)
os.system("echo %txt%")
elif line[0:1]=="if":
pass # IF-ELSE method not supported
else: os.system(line)
print("")
print("Program exited")
print("")