Added counter to gps_tool
This commit is contained in:
@ -16,19 +16,20 @@ class ConfigurationFile():
|
||||
(base, ext) = os.path.splitext(os.path.basename(app_path))
|
||||
self.app_name = base
|
||||
self.cfg_file = self.app_name + ".yaml"
|
||||
self.use_path = ""
|
||||
self.use_path = self.cfg_file
|
||||
self.config = []
|
||||
self.paths = []
|
||||
self.paths.append(".") # local first
|
||||
# grab from env
|
||||
self.paths.append(self.cfg_path) # program location
|
||||
|
||||
def find_config(self):
|
||||
# local first
|
||||
if os.path.isfile(self.cfg_file):
|
||||
self.use_path = self.cfg_file
|
||||
return 1
|
||||
elif os.path.isfile(self.cfg_path + "/" + self.cfg_file):
|
||||
self.use_path = self.cfg_path + "/" + self.cfg_file
|
||||
return 1
|
||||
else:
|
||||
print("Config file not found:", self.cfg_file)
|
||||
for path in self.paths:
|
||||
cfg = path + "/" + self.cfg_file
|
||||
if os.path.isfile(cfg):
|
||||
self.use_path = cfg
|
||||
return 1
|
||||
print("Config file not found:", self.cfg_file)
|
||||
return 0
|
||||
|
||||
def read_config(self):
|
||||
@ -42,7 +43,15 @@ class ConfigurationFile():
|
||||
return self.config
|
||||
|
||||
def write_config(self, config):
|
||||
self.config = config
|
||||
with open(self.use_path, 'w') as f:
|
||||
f.write(yaml.dump(config))
|
||||
f.close()
|
||||
|
||||
|
||||
def get_config(self, name):
|
||||
if name in self.config:
|
||||
return self.config[name]
|
||||
return ""
|
||||
|
||||
def set_config(self, name, val):
|
||||
self.config[name] = val
|
||||
|
||||
Reference in New Issue
Block a user