-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigReader.py
111 lines (94 loc) · 3.99 KB
/
configReader.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright (C) 2105 wysiwyng
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, ConfigParser
class ConfigReader(object):
def __init__(self, path, debug = None):
self.debug = debug
self.debugMsg("opening config file and creating configParser")
self.parser = ConfigParser.ConfigParser()
cFile = open(os.path.join(path, "mai-bot.cfg"))
self.debugMsg("config file open, checking config file")
self.parser.readfp(cFile)
if not self.parser.has_section("mai-bot-cfg"):
raise ValueError("invalid config file")
self.debugMsg("config file is valid, ready to read values")
cFile.close()
def getKey(self, key):
return self.parser.get("mai-bot-cfg", key)
def getMaxSpeed(self):
if self.parser.has_option("mai-bot-cfg", "max-speed"):
return self.parser.getint("mai-bot-cfg", "max-speed")
else:
return 255
def getDistModifier(self):
if self.parser.has_option("mai-bot-cfg", "dist-modifier"):
return self.parser.getint("mai-bot-cfg", "dist-modifier")
else:
return 10
def getDistModifierBegin(self):
if self.parser.has_option("mai-bot-cfg", "dist-mod-begin"):
return self.parser.getint("mai-bot-cfg", "dist-mod-begin")
else:
return 80
def getCamResX(self):
if self.parser.has_option("mai-bot-cfg", "cam-res-x"):
return self.parser.getint("mai-bot-cfg", "cam-res-x")
else:
return 800
def getCamResY(self):
if self.parser.has_option("mai-bot-cfg", "cam-res-y"):
return self.parser.getint("mai-bot-cfg", "cam-res-y")
else:
return 600
def getMaxTries(self):
if self.parser.has_option("mai-bot-cfg", "max-tries"):
return self.parser.getint("mai-bot-cfg", "max-tries")
else:
return 2
def getDirection(self):
if self.parser.has_option("mai-bot-cfg", "direction"):
return self.parser.get("mai-bot-cfg", "direction")
else:
return "left"
def getCommands(self):
if self.parser.has_option("mai-bot-cfg", "commands"):
return str(self.parser.get("mai-bot-cfg", "commands")).split(",")
else:
return ["nearest", "middle-left", "far-left"]
def getTokenOrder(self):
if self.parser.has_option("mai-bot-cfg", "token-order"):
return str(self.parser.get("mai-bot-cfg", "token-order")).split(",")
else:
return ["0","1","2","3","4","5"]
def getDebug(self):
if self.parser.has_option("mai-bot-cfg", "debug"):
return self.parser.getboolean("mai-bot-cfg", "debug")
else:
return False
#def getStart(self):
# if self.parser.has_option("mai-bot-cfg", "start"):
# return self.parser.get("mai-bot-cfg", "start")
# else:
# return "nearest"
#def getMaxHeight(self):
# if self.parser.has_option("mai-bot-cfg", "max-height"):
# return self.parser.getint("mai-bot-cfg", "max-height")
# else:
# return 4
def debugMsg(self, message):
if self.debug != None:
self.debug.printMsg(message, self)
def __str__(self):
return "ConfigReader"