Skip to content

Commit c0870b5

Browse files
committed
Added error and warning counters.
1 parent 458124a commit c0870b5

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

doc/conf.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
# -- Project information -----------------------------------------------------
2323

2424
project = 'pyTerminalUI'
25-
copyright = '2007-2019, Patrick Lehmann'
25+
copyright = '2007-2020, Patrick Lehmann'
2626
author = 'Patrick Lehmann'
2727

2828
# The full version, including alpha/beta/rc tags
29-
release = 'v1.2'
29+
release = 'v1.3'
3030

3131

3232
# -- General configuration ---------------------------------------------------
@@ -41,17 +41,27 @@
4141
"sphinx.ext.autodoc",
4242
'sphinx.ext.extlinks',
4343
'sphinx.ext.intersphinx',
44-
'sphinx.ext.inheritance_diagram',
44+
# 'sphinx.ext.inheritance_diagram',
4545
'sphinx.ext.todo',
46-
'sphinx.ext.graphviz',
46+
# 'sphinx.ext.graphviz',
4747
'sphinx.ext.mathjax',
4848
'sphinx.ext.ifconfig',
4949
'sphinx.ext.viewcode',
50-
# SphinxContrib extensions
50+
# 'sphinx.ext.duration',
5151

52-
# Other extensions
53-
# 'DocumentMember',
54-
# local extensions (patched)
52+
# SphinxContrib extensions
53+
54+
# BuildTheDocs extensions
55+
'btd.sphinx.autoprogram',
56+
'btd.sphinx.graphviz',
57+
'btd.sphinx.inheritance_diagram',
58+
59+
# Other extensions
60+
# 'DocumentMember',
61+
'sphinx_fontawesome',
62+
'sphinx_autodoc_typehints',
63+
64+
# local extensions (patched)
5565

5666
# local extensions
5767
]
@@ -114,3 +124,12 @@
114124
# Sphinx.Ext.Graphviz
115125
# ==============================================================================
116126
graphviz_output_format = "svg"
127+
128+
129+
130+
# ==============================================================================
131+
# Sphinx.Ext.ToDo
132+
# ==============================================================================
133+
# If true, `todo` and `todoList` produce output, else they produce nothing.
134+
todo_include_todos = True
135+
todo_link_only = True

pyTerminalUI/__init__.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def deinitColors(cls):
136136
pass
137137

138138
@classmethod
139-
def exit(cls, returnCode=0):
139+
def exit(cls, returnCode:int =0):
140140
"""Exit the terminal application by uninitializing color support and returning an exit code."""
141141
cls.deinitColors()
142142
exit(returnCode)
@@ -174,24 +174,24 @@ def printException(cls, ex):
174174
cls.initColors()
175175

