Page MenuHomec4science

warning_manager.py
No OneTemporary

File Metadata

Created
Sun, Dec 1, 02:31

warning_manager.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import traceback as tb
from datetime import datetime
__all__ = ['RROMPyWarning']
def getTimestamp() -> str:
return "\x1b[42m{}\x1b[0m".format(datetime.now().strftime("%H:%M:%S.%f"))
def RROMPyWarning(msg : str = "", stacklevel : int = 0):
frameSummary = tb.extract_stack()[- 3 - stacklevel]
timestamp = getTimestamp()
if frameSummary.name == "<module>": name = ""
else: name = ", within {}".format(frameSummary.name)
print("{}\x1b[3m Warning at {}:{}{}:\x1b[0m".format(timestamp,
frameSummary.filename,
frameSummary.lineno,
name))
print("> \x1b[31m{}\x1b[0m".format(frameSummary.line))
if len(msg) > 0:
print("\x1b[3m {}\x1b[0m\n".format(msg))

Event Timeline