Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fact_pdf_report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
fact_pdf_report
Commits
908d4702
Commit
908d4702
authored
Jul 17, 2019
by
dorp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed meta template and added static variables
parent
e280210d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
19 deletions
+28
-19
generator.py
pdf_generator/generator.py
+11
-7
meta.tex
pdf_generator/templates/default/meta.tex
+0
-0
meta.tex
pdf_generator/templates/test/meta.tex
+2
-0
meta_data.tex
pdf_generator/templates/test/meta_data.tex
+0
-2
template_engine.py
pdf_generator/tex_generation/template_engine.py
+7
-3
test_generator.py
test/unit/test_generator.py
+8
-7
No files found.
pdf_generator/generator.py
View file @
908d4702
...
@@ -3,23 +3,27 @@ import shutil
...
@@ -3,23 +3,27 @@ import shutil
from
pathlib
import
Path
from
pathlib
import
Path
from
common_helper_process
import
execute_shell_command
from
common_helper_process
import
execute_shell_command
from
pdf_generator.tex_generation.template_engine
import
TemplateEngine
from
pdf_generator.tex_generation.template_engine
import
(
LOGO_FILE
,
MAIN_TEMPLATE
,
META_TEMPLATE
,
PLUGIN_TEMPLATE_BLUEPRINT
,
TemplateEngine
)
PDF_NAME
=
Path
(
MAIN_TEMPLATE
)
.
with_suffix
(
'.pdf'
)
.
name
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
(
'env buf_size=1000000 pdflatex
main.tex'
)
execute_shell_command
(
'env buf_size=1000000 pdflatex
{}'
.
format
(
MAIN_TEMPLATE
)
)
os
.
chdir
(
current_dir
)
os
.
chdir
(
current_dir
)
def
copy_fact_image
(
target
):
def
copy_fact_image
(
target
):
shutil
.
copy
(
str
(
Path
(
__file__
)
.
parent
/
'templates'
/
'fact_logo.png'
),
str
(
Path
(
target
)
/
'fact_logo.png'
))
shutil
.
copy
(
str
(
Path
(
__file__
)
.
parent
/
'templates'
/
LOGO_FILE
),
str
(
Path
(
target
)
/
LOGO_FILE
))
def
render_analysis_templates
(
engine
,
analysis
):
def
render_analysis_templates
(
engine
,
analysis
):
return
[
return
[
(
'{}.tex'
.
format
(
analysis_plugin
),
engine
.
render_analysis_template
(
analysis_plugin
,
analysis
[
analysis_plugin
]))
for
analysis_plugin
in
analysis
(
PLUGIN_TEMPLATE_BLUEPRINT
.
format
(
analysis_plugin
),
engine
.
render_analysis_template
(
analysis_plugin
,
analysis
[
analysis_plugin
]))
for
analysis_plugin
in
analysis
]
]
...
@@ -33,15 +37,15 @@ def compile_pdf(meta_data, tmp_dir):
...
@@ -33,15 +37,15 @@ 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
)
target_path
=
Path
(
tmp_dir
,
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
))
shutil
.
move
(
str
(
Path
(
tmp_dir
,
PDF_NAME
)),
str
(
target_path
))
return
target_path
return
target_path
def
create_templates
(
analysis
,
meta_data
,
tmp_dir
):
def
create_templates
(
analysis
,
meta_data
,
tmp_dir
):
engine
=
TemplateEngine
(
tmp_dir
=
tmp_dir
)
engine
=
TemplateEngine
(
tmp_dir
=
tmp_dir
)
Path
(
tmp_dir
,
'main.tex'
)
.
write_text
(
engine
.
render_main_template
(
analysis
=
analysis
,
meta_data
=
meta_data
))
Path
(
tmp_dir
,
MAIN_TEMPLATE
)
.
write_text
(
engine
.
render_main_template
(
analysis
=
analysis
,
meta_data
=
meta_data
))
Path
(
tmp_dir
,
'meta.tex'
)
.
write_text
(
engine
.
render_meta_template
(
meta_data
))
Path
(
tmp_dir
,
META_TEMPLATE
)
.
write_text
(
engine
.
render_meta_template
(
meta_data
))
for
filename
,
rendered_template
in
render_analysis_templates
(
engine
=
engine
,
analysis
=
analysis
):
for
filename
,
rendered_template
in
render_analysis_templates
(
engine
=
engine
,
analysis
=
analysis
):
Path
(
tmp_dir
,
filename
)
.
write_text
(
rendered_template
)
Path
(
tmp_dir
,
filename
)
.
write_text
(
rendered_template
)
pdf_generator/templates/default/meta
_data
.tex
→
pdf_generator/templates/default/meta.tex
View file @
908d4702
File moved
pdf_generator/templates/test/meta.tex
0 → 120000
View file @
908d4702
render
_
test.tex
\ No newline at end of file
pdf_generator/templates/test/meta_data.tex
deleted
120000 → 0
View file @
e280210d
render
_
test.tex
\ No newline at end of file
pdf_generator/tex_generation/template_engine.py
View file @
908d4702
...
@@ -9,6 +9,10 @@ import jinja2
...
@@ -9,6 +9,10 @@ import jinja2
from
common_helper_files
import
human_readable_file_size
from
common_helper_files
import
human_readable_file_size
GENERIC_TEMPLATE
=
'generic.tex'
GENERIC_TEMPLATE
=
'generic.tex'
MAIN_TEMPLATE
=
'main.tex'
META_TEMPLATE
=
'meta.tex'
PLUGIN_TEMPLATE_BLUEPRINT
=
'{}.tex'
LOGO_FILE
=
'fact_logo.png'
def
render_number_as_size
(
number
,
verbose
=
True
):
def
render_number_as_size
(
number
,
verbose
=
True
):
...
@@ -140,16 +144,16 @@ class TemplateEngine:
...
@@ -140,16 +144,16 @@ class TemplateEngine:
self
.
_tmp_dir
=
tmp_dir
self
.
_tmp_dir
=
tmp_dir
def
render_main_template
(
self
,
analysis
,
meta_data
):
def
render_main_template
(
self
,
analysis
,
meta_data
):
template
=
self
.
_environment
.
get_template
(
'main.tex'
)
template
=
self
.
_environment
.
get_template
(
MAIN_TEMPLATE
)
return
template
.
render
(
analysis
=
analysis
,
meta_data
=
meta_data
)
return
template
.
render
(
analysis
=
analysis
,
meta_data
=
meta_data
)
def
render_meta_template
(
self
,
meta_data
):
def
render_meta_template
(
self
,
meta_data
):
template
=
self
.
_environment
.
get_template
(
'meta_data.tex'
)
template
=
self
.
_environment
.
get_template
(
META_TEMPLATE
)
return
template
.
render
(
meta_data
=
meta_data
)
return
template
.
render
(
meta_data
=
meta_data
)
def
render_analysis_template
(
self
,
plugin
,
analysis
):
def
render_analysis_template
(
self
,
plugin
,
analysis
):
try
:
try
:
template
=
self
.
_environment
.
get_template
(
'{}.tex'
.
format
(
plugin
))
template
=
self
.
_environment
.
get_template
(
PLUGIN_TEMPLATE_BLUEPRINT
.
format
(
plugin
))
except
jinja2
.
TemplateNotFound
:
except
jinja2
.
TemplateNotFound
:
logging
.
warning
(
'Falling back on generic template for {}'
.
format
(
plugin
))
logging
.
warning
(
'Falling back on generic template for {}'
.
format
(
plugin
))
template
=
self
.
_environment
.
get_template
(
GENERIC_TEMPLATE
)
template
=
self
.
_environment
.
get_template
(
GENERIC_TEMPLATE
)
...
...
test/unit/test_generator.py
View file @
908d4702
...
@@ -3,7 +3,8 @@ from pathlib import Path
...
@@ -3,7 +3,8 @@ from pathlib import Path
import
pytest
import
pytest
from
pdf_generator.generator
import
(
from
pdf_generator.generator
import
(
copy_fact_image
,
create_report_filename
,
create_templates
,
execute_latex
,
render_analysis_templates
LOGO_FILE
,
MAIN_TEMPLATE
,
META_TEMPLATE
,
PLUGIN_TEMPLATE_BLUEPRINT
,
copy_fact_image
,
create_report_filename
,
create_templates
,
execute_latex
,
render_analysis_templates
)
)
...
@@ -38,7 +39,7 @@ def test_execute_latex(monkeypatch, tmpdir):
...
@@ -38,7 +39,7 @@ def test_execute_latex(monkeypatch, tmpdir):
def
test_copy_fact_image
(
tmpdir
):
def
test_copy_fact_image
(
tmpdir
):
copy_fact_image
(
str
(
tmpdir
))
copy_fact_image
(
str
(
tmpdir
))
assert
Path
(
str
(
tmpdir
),
'fact_logo.png'
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
LOGO_FILE
)
.
exists
()
@pytest.mark.parametrize
(
'device_name, pdf_name'
,
[
@pytest.mark.parametrize
(
'device_name, pdf_name'
,
[
...
@@ -56,7 +57,7 @@ def test_create_analysis_templates():
...
@@ -56,7 +57,7 @@ def test_create_analysis_templates():
assert
len
(
templates
)
==
1
assert
len
(
templates
)
==
1
filename
,
result_code
=
templates
[
0
]
filename
,
result_code
=
templates
[
0
]
assert
filename
==
'test.tex'
assert
filename
==
PLUGIN_TEMPLATE_BLUEPRINT
.
format
(
'test'
)
assert
result_code
==
'{"result": "data"}'
assert
result_code
==
'{"result": "data"}'
...
@@ -64,8 +65,8 @@ def test_create_templates(monkeypatch, tmpdir):
...
@@ -64,8 +65,8 @@ def test_create_templates(monkeypatch, tmpdir):
monkeypatch
.
setattr
(
'pdf_generator.generator.TemplateEngine'
,
MockEngine
)
monkeypatch
.
setattr
(
'pdf_generator.generator.TemplateEngine'
,
MockEngine
)
create_templates
(
analysis
=
{
'test'
:
{
'result'
:
'data'
}},
meta_data
=
{},
tmp_dir
=
str
(
tmpdir
))
create_templates
(
analysis
=
{
'test'
:
{
'result'
:
'data'
}},
meta_data
=
{},
tmp_dir
=
str
(
tmpdir
))
assert
Path
(
str
(
tmpdir
),
'main.tex'
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
MAIN_TEMPLATE
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
'meta.tex'
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
META_TEMPLATE
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
'test.tex'
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
PLUGIN_TEMPLATE_BLUEPRINT
.
format
(
'test'
)
)
.
exists
()
assert
Path
(
str
(
tmpdir
),
'test.tex'
)
.
read_text
()
==
'{"result": "data"}'
assert
Path
(
str
(
tmpdir
),
PLUGIN_TEMPLATE_BLUEPRINT
.
format
(
'test'
)
)
.
read_text
()
==
'{"result": "data"}'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment