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
f7b9bdd8
Commit
f7b9bdd8
authored
Apr 04, 2019
by
dorp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
smaller refactoring
parent
c34caf96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
14 deletions
+24
-14
code_generation.py
src/latex_code_generation/code_generation.py
+19
-12
pdf_generator.py
src/pdf_generator.py
+3
-0
test_code_generation.py
src/test/unit/test_code_generation.py
+2
-2
No files found.
src/latex_code_generation/code_generation.py
View file @
f7b9bdd8
...
...
@@ -44,10 +44,16 @@ def _setup_jinja_filters(environment):
def
generate_meta_data_code
(
environment
,
meta_data
):
template
=
environment
.
get_template
(
'
{}.tex'
.
format
(
'meta_data'
)
)
template
=
environment
.
get_template
(
'
meta_data.tex'
)
return
template
.
render
(
meta_data
=
meta_data
)
def
generate_main_code
(
firmware_analyses
,
firmware_meta_data
,
jinja_environment
):
template
=
jinja_environment
.
get_template
(
'main.tex'
)
return
template
.
render
(
analysis
=
firmware_analyses
,
meta_data
=
firmware_meta_data
)
def
generate_analysis_codes
(
environment
,
analysis
):
return
[(
'{}.tex'
.
format
(
analysis_plugin
),
_render_analysis_result
(
analysis
[
analysis_plugin
],
environment
,
analysis_plugin
))
for
analysis_plugin
in
analysis
]
...
...
@@ -77,7 +83,14 @@ def _copy_fact_image(target):
shutil
.
copy
(
Path
(
__file__
)
.
parent
.
parent
/
'templates'
/
'fact_logo.png'
,
Path
(
target
)
/
'fact_logo.png'
)
def
main
(
firmware_uid
=
"bab8d95fc42176abc9126393b6035e4012ebccc82c91e521b91d3bcba4832756_3801088"
):
def
execute_pdflatex
(
tmp_dir
):
current_dir
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
output
,
return_code
=
execute_shell_command_get_return_code
(
'env buf_size=1000000 pdflatex main.tex'
)
os
.
chdir
(
current_dir
)
def
generate_pdf_report
(
firmware_uid
=
"bab8d95fc42176abc9126393b6035e4012ebccc82c91e521b91d3bcba4832756_3801088"
):
request_url
=
create_request_url
(
firmware_uid
)
firmware_analyses
,
firmware_meta_data
=
request_firmware_data
(
request_url
)
...
...
@@ -86,21 +99,15 @@ def main(firmware_uid="bab8d95fc42176abc9126393b6035e4012ebccc82c91e521b91d3bcba
with
TemporaryDirectory
()
as
tmp_dir
:
Path
(
tmp_dir
,
'meta.tex'
)
.
write_text
(
generate_meta_data_code
(
environment
=
jinja_environment
,
meta_data
=
firmware_meta_data
))
for
filename
,
result_code
in
generate_analysis_codes
(
environment
=
jinja_environment
,
analysis
=
firmware_analyses
):
Path
(
tmp_dir
,
filename
)
.
write_text
(
result_code
)
# main_template_code = Path(Path(__file__).parent.parent, 'templates', 'default', 'main.tex').read_text()
template
=
jinja_environment
.
get_template
(
'main.tex'
)
main_code
=
template
.
render
(
analysis
=
firmware_analyses
,
meta_data
=
firmware_meta_data
)
Path
(
tmp_dir
,
'main.tex'
)
.
write_text
(
main_code
)
pdf_filename
=
create_report_filename
(
firmware_meta_data
)
Path
(
tmp_dir
,
'main.tex'
)
.
write_text
(
generate_main_code
(
firmware_analyses
,
firmware_meta_data
,
jinja_environment
))
_copy_fact_image
(
tmp_dir
)
current_dir
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
execute_pdflatex
(
tmp_dir
)
output
,
return_code
=
execute_shell_command_get_return_code
(
'env buf_size=1000000 pdflatex main.tex'
)
os
.
chdir
(
current_dir
)
pdf_filename
=
create_report_filename
(
firmware_meta_data
)
shutil
.
move
(
Path
(
tmp_dir
,
'main.pdf'
),
Path
(
'.'
,
pdf_filename
))
src/pdf_generator.py
View file @
f7b9bdd8
...
...
@@ -18,6 +18,8 @@ import logging
import
os
import
sys
from
latex_code_generation.code_generation
import
generate_pdf_report
PROGRAM_NAME
=
'FACT PDF Report Generator'
PROGRAM_VERSION
=
'0.1'
...
...
@@ -76,5 +78,6 @@ if __name__ == '__main__':
logging
.
info
(
args
.
config_file
)
# insert your program here
generate_pdf_report
(
args
.
UID
)
sys
.
exit
()
src/test/unit/test_code_generation.py
View file @
f7b9bdd8
from
tempfile
import
TemporaryDirectory
from
pathlib
import
Path
from
latex_code_generation.code_generation
import
_set_jinja_env
,
_render_analysis_result
,
_create_tex_files
,
main
from
latex_code_generation.code_generation
import
_set_jinja_env
,
_render_analysis_result
,
_create_tex_files
,
generate_pdf_report
def
test_render_template
():
...
...
@@ -21,5 +21,5 @@ def test_create_tex_files():
def
test_main
():
main
(
firmware_uid
=
'b79ea608e2f0390744642bad472f8d9fd7e4713791857da5d5fcabf70a009e50_29626948'
)
generate_pdf_report
(
firmware_uid
=
'b79ea608e2f0390744642bad472f8d9fd7e4713791857da5d5fcabf70a009e50_29626948'
)
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