Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from cisagov/bug/fix_cisagov_conversion
Browse files Browse the repository at this point in the history
Fix bug in the `convert-cisagov` command
  • Loading branch information
mcdonnnj committed Jan 20, 2022
2 parents d98917f + e0852c2 commit e1c5d47
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/mdyml/convert_cisagov.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ def convert() -> None:

out_dict_list.append(out_dict)

# Sort in the same manner groupby() will group entries
out_dict_list.sort(key=lambda p: p["vendor"][0].lower())

logging.debug("Total rows for grouping: %d", len(out_dict_list))

out_dict_groups = {
k: list(g)
for k, g in groupby(out_dict_list, key=lambda s: s["vendor"][0].upper())
k.upper(): list(g)
for k, g in groupby(out_dict_list, key=lambda s: s["vendor"][0].lower())
}

non_letter_groups = list()
Expand All @@ -173,10 +178,13 @@ def convert() -> None:
del out_dict_groups[key]
out_dict_groups["Non-Alphabet"] = non_letter_groups

total_group_count = 0
for key, data in out_dict_groups.items():
filename = SOFTWARE_LIST_FILE_FORMAT.format(key)
logging.debug("Writing data for '%s' to '%s'", key, filename)
with open(filename, "w") as out_file:
group_count = len(data)
total_group_count += group_count
doc = {
"version": "1.0",
"owners": [
Expand All @@ -196,6 +204,10 @@ def convert() -> None:
yaml.allow_unicode = True
yaml.dump(doc, out_file)

logging.debug("Group '%s' rows: %d", key, group_count)

logging.debug("Total grouped rows processed: %d", total_group_count)


def main() -> None:
"""Set up logging and call the convert function."""
Expand Down

0 comments on commit e1c5d47

Please sign in to comment.