Commit 697fc7db by dorp

added docker support and fixed bug in template engine

parent 80a9e922
FROM phusion/baseimage:0.11
WORKDIR /opt/app
COPY . /opt/app
RUN install_clean git python3 python3-pip python3-wheel python3-setuptools texlive-latex-base texlive-latex-extra lmodern
RUN pip3 install -r requirements.txt
RUN apt-get remove -y python3-pip
ENTRYPOINT ["./docker_entry.py"]
#!/usr/bin/env python3
'''
fact_pdf_report
Copyright (C) 2015-2019 Fraunhofer FKIE
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/>.
'''
import json
import shutil
from pathlib import Path
from tempfile import TemporaryDirectory
from pdf_generator.generator import compile_pdf, create_templates
def get_data():
return json.loads(Path('/tmp', 'interface', 'data', 'analysis.json').read_text()), json.loads(Path('/tmp', 'interface', 'data', 'meta.json').read_text())
def move_pdf_report(pdf_path):
shutil.move(str(pdf_path.absolute()), str(Path('/tmp', 'interface', 'pdf', pdf_path.name)))
def main():
analysis, meta_data = get_data()
with TemporaryDirectory() as tmp_dir:
create_templates(analysis, meta_data, tmp_dir)
target_path = compile_pdf(meta_data, tmp_dir)
move_pdf_report(target_path)
return 0
if __name__ == '__main__':
exit(main())
...@@ -4,7 +4,7 @@ import shutil ...@@ -4,7 +4,7 @@ import shutil
from pathlib import Path from pathlib import Path
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from common_helper_process import execute_shell_command_get_return_code from common_helper_process import execute_shell_command
from pdf_generator.pre_processing.rest import create_request_url, request_firmware_data from pdf_generator.pre_processing.rest import create_request_url, request_firmware_data
from pdf_generator.tex_generation.template_engine import Engine from pdf_generator.tex_generation.template_engine import Engine
...@@ -12,7 +12,7 @@ from pdf_generator.tex_generation.template_engine import Engine ...@@ -12,7 +12,7 @@ from pdf_generator.tex_generation.template_engine import Engine
def execute_latex(tmp_dir): def execute_latex(tmp_dir):
current_dir = os.getcwd() current_dir = os.getcwd()
os.chdir(tmp_dir) os.chdir(tmp_dir)
execute_shell_command_get_return_code('env buf_size=1000000 pdflatex main.tex') execute_shell_command('env buf_size=1000000 pdflatex main.tex')
os.chdir(current_dir) os.chdir(current_dir)
...@@ -27,13 +27,17 @@ def generate_analysis_templates(engine, analysis): ...@@ -27,13 +27,17 @@ def generate_analysis_templates(engine, analysis):
def create_report_filename(meta_data): def create_report_filename(meta_data):
return '{}_analysis_report.pdf'.format(meta_data['device_name'].replace(' ', '_').replace('/', '__')) unsafe_name = '{}_analysis_report.pdf'.format(meta_data['device_name'])
safer_name = unsafe_name.replace(' ', '_').replace('/', '__')
return safer_name.encode('latin-1', errors='ignore').decode('latin-1')
def compile_pdf(meta_data, tmp_dir): def compile_pdf(meta_data, tmp_dir):
copy_fact_image(tmp_dir) copy_fact_image(tmp_dir)
execute_latex(tmp_dir) execute_latex(tmp_dir)
shutil.move(str(Path(tmp_dir, 'main.pdf')), str(Path(create_report_filename(meta_data)))) target_path = Path(tmp_dir, create_report_filename(meta_data))
shutil.move(str(Path(tmp_dir, 'main.pdf')), str(target_path))
return target_path
def create_templates(analysis, meta_data, tmp_dir): def create_templates(analysis, meta_data, tmp_dir):
......
...@@ -49,8 +49,8 @@ def filter_latex_special_chars(data): ...@@ -49,8 +49,8 @@ def filter_latex_special_chars(data):
latex_character_escapes['$'] = '\\$' latex_character_escapes['$'] = '\\$'
latex_character_escapes['('] = '$($' latex_character_escapes['('] = '$($'
latex_character_escapes[')'] = '$)$' latex_character_escapes[')'] = '$)$'
latex_character_escapes['['] = '$[$', latex_character_escapes['['] = '$[$'
latex_character_escapes[']'] = '$]$', latex_character_escapes[']'] = '$]$'
latex_character_escapes['#'] = '\\#' latex_character_escapes['#'] = '\\#'
latex_character_escapes['%'] = '\\%' latex_character_escapes['%'] = '\\%'
latex_character_escapes['&'] = '\\&' latex_character_escapes['&'] = '\\&'
......
#! /usr/bin/env python3 #!/usr/bin/env python3
'''
fact_pdf_report
Copyright (C) 2015-2019 Fraunhofer FKIE
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/>.
'''
import argparse import argparse
import logging import logging
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment