|
1 | | -from pathlib import Path |
2 | | -from argparse import ArgumentParser |
3 | 1 | from selenium.common.exceptions import TimeoutException |
4 | 2 |
|
5 | 3 | # pycharm complains that build_assets is an unresolved ref |
6 | 4 | # don't worry about it, the script still runs |
7 | 5 | from build_assets.SeleniumRunner import SeleniumRunner |
8 | | -from build_assets import filehandler |
9 | | -from build_assets.PathResolverAction import PathResolverAction |
| 6 | +from build_assets import filehandler, util |
10 | 7 |
|
11 | 8 |
|
12 | 9 | 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 | | - |
| 10 | + args = util.get_commandline_args() |
41 | 11 | new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path) |
42 | 12 | if len(new_icons) == 0: |
43 | | - print("No files need to be peek. Ending script...") |
| 13 | + print("No files need to be uploaded. Ending script...") |
44 | 14 | return |
45 | 15 |
|
46 | | - # print list of new icons, separated by comma |
47 | | - print("List of new icons:") |
48 | | - print(*new_icons, sep = "\n") |
| 16 | + # print list of new icons |
| 17 | + print("List of new icons:", *new_icons, sep = "\n") |
| 18 | + |
| 19 | + runner = None |
49 | 20 | try: |
50 | | - runner = SeleniumRunner(args.download_path, |
51 | | - args.geckodriver_path, args.headless) |
| 21 | + runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless) |
52 | 22 | svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path) |
53 | 23 | runner.upload_svgs(svgs) |
54 | | - runner.close() |
55 | 24 | print("Task completed.") |
56 | 25 | except TimeoutException as e: |
57 | 26 | print(e) |
58 | 27 | print(e.stacktrace) |
| 28 | + finally: |
59 | 29 | runner.close() |
60 | 30 |
|
61 | 31 |
|
|
0 commit comments