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

Python now print traceback

This commit is contained in:
Thomas Bui
2021-01-08 15:36:05 -08:00
parent b7ae338d2f
commit b1922925b7
7 changed files with 61 additions and 47 deletions

View File

@@ -214,6 +214,7 @@ def get_added_modified_svgs(files_changed_json_path: str):
:return: a list of the svg file paths that were added/modified in this pr.
"""
files_dict = get_json_file_content(files_changed_json_path)
print(files_dict)
svgs = []
for file in files_dict["added"]:
path = Path(file)

View File

@@ -1,33 +0,0 @@
import os
import platform
def set_env_var(key: str, value: str, delimiter: str='~'):
"""
Set the GitHub env variable of 'key' to 'value' using
the method specified here:
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
Support both Windows and Ubuntu machines provided by GitHub Actions.
:param: key, the name of the env variable.
:param: value, the value of the env variable.
:param: delimiter, the delimiter that you want to use
to write to the file. Only applicable if the 'value' contains
'\n' character aka a multiline string.
"""
if platform.system() == "Windows":
if "\n" in value:
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%')
os.system(f'echo "{value}" >> %GITHUB_ENV%')
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%')
else:
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%')
elif platform.system() == "Linux":
if "\n" in value:
os.system(f'echo "{key}<<{delimiter}" >> $GITHUB_ENV')
os.system(f'echo "{value}" >> $GITHUB_ENV')
os.system(f'echo "{delimiter}" >> $GITHUB_ENV')
else:
os.system(f'echo "{key}={value}" >> $GITHUB_ENV')
else:
raise Exception("This function doesn't support this platform: " + platform.system())

View File

@@ -1,6 +1,19 @@
from typing import List
import xml.etree.ElementTree as et
from pathlib import Path
import os
import platform
import sys
import traceback
def exit_with_err(err: Exception):
"""
Exit the current step and display the err.
:param: err, the error/exception encountered.
"""
traceback.print_exc()
sys.exit(str(err))
def check_svgs(svg_file_paths: List[Path]):
@@ -50,4 +63,35 @@ def check_svgs(svg_file_paths: List[Path]):
err_msgs.append("\n".join(err_msg))
if len(err_msgs) > 0:
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
def set_env_var(key: str, value: str, delimiter: str='~'):
"""
Set the GitHub env variable of 'key' to 'value' using
the method specified here:
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
Support both Windows and Ubuntu machines provided by GitHub Actions.
:param: key, the name of the env variable.
:param: value, the value of the env variable.
:param: delimiter, the delimiter that you want to use
to write to the file. Only applicable if the 'value' contains
'\n' character aka a multiline string.
"""
if platform.system() == "Windows":
if "\n" in value:
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%')
os.system(f'echo "{value}" >> %GITHUB_ENV%')
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%')
else:
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%')
elif platform.system() == "Linux":
if "\n" in value:
os.system(f'echo "{key}<<{delimiter}" >> $GITHUB_ENV')
os.system(f'echo "{value}" >> $GITHUB_ENV')
os.system(f'echo "{delimiter}" >> $GITHUB_ENV')
else:
os.system(f'echo "{key}={value}" >> $GITHUB_ENV')
else:
raise Exception("This function doesn't support this platform: " + platform.system())

View File

@@ -1,11 +1,10 @@
from pathlib import Path
import json
import traceback
import sys
# pycharm complains that build_assets is an unresolved ref
# don't worry about it, the script still runs
from build_assets import filehandler, arg_getters
from build_assets import svg_checker
from build_assets import util
def main():
@@ -17,10 +16,11 @@ def main():
try:
devicon_json = filehandler.get_json_file_content(args.devicon_json_path)
svgs = filehandler.get_svgs_paths(devicon_json, args.icons_folder_path)
svg_checker.check_svgs(svgs)
util.check_svgs(svgs)
print("All SVGs found were good. Task completed.")
except Exception as e:
sys.exit(str(e))
util.exit_with_err(e)
if __name__ == "__main__":

View File

@@ -5,7 +5,7 @@ import time
# pycharm complains that build_assets is an unresolved ref
# don't worry about it, the script still runs
from build_assets import filehandler, arg_getters
from build_assets import github_env, svg_checker
from build_assets import util
def main():
@@ -19,11 +19,11 @@ def main():
# check the svgs
svgs = filehandler.get_added_modified_svgs(args.files_changed_json_path)
print("SVGs to check: ", *svgs, sep='\n')
svg_checker.check_svgs(svgs)
util.check_svgs(svgs)
print("All SVGs found were good. Task completed.")
except Exception as e:
github_env.set_env_var("SVG_ERR_MSGS", str(e))
sys.exit(str(e))
util.set_env_var("SVG_ERR_MSGS", str(e))
util.exit_with_err(e)
if __name__ == "__main__":

View File

@@ -6,6 +6,7 @@ from selenium.common.exceptions import TimeoutException
# don't worry about it, the script still runs
from build_assets.SeleniumRunner import SeleniumRunner
from build_assets import filehandler, arg_getters
from build_assets import util
def main():
@@ -32,9 +33,9 @@ def main():
filehandler.rename_extracted_files(args.download_path)
print("Task completed.")
except TimeoutException as e:
sys.exit("Selenium Time Out Error: \n" + str(e))
util.exit_with_err("Selenium Time Out Error: \n" + str(e))
except Exception as e:
sys.exit(str(e))
util.exit_with_err(e)
finally:
runner.close()

View File

@@ -8,6 +8,7 @@ import xml.etree.ElementTree as et
# don't worry about it, the script still runs
from build_assets.SeleniumRunner import SeleniumRunner
from build_assets import filehandler, arg_getters
from build_assets import util
def main():
@@ -39,9 +40,9 @@ def main():
runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.")
except TimeoutException as e:
sys.exit("Selenium Time Out Error: \n" + str(e))
util.exit_with_err("Selenium Time Out Error: \n" + str(e))
except Exception as e:
sys.exit(str(e))
util.exit_with_err(e)
finally:
runner.close()