Skip to content

Commit 7e3e02b

Browse files
committed
fix html embedding issues with latest changes
1 parent db69de5 commit 7e3e02b

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

explorer/plots/operation.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ def determine_legend(fig, column):
112112
return legend
113113

114114

115+
def append_content(target_tag, source_path, part="body"):
116+
with open(source_path, "rb") as f:
117+
temp_soup = BeautifulSoup(f, "html.parser")
118+
source_part = getattr(temp_soup, part)
119+
if source_part:
120+
target_tag.extend(source_part.contents)
121+
122+
115123
parser = OptionParser()
116124
parser.add_option(
117125
"-f",
@@ -883,33 +891,32 @@ def determine_legend(fig, column):
883891
size = 176
884892

885893
file = options["file1"].split(".darshan")[0]
886-
command = "drishti --html --light --size {} --json {} {}.darshan".format(
887-
size, json_file_path, file
894+
command = "drishti --html --light --size {} --json {} --export_dir {} {}.darshan".format(
895+
size, json_file_path, file.split('/')[0], file
888896
)
897+
889898
args = shlex.split(command)
890899
s = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
891900
sOutput, sError = s.communicate()
892901

893902
if s.returncode == 0:
894-
drishti_output = open(file + ".drishti", "w")
895-
drishti_output.write(sOutput.decode())
896-
897-
output_doc = BeautifulSoup()
898-
output_doc.append(output_doc.new_tag("body"))
899-
output_doc.append(output_doc.new_tag("head"))
903+
with open(file + ".drishti", "w", encoding="utf-8") as drishti_output:
904+
drishti_output.write(sOutput.decode("utf-8"))
900905

901-
with open(options["output"], "r") as html_file:
902-
output_doc.body.extend(BeautifulSoup(html_file.read(), "html.parser").body)
906+
output_doc = BeautifulSoup("<html><head></head><body></body></html>", "html.parser")
903907

904-
with open(file + ".darshan.html", "r") as html_file:
905-
output_doc.head.extend(BeautifulSoup(html_file.read(), "html.parser").head)
908+
meta_tag = output_doc.new_tag("meta", charset="utf-8")
909+
output_doc.head.append(meta_tag)
906910

907-
with open(file + ".darshan.html", "r") as html_file:
908-
output_doc.body.extend(BeautifulSoup(html_file.read(), "html.parser").body)
911+
append_content(output_doc.body, options["output"], "body")
912+
append_content(output_doc.head, file + ".html", "head")
913+
append_content(output_doc.body, file + ".html", "body")
909914

910-
output_doc.style.append(BeautifulSoup("pre { padding-left: 60px;}", "html.parser"))
915+
style_tag = output_doc.new_tag("style")
916+
style_tag.string = "pre { padding-left: 60px;}"
917+
output_doc.head.append(style_tag)
911918

912-
with open(options["output"], "w") as output_file:
913-
output_file.write(str(output_doc))
919+
with open(options["output"], "wb") as output_file:
920+
output_file.write(output_doc.encode("utf-8"))
914921
else:
915922
sys.exit(os.EX_SOFTWARE)

0 commit comments

Comments
 (0)