Skip to content
Snippets Groups Projects
Commit 967230c8 authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

Use os tools to work with file path

parent 0c897c3b
No related branches found
No related tags found
1 merge request!70Feat: vector graphics in the calibration report
......@@ -62,34 +62,35 @@ def prepare_plots(run_path, threshold=1000000):
Convert svg file to pdf or png to be used for latex
Conversion of svg to vector graphics pdf is performed using svglib3.
This procedure is CPU consuming. In order to speeup process
This procedure is CPU consuming. In order to speed up process
large svg files are converted to png format.
Link in rst files to converted image files are corrected respectively.
The links in the rst files are adapted accordingly to the
converted image files.
:param run_path: Run path of the slurm job
:param threshold: Max svg file size to be converted to pdf
:param threshold: Max svg file size (in bytes) to be converted to pdf
"""
print('Convert svg to pdf and png')
run_path = os.path.abspath(run_path)
files = glob.glob('{}/*_files/*svg'.format(run_path))
for f_path in files:
print(f_path, f_path[len(run_path):])
dir_name, f_name = f_path[len(run_path) + 1:].split('/')
dir_name = os.path.dirname(f_path)
f_name = os.path.basename(f_path)
if (os.stat(f_path)).st_size < threshold:
check_call(["svg2pdf", "{}".format(f_path)], shell=False)
new_f_name = f_name[:-4] + '.pdf'
new_f_name = os.path.splitext(f_name)[0] + '.pdf'
else:
check_call(["convert", "{}".format(f_path),
"{}.png".format(f_path[:-4])], shell=False)
new_f_name = f_name[:-4] + '.png'
new_f_name = os.path.splitext(f_name)[0] + '.png'
print('{} converted to {}'.format(f_name, new_f_name))
check_call(["sed",
"-i",
"s/{}/{}/g".format(f_name, new_f_name),
"{}/{}.rst".format(run_path, dir_name[:-6])],
"{}.rst".format(dir_name[:-6])],
shell=False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment