in scripts/icon-builder.py [0:0]
def create_config_template():
"""Create config_template.yml file from source icons"""
source_files = []
category_dict = {}
dupe_check = [] # checking for duplicate names that need to be resolved
for dir in dir_list:
source_files = [str(i) for i in build_file_list(dir["dir"], dir["dir_glob"])]
for i in source_files:
# Get elements needed for YAML file
# Exception is if the files originate from the "Category" directory
category = Icon()._make_category(
regex=dir["category_regex"],
filename=i,
mappings=dir["category_mappings"],
)
target = Icon()._make_name(
regex=dir["filename_regex"],
filename=i,
mappings=dir["filename_mappings"],
)
source_name = i.split("/")[-1]
# For source directory, use only relative from this script ./source/official/AWS...
file_source_dir = "/".join(i.split("/", 3)[-1].split("/")[:-1])
# Process each file and populate entries for creating YAML file
# If new category, create new one
try:
if category not in category_dict:
category_dict[category] = {"Icons": []}
except KeyError:
# Initial entry into dict
category_dict = {category: {"Icons": []}}
# Check for duplicate entries then append to
if target not in dupe_check:
category_dict[category]["Icons"].append(
{
"Source": source_name,
"Target": target,
"SourceDir": file_source_dir,
}
)
dupe_check.append(target)
else:
category_dict[category]["Icons"].append(
{
"Source": source_name,
"Target": target,
"SourceDir": file_source_dir,
"ZComment": "******* Duplicate target name, must be made unique for All.puml ********",
}
)
# With the completed dictionary of entries, convert to an OrderedDict and sort by Category -> Target
# The sorted template file makes it easier to review changes between new icon releases
sorted_categories = OrderedDict()
for category in sorted(category_dict):
sorted_categories[category] = {"Icons": []}
sorted_categories[category]["Icons"] = sorted(
category_dict[category]["Icons"], key=lambda i: i["Target"]
)
yaml_content = yaml.safe_load(TEMPLATE_DEFAULT)
yaml_content["Categories"] = dict(sorted_categories)
with open("config-template.yml", "w") as f:
yaml.dump(yaml_content, f, default_flow_style=False)
print("Successfully created config-template.yml")
sys.exit(0)