added calls to odf2legi and legi2pdf

This commit is contained in:
Frédéric Péters 2007-12-02 20:19:40 +01:00
parent 15ebeeea9a
commit 6deaf1004d
2 changed files with 23 additions and 2 deletions

BIN
server/error.pdf Normal file

Binary file not shown.

View File

@ -22,6 +22,7 @@ import os
from optparse import OptionParser
from scgi.scgi_server import SCGIServer, SCGIHandler
import cgi
import random
class PreviewHandler(SCGIHandler):
debug = False
@ -51,9 +52,23 @@ class PreviewHandler(SCGIHandler):
odf_file = input.read(bodysize)
# XXX: add conversion to PDF here
if os.path.exists('../../legi2pdf/script/db2pdf.py'):
odf_filename = '/tmp/tabellio/%s.odt' % random.randint(0, 10000)
legi_filename = odf_filename.replace('.odt', '.legi')
pdf_filename = odf_filename.replace('.odt', '.pdf')
fd = file(odf_filename, 'w')
fd.write(odf_file)
fd.close()
pdf_file = file('unconfigured.pdf').read()
os.system('python ../odf2legi/odf2legi.py %s' % odf_filename)
os.system('python ../../legi2pdf/script/db2pdf.py --input=%s' % legi_filename)
if os.path.exists(pdf_filename):
pdf_file = file(pdf_filename).read()
else:
pdf_file = file('error.pdf').read()
else:
pdf_file = file('unconfigured.pdf').read()
print >> output, 'Content-type: application/pdf'
print >> output, 'Content-length: %s' % len(pdf_file)
print >> output, ''
@ -65,6 +80,12 @@ def main():
parser.add_option('--debug', action = 'store_true', dest = 'debug')
options, args = parser.parse_args()
if not os.path.exists('../../legi2pdf/script/db2pdf.py'):
print >> sys.stderr, 'W: legi2pdf not found'
if not os.path.exists('/tmp/tabellio'):
os.mkdir('/tmp/tabellio')
PreviewHandler.debug = options.debug
SCGIServer(handler_class = PreviewHandler, port = options.port).serve()