Loading bin/is +3 −3 Original line number Diff line number Diff line Loading @@ -748,10 +748,10 @@ def main(): except KeyboardInterrupt: warn("Keyboard Interrupted") exit(1) except ISException as e: error(u"%s.%s" % (e, e.get_tb())) except ISError as e: error(exception=e) except Exception as e: error(u"Unknown error, please report it: %s." % e) error(u"Unexpected error, please report it with debug enabled", exception=e) # Entry point if __name__ == '__main__': Loading installsystems/exception.py +23 −11 Original line number Diff line number Diff line Loading @@ -32,34 +32,46 @@ class ISException(Exception): ''' Base exception class ''' def __init__(self, message='', exception=None): self.message = message def __init__(self, message="", exception=None): self.message = unicode(message) self.exception = exception if exception: self.exc_info = sys.exc_info() def __str__(self): if self.exception: return "%s: %s" % (self.message, self.exception) return u"%s: %s" % (self.message, self.exception) else: return self.message def get_tb(self): if self.exception and installsystems.verbosity > 1: sio = StringIO.StringIO() def print_tb(self, fd=sys.stderr): ''' Print traceback from embeded exception or current one ''' from installsystems.printer import out # coloring out("#l##B#", fd=fd, endl="") # print original exception traceback if self.exception is not None: traceback.print_exception(self.exc_info[0], self.exc_info[1], self.exc_info[2], file=sio) str = "\n#R#%s" % sio.getvalue() sio.close() return str return "" self.exc_info[2], file=fd) # print current exception traceback else: exc_info = sys.exc_info() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file=fd) # reset color out("#R#", fd=fd, endl="") class ISError(ISException): ''' Installsystems error; this exception will stop execution ''' class ISWarning(ISException): ''' Installsystems warning; this exception do not stop execution ''' installsystems/printer.py +17 −4 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import sys import os import re import installsystems from installsystems.exception import * NOCOLOR = False Loading Loading @@ -92,10 +93,22 @@ def fatal(message, quit=True, fd=sys.stderr, endl=os.linesep): if quit: os._exit(21) def error(message, quit=True, fd=sys.stderr, endl=os.linesep): out(u"#light##red#Error:#reset# #red#%s#reset#" % message, fd, endl) if sys.exc_info()[0] is not None and installsystems.verbosity > 1: raise def error(message=None, exception=None, quit=True, fd=sys.stderr, endl=os.linesep): # create error message pmesg = u"" if message is not None: pmesg += unicode(message) if exception is not None: if pmesg == "": pmesg += unicode(exception) else: pmesg += u": %s" % unicode(exception) # print error message if pmesg != "": out(u"#light##red#Error:#reset# #red#%s#reset#" % pmesg, fd, endl) # print traceback in debug mode if installsystems.verbosity > 1 and isinstance(exception, ISException): exception.print_tb(fd) if quit: exit(42) Loading Loading
bin/is +3 −3 Original line number Diff line number Diff line Loading @@ -748,10 +748,10 @@ def main(): except KeyboardInterrupt: warn("Keyboard Interrupted") exit(1) except ISException as e: error(u"%s.%s" % (e, e.get_tb())) except ISError as e: error(exception=e) except Exception as e: error(u"Unknown error, please report it: %s." % e) error(u"Unexpected error, please report it with debug enabled", exception=e) # Entry point if __name__ == '__main__': Loading
installsystems/exception.py +23 −11 Original line number Diff line number Diff line Loading @@ -32,34 +32,46 @@ class ISException(Exception): ''' Base exception class ''' def __init__(self, message='', exception=None): self.message = message def __init__(self, message="", exception=None): self.message = unicode(message) self.exception = exception if exception: self.exc_info = sys.exc_info() def __str__(self): if self.exception: return "%s: %s" % (self.message, self.exception) return u"%s: %s" % (self.message, self.exception) else: return self.message def get_tb(self): if self.exception and installsystems.verbosity > 1: sio = StringIO.StringIO() def print_tb(self, fd=sys.stderr): ''' Print traceback from embeded exception or current one ''' from installsystems.printer import out # coloring out("#l##B#", fd=fd, endl="") # print original exception traceback if self.exception is not None: traceback.print_exception(self.exc_info[0], self.exc_info[1], self.exc_info[2], file=sio) str = "\n#R#%s" % sio.getvalue() sio.close() return str return "" self.exc_info[2], file=fd) # print current exception traceback else: exc_info = sys.exc_info() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file=fd) # reset color out("#R#", fd=fd, endl="") class ISError(ISException): ''' Installsystems error; this exception will stop execution ''' class ISWarning(ISException): ''' Installsystems warning; this exception do not stop execution '''
installsystems/printer.py +17 −4 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import sys import os import re import installsystems from installsystems.exception import * NOCOLOR = False Loading Loading @@ -92,10 +93,22 @@ def fatal(message, quit=True, fd=sys.stderr, endl=os.linesep): if quit: os._exit(21) def error(message, quit=True, fd=sys.stderr, endl=os.linesep): out(u"#light##red#Error:#reset# #red#%s#reset#" % message, fd, endl) if sys.exc_info()[0] is not None and installsystems.verbosity > 1: raise def error(message=None, exception=None, quit=True, fd=sys.stderr, endl=os.linesep): # create error message pmesg = u"" if message is not None: pmesg += unicode(message) if exception is not None: if pmesg == "": pmesg += unicode(exception) else: pmesg += u": %s" % unicode(exception) # print error message if pmesg != "": out(u"#light##red#Error:#reset# #red#%s#reset#" % pmesg, fd, endl) # print traceback in debug mode if installsystems.verbosity > 1 and isinstance(exception, ISException): exception.print_tb(fd) if quit: exit(42) Loading