Added counter to gps_tool

This commit is contained in:
2021-11-19 08:49:59 -05:00
parent 5d1e98eee6
commit 54eeb99d42
4 changed files with 51 additions and 11 deletions

View File

@ -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