forked from UniversalPython/UniversalPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurdu_python.py
More file actions
85 lines (66 loc) · 2.85 KB
/
Copy pathurdu_python.py
File metadata and controls
85 lines (66 loc) · 2.85 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
# ------------------------------------------------------------
# urdu_python.py
#
# Main driver file.
# - Arguments are captured here
# - The parsing mode is called from here with the same args as this file
# ------------------------------------------------------------
import importlib
import inspect
import sys
import os
SCRIPTDIR = os.path.dirname(__file__)
def run_module(
mode,
code,
args={
'translate': False,
'dictionary': os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'),
'reverse': False,
'keep': False,
'keep_only': False,
'return': True,
},
):
mod = importlib.import_module(".modes."+mode, package='urdupython')
return mod.run(args, code)
def main():
import argparse
# construct the argument parser and parse the argument
ap = argparse.ArgumentParser()
ap.add_argument('file', metavar='F', type=str, nargs='+',
help='File to compile.')
ap.add_argument("-t", "--translate",
action='store_true',
default=False, required = False,
help = "Translate variables and functions to English, using the unicode.")
ap.add_argument("-m", "--mode",
default="lex", required = False,
help = "The mode to use to translate the code.")
ap.add_argument("-d", "--dictionary",
default=os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'), required = False,
help = "The dictionary to use to translate the code.")
ap.add_argument("-r", "--reverse",
action='store_true',
default=False, required = False,
help = "Translate English code to the language of your choice.")
ap.add_argument("-re", "--return",
action='store_false',
default=False, required = False,
help = "Return the code instead of executing (used in module mode).")
group = ap.add_mutually_exclusive_group(required=False)
group.add_argument("-k", "--keep",
action='store_true',
default=False, required = False,
help = "Save the compiled file to the specified location.")
group.add_argument("-ko", "--keep-only",
action='store_true',
default=False, required = False,
help = "Save the compiled file to the specified location, but don't run the file.")
args = vars(ap.parse_args())
code_pyfile = open(args["file"][0])
code = code_pyfile.read()
mode = args["mode"]
run_module (mode, code, args)
if __name__ == "__main__":
sys.exit(main())