/usr/lib/python2.7/dist-packages/relatorio/templates/pdf.py is in python-relatorio 0.6.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | ###############################################################################
#
# Copyright (c) 2014 Cedric Krier.
# Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights
# Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
__metaclass__ = type
import os
import shutil
import tempfile
import subprocess
from io import BytesIO
import genshi
import genshi.output
from genshi.template import NewTextTemplate
from relatorio.templates.base import RelatorioStream
from relatorio.reporting import MIMETemplateLoader
TEXEXEC = 'texexec'
_encode = genshi.output.encode
class Template(NewTextTemplate):
def generate(self, *args, **kwargs):
generated = super(Template, self).generate(*args, **kwargs)
return RelatorioStream(generated, PDFSerializer())
class PDFSerializer:
def __init__(self):
self.working_dir = tempfile.mkdtemp(prefix='relatorio')
self.tex_file = os.path.join(self.working_dir, 'report.tex')
self.pdf_file = os.path.join(self.working_dir, 'report.pdf')
self.text_serializer = genshi.output.TextSerializer()
def __call__(self, stream):
tex_file = open(self.tex_file, 'w')
tex_file.write(_encode(self.text_serializer(stream)))
tex_file.close()
subprocess.check_call([TEXEXEC, '--purge', 'report.tex'],
cwd=self.working_dir)
pdf = BytesIO()
pdf.write(open(self.pdf_file, 'r').read())
shutil.rmtree(self.working_dir, ignore_errors=True)
return pdf
MIMETemplateLoader.add_factory('pdf', Template)
|