From 015f62d05b35466a6fbb5f33370d9615e028f9f0 Mon Sep 17 00:00:00 2001 From: umarcor Date: Sun, 20 Jun 2021 02:57:43 +0200 Subject: pyGHDL: add ghdl-dom entrypoint --- pyGHDL/cli/DOM.py | 4 ++-- setup.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyGHDL/cli/DOM.py b/pyGHDL/cli/DOM.py index 2b846edde..1ab3d4321 100755 --- a/pyGHDL/cli/DOM.py +++ b/pyGHDL/cli/DOM.py @@ -40,7 +40,7 @@ class Application: print("\n".join(buffer)) -def main(items): +def main(items=argv[1:]): _exitcode = 0 if len(items) < 1: @@ -63,4 +63,4 @@ def main(items): if __name__ == "__main__": - sysexit(main(argv[1:])) + sysexit(main()) diff --git a/setup.py b/setup.py index db08a2296..75e04bb3a 100644 --- a/setup.py +++ b/setup.py @@ -93,7 +93,8 @@ setuptools_setup( packages=setuptools_find_packages(exclude=("tests",)), entry_points={ 'console_scripts': [ - "ghdl-ls = pyGHDL.cli.lsp:main" + "ghdl-ls = pyGHDL.cli.lsp:main", + "ghdl-dom = pyGHDL.cli.DOM:main" ] }, -- cgit v1.2.3 From 38571ce4ce5e1d594a7c55f5bb6f1514f1402329 Mon Sep 17 00:00:00 2001 From: umarcor Date: Sun, 20 Jun 2021 01:02:59 +0200 Subject: pyGHDL/cli/DOM: handle multiple exception types --- pyGHDL/cli/DOM.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/pyGHDL/cli/DOM.py b/pyGHDL/cli/DOM.py index 1ab3d4321..2feb6aecd 100755 --- a/pyGHDL/cli/DOM.py +++ b/pyGHDL/cli/DOM.py @@ -7,15 +7,15 @@ from pathlib import Path from pydecor import export +from pyGHDL import GHDLBaseException +from pyGHDL.libghdl import LibGHDLException from pyGHDL.dom import NonStandard +from pyGHDL.dom.Common import DOMException +from pyGHDL.dom.formatting.prettyprint import PrettyPrint, PrettyPrintException __all__ = [] __api__ = __all__ -from pyGHDL.dom.Common import DOMException - -from pyGHDL.dom.formatting.prettyprint import PrettyPrint, PrettyPrintException - @export class Application: @@ -40,6 +40,26 @@ class Application: print("\n".join(buffer)) +def handleException(ex): + if isinstance(ex, PrettyPrintException): + print("PP:", ex) + return 5 + elif isinstance(ex, DOMException): + print("DOM:", ex) + return 4 + elif isinstance(ex, LibGHDLException): + print("LIB:", ex) + return 3 + elif isinstance(ex, GHDLBaseException): + print("GHDL:", ex) + return 2 + else: + print( + "Fatal: An unhandled exception has reached to the top-most exception handler." + ) + return 1 + + def main(items=argv[1:]): _exitcode = 0 @@ -53,11 +73,8 @@ def main(items=argv[1:]): app = Application() app.addFile(Path(item), "default_lib") app.prettyPrint() - except DOMException as ex: - print("DOM:", ex) - except PrettyPrintException as ex: - print("PP:", ex) - _exitcode = 1 + except Exception as ex: + _exitcode = handleException(ex) return _exitcode -- cgit v1.2.3