summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--command.py6
-rw-r--r--command_context.py2
-rw-r--r--command_manager.py6
-rw-r--r--error.py32
-rw-r--r--filter.py3
-rw-r--r--format.py3
-rw-r--r--main.py2
-rw-r--r--utils.py26
8 files changed, 45 insertions, 35 deletions
diff --git a/command.py b/command.py
index 9c5e946..fc890ba 100644
--- a/command.py
+++ b/command.py
@@ -8,10 +8,10 @@ __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
import logging
from optparse import make_option, SUPPRESS_HELP
+from .error import ClufterError, \
+ EC
from .plugin_registry import PluginRegistry
-from .utils import ClufterError, \
- EC, \
- func_defaults_varnames, \
+from .utils import func_defaults_varnames, \
head_tail, \
hybridproperty
diff --git a/command_context.py b/command_context.py
index f251a44..fc8c7dd 100644
--- a/command_context.py
+++ b/command_context.py
@@ -7,7 +7,7 @@ __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
import logging
-from .utils import ClufterError
+from .error import ClufterError
log = logging.getLogger(__name__)
diff --git a/command_manager.py b/command_manager.py
index 389c843..acbb730 100644
--- a/command_manager.py
+++ b/command_manager.py
@@ -8,10 +8,10 @@ __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
import logging
from .command import commands
+from .error import ClufterError, ClufterPlainError, \
+ EC
from .plugin_registry import PluginManager
-from .utils import ClufterError, ClufterPlainError, \
- EC, \
- apply_preserving_depth, \
+from .utils import apply_preserving_depth, \
apply_aggregation_preserving_depth, \
apply_intercalate
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)
diff --git a/filter.py b/filter.py
index 92d5799..2484d98 100644
--- a/filter.py
+++ b/filter.py
@@ -12,8 +12,9 @@ from collections import OrderedDict, defaultdict
from lxml import etree
+from .error import ClufterError
from .plugin_registry import PluginRegistry
-from .utils import ClufterError, head_tail, hybridproperty, filtervarspop
+from .utils import head_tail, hybridproperty, filtervarspop
from .command_context import CommandContext
log = logging.getLogger(__name__)
diff --git a/format.py b/format.py
index d4e2ca4..ef3e211 100644
--- a/format.py
+++ b/format.py
@@ -16,8 +16,9 @@ from sys import modules
from lxml import etree
+from .error import ClufterError
from .plugin_registry import PluginRegistry
-from .utils import ClufterError, classproperty
+from .utils import classproperty
log = logging.getLogger(__name__)
MAX_DEPTH = 1000
diff --git a/main.py b/main.py
index 1079c7b..361e600 100644
--- a/main.py
+++ b/main.py
@@ -12,10 +12,10 @@ from optparse import make_option, \
OptionGroup, \
IndentedHelpFormatter
+from .error import EC
from .format_manager import FormatManager
from .filter_manager import FilterManager
from .command_manager import CommandManager
-from .utils import EC
from . import version_text, description_text
diff --git a/utils.py b/utils.py
index 2ef8bf5..785bdad 100644
--- a/utils.py
+++ b/utils.py
@@ -9,11 +9,7 @@ import os
import sys
from subprocess import Popen
-
-# name the exitcodes
-ecodes = 'SUCCESS', 'FAILURE'
-EC = type('EC', (), dict((n, v) for v, n
- in enumerate('EXIT_' + i for i in ecodes)))
+from .error import ClufterError
head_tail = lambda x=None, *y: (x, x if x is None else y)
@@ -76,26 +72,6 @@ def func_defaults_varnames(func):
return func_defaults, func_varnames
-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)
-
-
class OneoffWrappedStdinPopen(object):
"""Singleton to watch for atmost one use of stdin in Popen context"""
def __init__(self):