Global customized output directory

This commit is contained in:
giomba 2018-11-03 16:27:40 +01:00
parent f6bff1b998
commit 9c7ec28729
4 changed files with 32 additions and 15 deletions

View File

@ -7,5 +7,10 @@
################################################################################ ################################################################################
[default] [default]
# Path to Tellico .tc database to use
path = /some/path/to/tellico.tc # Path to Tellico .tc database to use
path = /path/to/some/tellico.tc
# Path to output directory for images and temporary data
# Must be accessible by webserver
outdir = output

5
glob.py Normal file
View File

@ -0,0 +1,5 @@
import configparser
# Read configuration files (latest files in list override previous settings)
conf = configparser.ConfigParser()
conf.read(['conf/conf.ini', 'conf/conf.custom.ini'])

29
main.py
View File

@ -25,11 +25,12 @@ import zipfile
import shutil as sh import shutil as sh
import os import os
import time import time
import configparser
# Our custom library (again no pun intended) # Our custom library (again no pun intended)
import tcparser import tcparser
import glob
# Start CGI handling for webserver # Start CGI handling for webserver
cgitb.enable() cgitb.enable()
inputvars = cgi.FieldStorage() inputvars = cgi.FieldStorage()
@ -49,29 +50,33 @@ print()
### End of HTTP headers: it is now safe to output things ### 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') # Create output directory and temporary files if they do not exist
if not os.path.exists(glob.conf['default']['outdir']):
os.mkdir(glob.conf['default']['outdir'])
if not os.path.exists(glob.conf['default']['outdir'] + '/lastupdate.txt'):
luh = open(glob.conf['default']['outdir'] + '/lastupdate.txt', 'w')
luh.write('0')
luh.close()
# Retrieve last database update timestamp
luh = open(glob.conf['default']['outdir'] + '/lastupdate.txt', 'r')
lu = int(float(luh.read())) lu = int(float(luh.read()))
luh.close() luh.close()
mtime = os.path.getmtime(conf['default']['path']) mtime = os.path.getmtime(glob.conf['default']['path'])
outdir = './output'
if int(lu) < int(mtime): if int(lu) < int(mtime):
# Unzip Tellico .tc database # Unzip Tellico .tc database
zipHandler = zipfile.ZipFile(conf['default']['path'], 'r') zipHandler = zipfile.ZipFile(glob.conf['default']['path'], 'r')
zipHandler.extractall(outdir) zipHandler.extractall(glob.conf['default']['outdir'])
zipHandler.close() zipHandler.close()
luh = open('./output/lastupdate.txt', 'w') luh = open(glob.conf['default']['outdir'] + '/lastupdate.txt', 'w')
luh.write(str(time.time())) luh.write(str(time.time()))
luh.close() luh.close()
# Get a Python-friendly library struct from XML file # Get a Python-friendly library struct from XML file
library = tcparser.getLibrary(outdir + "/tellico.xml", lu) library = tcparser.getLibrary(glob.conf['default']['outdir'] + "/tellico.xml", lu)
### Get filters to search for books ### ### Get filters to search for books ###
try: try:

View File

@ -3,6 +3,8 @@ import json
import datetime import datetime
import sys import sys
import glob
# Parse Tellico's XML and get a library struct, # Parse Tellico's XML and get a library struct,
# a stripped version of our library in a Python-friendly format # a stripped version of our library in a Python-friendly format
def getLibrary(path, lastUpdate): def getLibrary(path, lastUpdate):
@ -112,7 +114,7 @@ def getHTML(library):
cover = ET.Element('td') cover = ET.Element('td')
if i.get('cover'): if i.get('cover'):
img = ET.Element('img', attrib={'alt': 'Book "' + i.get('title') + '" cover', 'src': 'output/images/' + i.get('cover')}) img = ET.Element('img', attrib={'alt': 'Book "' + i.get('title') + '" cover', 'src': glob.conf['default']['outdir'] + '/images/' + i.get('cover')})
cover.append(img) cover.append(img)
tr.append(cover) tr.append(cover)