summaryrefslogtreecommitdiffstats
path: root/error.py
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-01-27 14:17:23 +0100
committerJan Pokorný <jpokorny@redhat.com>2014-01-27 23:17:25 +0100
commitabfb91d87a57970315504508dd094b9f5cdba489 (patch)
tree4b038e0b4898aba023edf2c8ddcb614b679e8889 /error.py
parentce201e6299a08fe29fe0e4af3d8b2a30f4f67b2c (diff)
downloadclufter-abfb91d87a57970315504508dd094b9f5cdba489.tar.gz
clufter-abfb91d87a57970315504508dd094b9f5cdba489.tar.xz
clufter-abfb91d87a57970315504508dd094b9f5cdba489.zip
Move base exceptions and exit codes to separate error.py
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'error.py')
-rw-r--r--error.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/error.py b/error.py
new file mode 100644
index 0000000..5aafec5
--- /dev/null
+++ b/error.py
@@ -0,0 +1,32 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2014 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2 (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+"""Base exception classes and exit code definitions"""
+__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
+
+
+# name the exitcodes
+ecodes = 'SUCCESS', 'FAILURE'
+EC = type('EC', (), dict((n, v) for v, n
+ in enumerate('EXIT_' + i for i in ecodes)))
+
+
+class ClufterError(Exception):
+ def __init__(self, ctx_self, msg, *args):
+ self.ctx_self = ctx_self
+ self.msg = msg
+ self.args = args
+
+ def __str__(self):
+ ret = ''
+ if self.ctx_self:
+ ret = getattr(self.ctx_self, '__name__',
+ self.ctx_self.__class__.__name__)
+ ret += ': '
+ return ret + self.msg.format(*self.args)
+
+
+class ClufterPlainError(ClufterError):
+ def __init__(self, msg, *args):
+ super(ClufterPlainError, self).__init__(None, msg, *args)