Added configuration file class

This commit is contained in:
Neal Probert
2021-11-17 12:29:37 -05:00
parent a3bfa9192b
commit 19d85aebfe
2 changed files with 38 additions and 1 deletions

37
classes/utils/configs.py Normal file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 8 10:26:56 2021
@author: neal
"""
import os
import system
import yaml
class ArrowHandle():
def __init__(self, icon):
self.pathfilename = "./" + "config.yaml"
self.config = []
def find_config(self, path=".", file="config.yaml"):
# local first
if path.isfile(file):
self.pathfilename = file
return 1
elif path.isfile(path + "/" + file):
self.pathfilename = path + "/" + file
return 1
else:
print("Config file not found:", file)
return 0
def read_config(self, path=".", file="config.yaml"):
if self.find_config(path, file):
with open(self.pathfilename) as f:
self.config = yaml.load(f, Loader=yaml.FullLoader)
f.close()
else:
self.config= []
return self.config