mirror of
https://github.com/konpa/devicon.git
synced 2025-01-29 11:35:26 +01:00
Refactored peek and build scripts
This commit is contained in:
parent
b745708288
commit
acdbed3075
23
.github/scripts/build_assets/SeleniumRunner.py
vendored
23
.github/scripts/build_assets/SeleniumRunner.py
vendored
@ -75,14 +75,12 @@ class SeleniumRunner:
|
||||
self.driver = WebDriver(options=options, executable_path=geckodriver_path)
|
||||
self.driver.get(self.ICOMOON_URL)
|
||||
assert "IcoMoon App" in self.driver.title
|
||||
|
||||
# wait until the whole web page is loaded by testing the hamburger input
|
||||
hamburger_input = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
|
||||
ec.element_to_be_clickable((By.CSS_SELECTOR,
|
||||
"button.btn5.lh-def.transparent i.icon-menu"))
|
||||
WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
|
||||
ec.element_to_be_clickable((By.XPATH, "(//i[@class='icon-menu'])[2]"))
|
||||
)
|
||||
hamburger_input.click()
|
||||
print("Accessed icomoon.io")
|
||||
|
||||
|
||||
def upload_icomoon(self, icomoon_json_path: str):
|
||||
"""
|
||||
@ -92,11 +90,16 @@ class SeleniumRunner:
|
||||
"""
|
||||
print("Uploading icomoon.json file...")
|
||||
try:
|
||||
self.click_hamburger_input()
|
||||
|
||||
# find the file input and enter the file path
|
||||
import_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
|
||||
ec.element_to_be_clickable((By.CSS_SELECTOR, "div#file input"))
|
||||
)
|
||||
import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input")
|
||||
import_btn.send_keys(icomoon_json_path)
|
||||
except SeleniumTimeoutException as e:
|
||||
print(e.stacktrace)
|
||||
print("Selenium timed out. Couldn't find import button.")
|
||||
self.close()
|
||||
raise e
|
||||
except Exception as e:
|
||||
self.close()
|
||||
raise e
|
||||
@ -159,8 +162,8 @@ class SeleniumRunner:
|
||||
:return: None.
|
||||
"""
|
||||
try:
|
||||
hamburger_input = self.driver.find_element_by_css_selector(
|
||||
"button.btn5.lh-def.transparent i.icon-menu"
|
||||
hamburger_input = self.driver.find_element_by_xpath(
|
||||
"(//i[@class='icon-menu'])[2]"
|
||||
)
|
||||
|
||||
menu_appear_callback = ec.element_to_be_clickable(
|
||||
|
33
.github/scripts/build_assets/util.py
vendored
Normal file
33
.github/scripts/build_assets/util.py
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
from pathlib import Path
|
||||
from argparse import ArgumentParser
|
||||
from build_assets.PathResolverAction import PathResolverAction
|
||||
|
||||
def get_commandline_args():
|
||||
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
|
||||
|
||||
parser.add_argument("--headless",
|
||||
help="Whether to run the browser in headless/no UI mode",
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("geckodriver_path",
|
||||
help="The path to the firefox executable file",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icomoon_json_path",
|
||||
help="The path to the icomoon.json aka the selection.json created by Icomoon",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("devicon_json_path",
|
||||
help="The path to the devicon.json",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icons_folder_path",
|
||||
help="The path to the icons folder",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("download_path",
|
||||
help="The path where you'd like to download the Icomoon files to",
|
||||
action=PathResolverAction)
|
||||
|
||||
|
||||
return parser.parse_args()
|
42
.github/scripts/icomoon_build.py
vendored
Normal file
42
.github/scripts/icomoon_build.py
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
from pathlib import Path
|
||||
from selenium.common.exceptions import TimeoutException
|
||||
|
||||
# pycharm complains that build_assets is an unresolved ref
|
||||
# don't worry about it, the script still runs
|
||||
from build_assets.SeleniumRunner import SeleniumRunner
|
||||
from build_assets import filehandler, util
|
||||
|
||||
|
||||
def main():
|
||||
args = util.get_commandline_args()
|
||||
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
|
||||
|
||||
# print list of new icons
|
||||
print("List of new icons:", *new_icons, sep = "\n")
|
||||
|
||||
runner = None
|
||||
try:
|
||||
runner = SeleniumRunner(args.download_path,
|
||||
args.geckodriver_path, args.headless)
|
||||
runner.upload_icomoon(args.icomoon_json_path)
|
||||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
|
||||
runner.upload_svgs(svgs)
|
||||
|
||||
zip_name = "devicon-v1.0.zip"
|
||||
zip_path = Path(args.download_path, zip_name)
|
||||
runner.download_icomoon_fonts(zip_path)
|
||||
filehandler.extract_files(str(zip_path), args.download_path)
|
||||
filehandler.rename_extracted_files(args.download_path)
|
||||
print("Task completed.")
|
||||
except TimeoutException as e:
|
||||
print(e)
|
||||
print(e.stacktrace)
|
||||
finally:
|
||||
runner.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
48
.github/scripts/icomoon_peek.py
vendored
48
.github/scripts/icomoon_peek.py
vendored
@ -1,61 +1,31 @@
|
||||
from pathlib import Path
|
||||
from argparse import ArgumentParser
|
||||
from selenium.common.exceptions import TimeoutException
|
||||
|
||||
# pycharm complains that build_assets is an unresolved ref
|
||||
# don't worry about it, the script still runs
|
||||
from build_assets.SeleniumRunner import SeleniumRunner
|
||||
from build_assets import filehandler
|
||||
from build_assets.PathResolverAction import PathResolverAction
|
||||
from build_assets import filehandler, util
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
|
||||
|
||||
parser.add_argument("--headless",
|
||||
help="Whether to run the browser in headless/no UI mode",
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("geckodriver_path",
|
||||
help="The path to the firefox executable file",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icomoon_json_path",
|
||||
help="The path to the icomoon.json aka the selection.json created by Icomoon",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("devicon_json_path",
|
||||
help="The path to the devicon.json",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icons_folder_path",
|
||||
help="The path to the icons folder",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("download_path",
|
||||
help="The path where you'd like to download the Icomoon files to",
|
||||
action=PathResolverAction)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
args = util.get_commandline_args()
|
||||
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 peek. Ending script...")
|
||||
print("No files need to be uploaded. Ending script...")
|
||||
return
|
||||
|
||||
# print list of new icons, separated by comma
|
||||
print("List of new icons:")
|
||||
print(*new_icons, sep = "\n")
|
||||
# print list of new icons
|
||||
print("List of new icons:", *new_icons, sep = "\n")
|
||||
|
||||
runner = None
|
||||
try:
|
||||
runner = SeleniumRunner(args.download_path,
|
||||
args.geckodriver_path, args.headless)
|
||||
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)
|
||||
runner.close()
|
||||
print("Task completed.")
|
||||
except TimeoutException as e:
|
||||
print(e)
|
||||
print(e.stacktrace)
|
||||
finally:
|
||||
runner.close()
|
||||
|
||||
|
||||
|
71
.github/scripts/icomoon_upload.py
vendored
71
.github/scripts/icomoon_upload.py
vendored
@ -1,71 +0,0 @@
|
||||
from pathlib import Path
|
||||
from argparse import ArgumentParser
|
||||
from selenium.common.exceptions import TimeoutException
|
||||
|
||||
# pycharm complains that build_assets is an unresolved ref
|
||||
# don't worry about it, the script still runs
|
||||
from build_assets.SeleniumRunner import SeleniumRunner
|
||||
from build_assets import filehandler
|
||||
from build_assets.PathResolverAction import PathResolverAction
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
|
||||
|
||||
parser.add_argument("--headless",
|
||||
help="Whether to run the browser in headless/no UI mode",
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("geckodriver_path",
|
||||
help="The path to the firefox executable file",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icomoon_json_path",
|
||||
help="The path to the icomoon.json aka the selection.json created by Icomoon",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("devicon_json_path",
|
||||
help="The path to the devicon.json",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icons_folder_path",
|
||||
help="The path to the icons folder",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("download_path",
|
||||
help="The path where you'd like to download the Icomoon files to",
|
||||
action=PathResolverAction)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
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
|
||||
|
||||
# print list of new icons, separated by comma
|
||||
print("List of new icons:")
|
||||
print(*new_icons, sep = "\n")
|
||||
try:
|
||||
runner = SeleniumRunner(args.download_path,
|
||||
args.geckodriver_path, args.headless)
|
||||
runner.upload_icomoon(args.icomoon_json_path)
|
||||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
|
||||
runner.upload_svgs(svgs)
|
||||
|
||||
|
||||
zip_name = "devicon-v1.0.zip"
|
||||
zip_path = Path(args.download_path, zip_name)
|
||||
runner.download_icomoon_fonts(zip_path)
|
||||
filehandler.extract_files(str(zip_path), args.download_path)
|
||||
filehandler.rename_extracted_files(args.download_path)
|
||||
runner.close()
|
||||
print("Task completed.")
|
||||
except TimeoutException as e:
|
||||
print(e)
|
||||
print(e.stacktrace)
|
||||
runner.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
5
.github/workflows/build_icons.yml
vendored
5
.github/workflows/build_icons.yml
vendored
@ -19,10 +19,7 @@ jobs:
|
||||
pip install -r ./.github/scripts/requirements.txt
|
||||
npm install
|
||||
- name: Run icomoon_upload.py
|
||||
run: >
|
||||
python ./.github/scripts/icomoon_upload.py
|
||||
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe
|
||||
./icomoon.json ./devicon.json ./icons ./ --headless
|
||||
run: npm run build
|
||||
- name: Upload geckodriver.log for debugging purposes
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{failure()}}
|
||||
|
5
.github/workflows/peek_icons.yml
vendored
5
.github/workflows/peek_icons.yml
vendored
@ -22,10 +22,7 @@ jobs:
|
||||
pip install -r ./.github/scripts/requirements.txt
|
||||
npm install
|
||||
- name: Run icomoon_peek.py
|
||||
run: >
|
||||
python ./.github/scripts/icomoon_peek.py
|
||||
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe
|
||||
./icomoon.json ./devicon.json ./icons ./ --headless
|
||||
run: npm run peek
|
||||
- name: Upload geckodriver.log for debugging purposes
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{failure()}}
|
||||
|
@ -4,7 +4,9 @@
|
||||
"description": "Programming related icons collection",
|
||||
"main": "devicon.min.css",
|
||||
"scripts": {
|
||||
"build-css": "gulp updateCss && gulp clean"
|
||||
"build-css": "gulp updateCss && gulp clean",
|
||||
"build": "python ./.github/scripts/icomoon_build.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./ --headless",
|
||||
"peek": "python ./.github/scripts/icomoon_peek.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./ --headless"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
Loading…
x
Reference in New Issue
Block a user