Skip to content

Commit

Permalink
Address more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkavulich committed Nov 6, 2023
1 parent 7eb7a6f commit 28f9892
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
15 changes: 7 additions & 8 deletions tools/check_name_rules.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3

"""
Remove duplicates from a metadata standard-name XML library file.
Check standard names database file for violations of standard name character rules
"""

import argparse
import sys
import os.path
import copy
import re

################################################
Expand Down Expand Up @@ -50,20 +49,20 @@ def main():
validate_xml_file(stdname_file, schema_name, version, None,
schema_path=schema_root, error_on_noxmllint=True)
except ValueError:
raise ValueError("Invalid standard names file, {}".format(stdname_file))
raise ValueError(f"Invalid standard names file, {stdname_file}")
else:
raise ValueError(
'Cannot find schema file, {}, for version {}'.format(schema_name, version)
)
raise ValueError(f'Cannot find schema file, {schema_name}, for {version=}')

#Parse list of standard names and see if any names violate one or more rules
violators = {}
legal_first_char = re.compile('[a-z]')
valid_chars = re.compile('[a-z0-9_]')
for name in root.findall('./section/standard_name'):
sname = name.attrib['name']
violations = []
if re.sub('[a-z]', '', sname[0]):
if legal_first_char.sub('', sname[0]):
violations.append('First character is not a lowercase letter')
testchars = re.sub('[a-z0-9_]', '', sname)
testchars = valid_chars.sub('', sname)
if testchars:
violations.append(f'Invalid characters are present: "{testchars}"')

Expand Down
12 changes: 5 additions & 7 deletions tools/check_xml_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ def main_func():
validate_xml_file(stdname_file, schema_name, version, None,
schema_path=schema_root, error_on_noxmllint=True)
except ValueError:
raise ValueError("Invalid standard names file, {}".format(stdname_file))
raise ValueError(f"Invalid standard names file, {stdname_file}")
else:
raise ValueError(
'Cannot find schema file, {}, for version {}'.format(schema_name, version)
)
raise ValueError(f'Cannot find schema file, {schema_name}, for {version=}')

#get list of all standard names
all_std_names = []
Expand All @@ -87,8 +85,8 @@ def main_func():
print('The following duplicate standard names were found:')
for dup in dup_std_names:
rm_elements = root.findall('./section/standard_name[@name="%s"]'%dup)[1:]
print("{0}, ({1} duplicate(s))".format(dup, len(rm_elements)))
print('Removing duplicates and overwriting {}'.format(stdname_file))
print("{dup}, ({len(rm_elements)} duplicate(s))")
print('Removing duplicates and overwriting {stdname_file}')
for dup in dup_std_names:
first_use = True #Logical that indicates the first use of the duplicated name
rm_parents = root.findall('./section/standard_name[@name="%s"]..'%dup)
Expand All @@ -110,7 +108,7 @@ def main_func():
print('The following duplicate standard names were found:')
for dup in dup_std_names:
rm_elements = root.findall('./section/standard_name[@name="%s"]'%dup)[1:]
print("{0}, ({1} duplicate(s))".format(dup, len(rm_elements)))
print("{dup}, ({len(rm_elements)} duplicate(s))")
sys.exit(1)
else:
print('No duplicate standard names were found.')
Expand Down

0 comments on commit 28f9892

Please sign in to comment.