|
| 1 | +from pathlib import Path |
| 2 | +from argparse import ArgumentParser |
| 3 | +from selenium.common.exceptions import TimeoutException |
| 4 | + |
| 5 | +# pycharm complains that build_assets is an unresolved ref |
| 6 | +# don't worry about it, the script still runs |
| 7 | +from build_assets.SeleniumRunner import SeleniumRunner |
| 8 | +from build_assets import filehandler |
| 9 | +from build_assets.PathResolverAction import PathResolverAction |
| 10 | + |
| 11 | + |
| 12 | +def main(): |
| 13 | + parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.") |
| 14 | + |
| 15 | + parser.add_argument("--headless", |
| 16 | + help="Whether to run the browser in headless/no UI mode", |
| 17 | + action="store_true") |
| 18 | + |
| 19 | + parser.add_argument("geckodriver_path", |
| 20 | + help="The path to the firefox executable file", |
| 21 | + action=PathResolverAction) |
| 22 | + |
| 23 | + parser.add_argument("icomoon_json_path", |
| 24 | + help="The path to the icomoon.json aka the selection.json created by Icomoon", |
| 25 | + action=PathResolverAction) |
| 26 | + |
| 27 | + parser.add_argument("devicon_json_path", |
| 28 | + help="The path to the devicon.json", |
| 29 | + action=PathResolverAction) |
| 30 | + |
| 31 | + parser.add_argument("icons_folder_path", |
| 32 | + help="The path to the icons folder", |
| 33 | + action=PathResolverAction) |
| 34 | + |
| 35 | + parser.add_argument("download_path", |
| 36 | + help="The path where you'd like to download the Icomoon files to", |
| 37 | + action=PathResolverAction) |
| 38 | + |
| 39 | + args = parser.parse_args() |
| 40 | + |
| 41 | + new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path) |
| 42 | + if len(new_icons) == 0: |
| 43 | + print("No files need to be uploaded. Ending script...") |
| 44 | + return |
| 45 | + |
| 46 | + # print list of new icons, separated by comma |
| 47 | + print("List of new icons:") |
| 48 | + print(*new_icons, sep = "\n") |
| 49 | + try: |
| 50 | + runner = SeleniumRunner(args.download_path, |
| 51 | + args.geckodriver_path, args.headless) |
| 52 | + runner.upload_icomoon(args.icomoon_json_path) |
| 53 | + svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path) |
| 54 | + runner.upload_svgs(svgs) |
| 55 | + |
| 56 | + |
| 57 | + zip_name = "devicon-v1.0.zip" |
| 58 | + zip_path = Path(args.download_path, zip_name) |
| 59 | + runner.download_icomoon_fonts(zip_path) |
| 60 | + filehandler.extract_files(str(zip_path), args.download_path) |
| 61 | + filehandler.rename_extracted_files(args.download_path) |
| 62 | + runner.close() |
| 63 | + print("Task completed.") |
| 64 | + except TimeoutException as e: |
| 65 | + print(e) |
| 66 | + print(e.stacktrace) |
| 67 | + runner.close() |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + main() |
0 commit comments