|
5 | 5 | from glob import glob
|
6 | 6 | from PIL import Image
|
7 | 7 | from subprocess import run
|
| 8 | +from re import compile |
8 | 9 |
|
9 | 10 | # defaults
|
10 | 11 | BASE_PATH_TO_IMPORT = "/flask-backend/data/import/"
|
@@ -626,24 +627,37 @@ def moveFileToStorage(
|
626 | 627 | if type == "milts":
|
627 | 628 | try:
|
628 | 629 | with open(newPath, "r") as plotFile:
|
629 |
| - lines = plotFile.readlines() |
| 630 | + plot_data = "".join(plotFile.readlines()).replace("\n", "") |
| 631 | + plot_data = plot_data.replace('"title":"taxonomic assignment"', f'"title":"{name}"') |
630 | 632 | plotFile.close()
|
631 | 633 |
|
632 |
| - for index, line in enumerate(lines): |
633 |
| - if "3D_plot_files" in line: |
634 |
| - lines[index] = line.replace( |
635 |
| - "3D_plot_files", |
636 |
| - "../../../../../dependencies/3D_plot_files", |
637 |
| - ) |
638 |
| - elif '"title":"taxonomic assignment",' in line: |
639 |
| - lines[index] = line.replace( |
640 |
| - '"title":"taxonomic assignment",', f'"title":"{name}",' |
641 |
| - ) |
| 634 | + with open( |
| 635 | + "src/Tools/templates/milts_head_template.html", "r" |
| 636 | + ) as milts_template_file: |
| 637 | + milts_template = milts_template_file.readlines() |
| 638 | + milts_template_file.close() |
| 639 | + |
| 640 | + body_regex = compile(r"<body>.*</body>") |
| 641 | + body_match = body_regex.findall(plot_data) |
| 642 | + if len(body_match) != 1: |
| 643 | + return 0, { |
| 644 | + "label": "Error", |
| 645 | + "message": "Error using template html!", |
| 646 | + "type": "error", |
| 647 | + } |
| 648 | + |
| 649 | + for i in range(len(milts_template)-1, len(milts_template)-5, -1): |
| 650 | + if ("<body>REPLACE_BODY</body>" in milts_template[i]): |
| 651 | + milts_template[i] = milts_template[i].replace("<body>REPLACE_BODY</body>", body_match[0]) |
| 652 | + elif ("<title>REPLACE_TITLE</title>" in milts_template[i]): |
| 653 | + milts_template[i] = milts_template[i].replace("REPLACE_TITLE", name) |
| 654 | + break |
642 | 655 |
|
643 | 656 | with open(newPath, "w") as plotFile:
|
644 |
| - lines = plotFile.writelines(lines) |
| 657 | + plotFile.writelines(milts_template) |
645 | 658 | plotFile.close()
|
646 |
| - except: |
| 659 | + except Exception as err: |
| 660 | + print(str(err)) |
647 | 661 | self.deleteDirectories(fullPathToAnalysis)
|
648 | 662 | return 0, STORAGEERROR
|
649 | 663 |
|
|
0 commit comments