From c9b82f2e36b602fd3982aebdd8900b3dde7b9a4a Mon Sep 17 00:00:00 2001 From: Ken Sanislo Date: Mon, 31 Dec 2018 15:41:28 -0800 Subject: [PATCH] append or create --- Dockerfile | 1 + tcc-exporter | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7d32322..9f2d158 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM python:3.7 EXPOSE 9528 RUN groupadd --gid 5001 tcc-exporter && useradd --no-log-init --no-create-home --home-dir /usr/src/tcc-exporter --uid 5001 --gid 5001 --shell /bin/false tcc-exporter RUN mkdir -p /usr/src/tcc-exporter && chown tcc-exporter:tcc-exporter /usr/src/tcc-exporter +RUN mkdir -p /var/log/tcc-exporter && chown tcc-exporter:tcc-exporter /var/log/tcc-exporter WORKDIR /usr/src/tcc-exporter RUN pip install dumb-init RUN pip install pyyaml diff --git a/tcc-exporter b/tcc-exporter index 0d39e7c..e203786 100755 --- a/tcc-exporter +++ b/tcc-exporter @@ -17,7 +17,7 @@ from http.cookiejar import LWPCookieJar from http.server import HTTPServer, BaseHTTPRequestHandler from urllib.error import HTTPError, URLError -VERSION = '1.1.0' +VERSION = '1.1.1' CONFIG_FILE = os.environ.get('TCC_CONFIG_FILE', 'persistent/config.yml') PREFIX = 'https://mytotalconnectcomfort.com/' @@ -225,7 +225,10 @@ def log(level, *message): if (level <= debug_level): print("[{0}] {1}".format(LOGLEVELS[level], " ".join(message))) if config['log.file']: - lfh = open(config['log.file'], 'a') + try: + lfh = open(config['log.file'], 'a') + except FileNotFoundError: + lfh = open(config['log.file'], 'w') try: timestring = time.strftime('%D %T') lfh.write("{0} [{1}] {2}\n".format(timestring, LOGLEVELS[level], " ".join(message)))