some tweaks for yaml config files

workspace
Brendan Howell 7 years ago
parent 529191aad6
commit 7b3a153044

@ -1,5 +1,4 @@
# bureau
import configparser
import functools
import inspect
import json
@ -16,6 +15,7 @@ import PIL
import zmq
from escpos import printer
from mako.template import Template
from ruamel.yaml import YAML
def update_commands(cls):
@ -63,8 +63,7 @@ class Bureau(object):
name = "TEST"
prefix = "00"
version = 0
default_config = {"smallprinter": "/dev/usb/lp0"}
default_config = {}
def __init__(self):
""" set up ZeroMQ connections and register commands"""
@ -93,7 +92,6 @@ class Bureau(object):
logging.basicConfig(filename=logfile, level=logging.DEBUG)
self.log = logging.getLogger(self.prefix)
self.config = configparser.ConfigParser()
self.load_config()
# setup a dir to store files and data
@ -117,14 +115,13 @@ class Bureau(object):
"""
load (or reload) config data from file
"""
cfgfile = self.prefix + ".ini"
if os.path.exists(cfgfile):
self.config.read(cfgfile)
else:
self.config["DEFAULT"] = self.default_config
self.config["bureau"] = self.default_config
yaml = YAML()
cfgfile = self.prefix + ".yml"
if not os.path.exists(cfgfile):
with open(cfgfile, "w") as configfile:
self.config.write(configfile)
yaml.dump(self.default_config, configfile)
with open(cfgfile) as cfp:
self.config = yaml.load(cfp)
def send(self, recipient, message, data=None):
"""

@ -51,12 +51,7 @@ class MailRoom(Bureau):
self.host = self.config["user"]["host"]
self.spamfolder = self.config["user"]["spamfolder"]
self.trashfolder = self.config["user"]["trashfolder"]
self.imap_ssl = self.config["user"]["ssl"]
if self.imap_ssl.lower() == "true":
self.imap_ssl = True
else:
self.imap_ssl = False
self.imapserv = imapclient.IMAPClient(self.host, use_uid=True, ssl=self.imap_ssl)
self.imapserv.login(self.login, self.password)

Loading…
Cancel
Save