Added configuration file class
This commit is contained in:
37
classes/utils/configs.py
Normal file
37
classes/utils/configs.py
Normal 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
|
||||
Reference in New Issue
Block a user