def main(): verify_environment() if args["create_config_template"]: create_config_template() # clear out dist/ directory clean_dist() # Copy source/*.puml files to dist/ copy_puml() # Build and validate each entry as icon object source_files = build_file_list() icons = [Icon(filename, config) for filename in source_files] # Create category directories categories = sorted(set([icon.category for icon in icons])) for i in categories: Path(f"../dist/{i}").mkdir(exist_ok=True) # Create PlantUML sprites pool = Pool(processes=multiprocessing.cpu_count()) for i in icons: pool.apply_async(worker, args=(i,)) pool.close() pool.join() # Generate "all.puml" files for each category for i in categories: create_category_all_file(Path(f"../dist/{i}")) # Create markdown sheet and place in dist sorted_icons = sorted(icons, key=lambda x: (x.category, x.target)) markdown = cfg.MARKDOWN_PREFIX_TEMPLATE for i in categories: category = i markdown += f"**{category}** | | | **{category}/all.puml**\n" for j in sorted_icons: if j.category == i: cat = j.category tgt = j.target markdown += ( f"{cat} | {tgt} | ![{tgt}](dist/{cat}/{tgt}.png?raw=true) |" f"{cat}/{tgt}.puml\n" ) with open(Path(f"../{cfg.PREFIX}Symbols.md"), "w") as f: f.write(markdown)
def create_config_template(): """Create config_template.yml file""" source_files = build_file_list() files_sorted = sorted(str(i) for i in source_files) current_category = None entries = [] category_dict = {} dupe_check = [] # checking for duplicate names that need to be resolved for i in files_sorted: # Get elements needed for YAML file category = i.split("/")[3] target = Icon(i.split("/")[-1], {})._make_name(i.split("/")[-1]) source_name = i.split("/")[-1].split("*****@*****.**")[0] file_source_dir = "/".join(i.split("/", 3)[-1].split("/")[:-1]) # Process each file and populate entries for creating YAML file if category != current_category: if current_category is not None: entries.append(category_dict) current_category = category category_dict = { "Name": category, "SourceDir": category, "Services": [] } if "/" in file_source_dir: # Sub directories, add SourceDir to service if target in dupe_check: category_dict["Services"].append({ "Source": source_name, "Target": target, "SourceDir": file_source_dir, "ZComment": "******* Duplicate target name, must be made unique for All.puml ********", }) else: category_dict["Services"].append({ "Source": source_name, "Target": target, "SourceDir": file_source_dir, }) dupe_check.append(target) else: if target in dupe_check: category_dict["Services"].append({ "Source": source_name, "Target": target, "ZComment": "******* Duplicate target name, must be made unique for All.puml ********", }) else: category_dict["Services"].append({ "Source": source_name, "Target": target }) dupe_check.append(target) # Append last category entries.append(category_dict) yaml_content = yaml.safe_load(TEMPLATE_DEFAULT) yaml_content["Categories"] = entries 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)