From f6bff1b998a9959130c2dab99eb8dadf9f72f240 Mon Sep 17 00:00:00 2001 From: giomba Date: Sat, 3 Nov 2018 14:13:18 +0100 Subject: [PATCH] Proper configuration file --- .gitignore | 1 + conf/conf.ini | 11 +++++++++++ main.py | 9 ++++++--- settings.py | 4 ---- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 conf/conf.ini delete mode 100644 settings.py diff --git a/.gitignore b/.gitignore index db237ca..c8e4d0b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ test/ input/ images/ +conf/*custom.ini .directory *.swp *~ diff --git a/conf/conf.ini b/conf/conf.ini new file mode 100644 index 0000000..905fdeb --- /dev/null +++ b/conf/conf.ini @@ -0,0 +1,11 @@ +# TPDF - Tellico Parser anD Finder +# Main configuration file +# +# Do not edit this file directly if you want to keep your git repository clean. +# Copy/Rename it as `conf.custom.ini` and edit it. +# It will override this file's values, and it will not be tracked. +################################################################################ + +[default] +# Path to Tellico .tc database to use +path = /some/path/to/tellico.tc diff --git a/main.py b/main.py index 65e70dc..64c09b8 100755 --- a/main.py +++ b/main.py @@ -25,10 +25,10 @@ import zipfile import shutil as sh import os import time +import configparser # Our custom library (again no pun intended) import tcparser -import settings # Start CGI handling for webserver cgitb.enable() @@ -49,18 +49,21 @@ print() ### End of HTTP headers: it is now safe to output things ########################################################## +# Read configuration files (latest files in list override previous settings) +conf = configparser.ConfigParser() +conf.read(['conf/conf.ini', 'conf/conf.custom.ini']) luh = open('./output/lastupdate.txt', 'r') lu = int(float(luh.read())) luh.close() -mtime = os.path.getmtime(settings.path) +mtime = os.path.getmtime(conf['default']['path']) outdir = './output' if int(lu) < int(mtime): # Unzip Tellico .tc database - zipHandler = zipfile.ZipFile(settings.path, 'r') + zipHandler = zipfile.ZipFile(conf['default']['path'], 'r') zipHandler.extractall(outdir) zipHandler.close() luh = open('./output/lastupdate.txt', 'w') diff --git a/settings.py b/settings.py deleted file mode 100644 index b07299d..0000000 --- a/settings.py +++ /dev/null @@ -1,4 +0,0 @@ -# TPDF - Tellico Parser anD Finder -- MAIN CONFIGURATION FILE - -# Path to Tellico .tc database to use -path = 'input/tellico.tc'