From 7b3a153044bb1c4e7e0d4ab8b5aa5ee384ce6866 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Fri, 22 Sep 2017 16:03:26 +0200 Subject: [PATCH] some tweaks for yaml config files --- screenless/bureau/bureau.py | 19 ++++++++----------- screenless/bureau/mailroom/mailroom.py | 5 ----- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 4479cb1..29256a9 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -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): """ diff --git a/screenless/bureau/mailroom/mailroom.py b/screenless/bureau/mailroom/mailroom.py index 515129c..2c6c062 100644 --- a/screenless/bureau/mailroom/mailroom.py +++ b/screenless/bureau/mailroom/mailroom.py @@ -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)