-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore capability to export metadata sections (previously headers) to html #445
Merged
climbfuji
merged 2 commits into
NCAR:main
from
climbfuji:bugfix/restore_metadata_header_to_html
Apr 12, 2022
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -604,6 +604,19 @@ class MetadataSection(ParseSource): | |
|
||
__vref_start = re.compile(r"^\[\s*"+FORTRAN_SCALAR_REF+r"\s*\]$") | ||
|
||
__html_template__ = """ | ||
<html> | ||
<head> | ||
<title>{title}</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<table border="1"> | ||
{header}{contents}</table> | ||
</body> | ||
</html> | ||
""" | ||
|
||
def __init__(self, table_name, table_type, run_env, parse_object=None, | ||
title=None, type_in=None, module=None, process_type=None, | ||
var_dict=None, known_ddts=None): | ||
|
@@ -1266,6 +1279,36 @@ def is_scalar_reference(test_val): | |
"""Return True iff <test_val> refers to a Fortran scalar.""" | ||
return check_fortran_ref(test_val, None, False) is not None | ||
|
||
def to_html(self, outdir, props): | ||
"""Write html file for metadata section and return filename. | ||
Skip metadata sections without variables""" | ||
if not self.__variables.variable_list(): | ||
return None | ||
# Write table header | ||
header = "<tr>" | ||
for prop in props: | ||
header += "<th>{}</th>".format(prop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been converting to f strings, this seems like a good place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have adopted f strings in this PR, thanks for the suggestion. |
||
header += "</tr>\n" | ||
# Write table contents, one row per variable | ||
contents = "" | ||
for var in self.__variables.variable_list(): | ||
row = "<tr>" | ||
for prop in props: | ||
value = var.get_prop_value(prop) | ||
# Pretty-print for dimensions | ||
if prop == 'dimensions': | ||
value = '(' + ', '.join(value) + ')' | ||
elif value is None: | ||
value = "n/a" | ||
row += "<td>{}</td>".format(value) | ||
row += "</tr>\n" | ||
contents += row | ||
filename = os.path.join(outdir, self.title + '.html') | ||
with open(filename,"w") as f: | ||
f.writelines(self.__html_template__.format(title=self.title + ' argument table', | ||
header=header, contents=contents)) | ||
return filename | ||
|
||
######################################################################## | ||
|
||
if __name__ == "__main__": | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this up to where the other active routines are, say right after
write_to_file
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.