-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargumentparser.py
58 lines (41 loc) · 1.35 KB
/
argumentparser.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
import sys
import globals as G
class ArgumentError(Exception):
pass
class ArgumentHandler:
def __init__(self):
self.argumenttypes = []
def register(self, type):
self.argumenttypes.append(type)
def parseArguments(self):
argumentpointer = 1
while len(sys.argv) - 1 >= argumentpointer:
flag = True
for e in self.argumenttypes:
if flag and e.isArgument(argumentpointer):
e.parseArgument(argumentpointer)
argumentpointer += e.getCommandLenght(argumentpointer)
flag = False
if flag:
raise ArgumentError(
"unknown argument for system at "
+ str(argumentpointer)
+ " in "
+ str(sys.argv)
)
G.argumenthandler = ArgumentHandler()
class ArgumentType:
@staticmethod
def isArgument(argumentindex):
return False
@staticmethod
def getCommandLenght(argumentindex):
return 1
@staticmethod
def parseArgument(argumentindex):
pass
class IgnoreVersionIncompatibles(ArgumentType):
@staticmethod
def isArgument(argumentindex):
return sys.argv[argumentindex] == "--deactivateversionicompatibles"
G.argumenthandler.register(IgnoreVersionIncompatibles)