176176
print("{RED}FATAL: An unknown or unhandled exception reached the topmost exception handler!{NOCOLOR}".format(**cls.Foreground))
177-
print("{YELLOW} Exception type:{NOCOLOR} {typename}".format(typename=ex.__class__.__name__, **cls.Foreground))
178-
print("{YELLOW} Exception message:{NOCOLOR} {message!s}".format(message=ex, **cls.Foreground))
177+
print(" {YELLOW}Exception type:{NOCOLOR} {typename}".format(typename=ex.__class__.__name__, **cls.Foreground))
178+
print(" {YELLOW}Exception message:{NOCOLOR} {message!s}".format(message=ex, **cls.Foreground))
179179
frame, sourceLine = [x for x in walk_tb(ex.__traceback__)][-1]
180180
filename = frame.f_code.co_filename
181181
funcName = frame.f_code.co_name
182-
print("{YELLOW} Caused in:{NOCOLOR} {function} in file '{filename}' at line {line}".format(
182+
print(" {YELLOW}Caused in:{NOCOLOR} {function} in file '{filename}' at line {line}".format(
183183
function=funcName,
184184
filename=filename,
185185
line=sourceLine,
186186
**cls.Foreground
187187
))
188188
if (ex.__cause__ is not None):
189-
print("{DARK_YELLOW} Caused by type:{NOCOLOR} {typename}".format(typename=ex.__cause__.__class__.__name__, **cls.Foreground))
190-
print("{DARK_YELLOW} Caused by message:{NOCOLOR} {message!s}".format(message=ex.__cause__, **cls.Foreground))
189+
print(" {DARK_YELLOW}Caused by type:{NOCOLOR} {typename}".format(typename=ex.__cause__.__class__.__name__, **cls.Foreground))
190+
print(" {DARK_YELLOW}Caused by message:{NOCOLOR} {message!s}".format(message=ex.__cause__, **cls.Foreground))
191191
print(("{RED}" + ("-" * 80) + "{NOCOLOR}").format(**cls.Foreground))
192192
print_tb(ex.__traceback__)
193193
print(("{RED}" + ("-" * 80) + "{NOCOLOR}").format(**cls.Foreground))
194-
print(("{RED}Please report this bug at GitHub: https://github.com/VLSI-EDA/pyIPCMI/issues{NOCOLOR}").format(**cls.Foreground))
194+
print(("{RED}Please report this bug at GitHub: https://github.com/Paebbels/pyTerminalUI/issues{NOCOLOR}").format(**cls.Foreground))
195195
print(("{RED}" + ("-" * 80) + "{NOCOLOR}").format(**cls.Foreground))
196196

197197
cls.exit(1)
@@ -522,6 +522,9 @@ def __init__(self, verbose=False, debug=False, quiet=False, writeToStdOut=True):
522522
self._lines = []
523523
self._baseIndent = 0
524524

525+
self._errorCounter = 0
526+
self._warningCounter = 0
527+
525528
@property
526529
def Verbose(self):
527530
"""Returns true, if verbose messages are enabled."""
@@ -565,6 +568,16 @@ def BaseIndent(self, value):
565568
Severity.Debug: "{DARK_GRAY}{message}{NOCOLOR}"
566569
} #: Message formatting rules.
567570

571+
def ExitOnPreviousErrors(self):
572+
if self._errorCounter > 0:
573+
self.WriteFatal("Too many errors in previous steps.")
574+
self.exit()
575+
576+
def ExitOnPreviousWarnings(self):
577+
if self._warningCounter > 0:
578+
self.WriteError("Too many warnings in previous steps.")
579+
self.exit()
580+
568581
def WriteLine(self, line : Line):
569582
"""Print a formatted line to the underlying terminal/console offered by the operating system."""
570583

@@ -579,13 +592,18 @@ def WriteLine(self, line : Line):
579592
def TryWriteLine(self, line):
580593
return (line.Severity >= self._WriteLevel)
581594

582-
def WriteFatal(self, message, indent=0, appendLinebreak=True):
583-
return self.WriteLine(Line(message, Severity.Fatal, self._baseIndent + indent, appendLinebreak))
595+
def WriteFatal(self, message, indent=0, appendLinebreak=True, immediateExit=True):
596+
ret = self.WriteLine(Line(message, Severity.Fatal, self._baseIndent + indent, appendLinebreak))
597+
if immediateExit:
598+
self.exit()
599+
return ret
584600

585601
def WriteError(self, message, indent=0, appendLinebreak=True):
602+
self._errorCounter += 1
586603
return self.WriteLine(Line(message, Severity.Error, self._baseIndent + indent, appendLinebreak))
587604

588605
def WriteWarning(self, message, indent=0, appendLinebreak=True):
606+
self._warningCounter += 1
589607
return self.WriteLine(Line(message, Severity.Warning, self._baseIndent + indent, appendLinebreak))
590608

591609
def WriteInfo(self, message, indent=0, appendLinebreak=True):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
setuptools.setup(
5252
name=projectName,
53-
version="1.2.4",
53+
version="1.3.0",
5454

5555
author="Patrick Lehmann",
5656
author_email="Paebbels@gmail.com",
@@ -89,4 +89,4 @@
8989
install_requires=requirements,
9090
# provides=
9191
# obsoletes=
92-
)
92+
)

0 commit comments

Comments
 (0)