1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-14 10:34:14 +02:00

Added zoomed in snapshot for peek scripts

This commit is contained in:
Thomas Bui
2020-12-28 18:32:49 -08:00
parent 4ec9d85805
commit eb6884db84
15 changed files with 159 additions and 28 deletions

View File

@@ -1,3 +1,6 @@
from os import sep
from typing import List
import re
from selenium.common.exceptions import TimeoutException
# pycharm complains that build_assets is an unresolved ref
@@ -7,27 +10,50 @@ from build_assets import filehandler, util
def main():
args = util.get_commandline_args()
args = util.get_commandline_args(True)
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
if len(new_icons) == 0:
print("No files need to be uploaded. Ending script...")
return
# get only the icon object that has the name matching the pr title
filtered_icons = find_object_added_in_this_pr(new_icons, args.pr_title)
# print list of new icons
print("List of new icons:", *new_icons, sep = "\n")
print("Icons being uploaded:", *filtered_icons, sep = "\n")
runner = None
try:
runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless)
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
runner.upload_svgs(svgs)
screenshot_folder = filehandler.create_screenshot_folder("./")
runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.")
except TimeoutException as e:
print("Selenium Time Out Error: ", e.stacktrace, sep='\n')
except Exception as e:
print(e)
print(e.stacktrace)
finally:
runner.close()
def find_object_added_in_this_pr(icons: List[dict], pr_title: str):
"""
Find the icon name from the PR title.
:param icons, a list of the font objects found in the devicon.json.
:pr_title, the title of the PR that this workflow was called on.
:return a list containing the dictionary with the "name"
entry's value matching the name in the pr_title.
If none can be found, return an empty list.
"""
try:
pattern = re.compile(r"(?<=^new icon: )\w+ (?=\(.+\))", re.I)
icon_name = pattern.findall(pr_title)[0].lower().strip() # should only have one match
return [icon for icon in icons if icon["name"] == icon_name]
except IndexError: # there are no match in the findall()
return []
if __name__ == "__main__":
main()