forked from ESCOMP/CAM-SIMA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates based on bug fixes and feedback.
- Loading branch information
1 parent
19e1586
commit 680d5a8
Showing
7 changed files
with
819 additions
and
24 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import argparse | ||
from collections import defaultdict | ||
from pathlib import Path | ||
from bs4 import BeautifulSoup | ||
import csv | ||
import re | ||
|
||
|
||
def parse_csv(csv_filepath): | ||
datamap = defaultdict(set) | ||
pattern = re.compile("\w+") | ||
print(f"Opening {csv_filepath}") | ||
with open(csv_filepath) as csvfile: | ||
csvdata = csv.reader(csvfile) | ||
for row in csvdata: | ||
inputname = row[0].split(" ")[0] | ||
standardnameMatch = pattern.fullmatch(row[5].split(" ")[0]) | ||
if csvdata.line_num < 432 and standardnameMatch and inputname and "Skipping" not in row[5] and "CCPP" not in row[5]: | ||
print(f"Adding {inputname} under {standardnameMatch.string}") | ||
# if standardnameMatch.string in datamap: | ||
# raise Exception(f"Found duplicate standard name {standardnameMatch.string} on line {csvdata.line_num}") | ||
datamap[standardnameMatch.string].add(inputname) | ||
return datamap | ||
|
||
|
||
|
||
def generate_stdname_xml(current_dict, output_filename): | ||
xmltree = BeautifulSoup(features="xml") | ||
|
||
entries = xmltree.new_tag("entries") | ||
for k, v in current_dict.items(): | ||
entry = xmltree.new_tag("entry") | ||
entry["stdname"] = k | ||
names = xmltree.new_tag("ic_file_input_names") | ||
for name in v: | ||
namenode = xmltree.new_tag("ic_file_input_name") | ||
namenode.string = name | ||
names.append(namenode) | ||
entry.append(names) | ||
entries.append(entry) | ||
xmltree.append(entries) | ||
with open(output_filename, "w") as xmlout: | ||
print(f"Creating new xml file : {output_filename}") | ||
xmlout.write(xmltree.prettify()) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='') | ||
parser.add_argument('--csv-file', type=str, default='CCPP Standard Names - Sheet1.csv', help='') | ||
parser.add_argument('--current-map', type=str, default='stdnames_to_inputnames_dictionary.xml', help='') | ||
parser.add_argument('--output-map', type=str, default='stdnames_to_inputnames_dictionary_new.xml', help='') | ||
|
||
args = parser.parse_args() | ||
|
||
current_csv_entries = parse_csv(args.csv_file) | ||
generate_stdname_xml(current_csv_entries, args.output_map) | ||
|
||
|
||
if __name__=="__main__": | ||
main() |
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
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