Author: poeml Date: Fri May 7 00:36:03 2010 New Revision: 8062 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8062&view=rev Log: mb Python module: revamp the error classes (modernized for Python 2.6) Modified: trunk/mb/mb/mberr.py Modified: trunk/mb/mb/mberr.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/mberr.py?rev=8062&r1=8061&r2=8062&view=diff ============================================================================== --- trunk/mb/mb/mberr.py (original) +++ trunk/mb/mb/mberr.py Fri May 7 00:36:03 2010 _at_@ -1,6 +1,6 @@ #!/usr/bin/python -# Copyright (C) 2008 Peter Poeml. All rights reserved. +# Copyright (C) 2008-2010 Peter Poeml. All rights reserved. # This program is free software; it may be used, copied, modified # and distributed under the terms of the GNU General Public Licence, # either version 2, or (at your option) any later version. _at_@ -8,56 +8,51 @@ # exception classes -class Error(Exception): - """Base class for MirrorBrain exceptions.""" +class MbBaseError(Exception): + def __init__(self, args=()): + Exception.__init__(self) + self.args = args + def __str__(self): + return ''.join(self.args) - def __init__(self, msg=''): - self.message = msg - Exception.__init__(self, msg) +class SignalInterrupt(Exception): + """Exception raised on SIGTERM and SIGHUP.""" - def __repr__(self): - return self.message +class UserAbort(MbBaseError): + """Exception raised when the user requested abortion""" - __str__ = __repr__ - - -class CommandFailedError(Error): - """Raised when an executed command returns != 0.""" - - def __init__(self, retcode, stderr, cmd): - Error.__init__(self, 'Command failed. It returned: %r' % (retcode,)) - self.retcode = retcode - self.stderr = stderr - self.cmd = cmd - -class CommandExecuteError(Error): - """Raised when a command could not be executed""" - - def __init__(self, cmd, msg): - Error.__init__(self, 'Could not execute command %r: %r' % (cmd, msg,)) - self.cmd = cmd +class NoConfigfile(MbBaseError): + """Exception raised when mb's configfile cannot be found""" + def __init__(self, fname, msg): + MbBaseError.__init__(self) + self.file = fname self.msg = msg -class MirrorNotFoundError(Error): +class ConfigError(MbBaseError): + """Exception raised when there is an error in the config file""" + def __init__(self, msg, fname): + MbBaseError.__init__(self) + self.msg = msg + self.file = fname + +class MirrorNotFoundError(MbBaseError): """Raised when a mirror wasn't found in the database""" + def __init__(self, identifier): + MbBaseError.__init__(self) + self.identifier = identifier + self.msg = 'A mirror with identifier %r does not exist in the database' \ + % self.identifier - def __init__(self, msg): - Error.__init__(self, 'A mirror with identifier %r doesn\'t exist in the database' % (msg,)) - self.msg = msg +class SocketError(MbBaseError): + """Raised for network errors""" + def __init__(self, url, msg): + MbBaseError.__init__(self) + self.url = url + self.msg = 'Could not access %r: %r' % (url, msg) -class SocketError(Error): - """Raised for network errors""" +class NameOrServiceNotKnown(MbBaseError): + """Raised when a hostname could not be looked up in the DNS""" + def __init__(self, hostname): + MbBaseError.__init__(self) + self.msg = 'DNS lookup for hostname %r failed: Name or service not known' % hostname - def __init__(self, url, msg): - Error.__init__(self, 'Cannot access %r: %r' % (url, msg,)) - self.url = url - self.msg = msg - -class NameOrServiceNotKnown(Error): - """Raised when a hostname could not be looked up in the DNS""" - - def __init__(self, msg): - Error.__init__(self, 'DNS lookup for hostname %r failed: Name or service not known' % (msg,)) - self.msg = msg - - _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu May 06 2010 - 22:36:06 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT