some tweaks for yaml config files

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

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

@ -51,12 +51,7 @@ class MailRoom(Bureau):
self.host = self.config["user"]["host"] self.host = self.config["user"]["host"]
self.spamfolder = self.config["user"]["spamfolder"] self.spamfolder = self.config["user"]["spamfolder"]
self.trashfolder = self.config["user"]["trashfolder"] self.trashfolder = self.config["user"]["trashfolder"]
self.imap_ssl = self.config["user"]["ssl"] 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 = imapclient.IMAPClient(self.host, use_uid=True, ssl=self.imap_ssl)
self.imapserv.login(self.login, self.password) self.imapserv.login(self.login, self.password)

Loading…
Cancel
Save