server: use parchemin mode for documents with type == PARCH (#3932)
This commit is contained in:
parent
376df1781c
commit
a29e5025ae
|
@ -27,6 +27,34 @@ import time
|
||||||
import syslog
|
import syslog
|
||||||
import socket
|
import socket
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
try:
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
except ImportError:
|
||||||
|
import elementtree.ElementTree as ET
|
||||||
|
|
||||||
|
def get_legi_metadata(legi_filename):
|
||||||
|
try:
|
||||||
|
z = zipfile.ZipFile(legi_filename)
|
||||||
|
except zipfile.BadZipfile:
|
||||||
|
content = file(legi_filename).read()
|
||||||
|
else:
|
||||||
|
content_zfile = None
|
||||||
|
for zfile in z.namelist():
|
||||||
|
if zfile == 'contents.xml':
|
||||||
|
content_zfile = zfile
|
||||||
|
break
|
||||||
|
if content_zfile is None:
|
||||||
|
return None
|
||||||
|
content = z.read(content_zfile)
|
||||||
|
|
||||||
|
content_tree = ET.ElementTree(ET.fromstring(content))
|
||||||
|
metadata = {}
|
||||||
|
for property in content_tree.findall('metadata/property'):
|
||||||
|
metadata[property.attrib.get('name')] = property.text
|
||||||
|
return metadata
|
||||||
|
|
||||||
|
|
||||||
class PreviewHandler(SCGIHandler):
|
class PreviewHandler(SCGIHandler):
|
||||||
debug = False
|
debug = False
|
||||||
|
@ -114,7 +142,12 @@ class PreviewHandler(SCGIHandler):
|
||||||
output.write(legi_file)
|
output.write(legi_file)
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.system('python ../legi2pdf/script/db2pdf.py --debug --latex --input=%s' % legi_filename):
|
args = ['--debug', '--latex', '--input=%s' % legi_filename]
|
||||||
|
metadata = get_legi_metadata(legi_filename)
|
||||||
|
if metadata and metadata.get('typedocid') == 'PARCH':
|
||||||
|
args.append('--parchemin')
|
||||||
|
cmd = ['python', '../legi2pdf/script/db2pdf.py'] + args
|
||||||
|
if os.system(' '.join(cmd)):
|
||||||
if self.daemon:
|
if self.daemon:
|
||||||
syslog.syslog(syslog.LOG_ERR, 'error in legi2pdf')
|
syslog.syslog(syslog.LOG_ERR, 'error in legi2pdf')
|
||||||
else:
|
else:
|
||||||
|
|
Reference in New Issue