diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-06-23 03:23:37 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-07-15 12:28:52 +0200 |
commit | b5e9f7b0f5f8b7e37c9e67b0eda0589ce263c200 (patch) | |
tree | c96583bedf0c6cde937350d0ed96e2ddd05adc8a /src | |
parent | 82b24514cfe6232e278ba5783171dd3a39b8e66d (diff) | |
download | nbb-b5e9f7b0f5f8b7e37c9e67b0eda0589ce263c200.tar.gz nbb-b5e9f7b0f5f8b7e37c9e67b0eda0589ce263c200.tar.xz nbb-b5e9f7b0f5f8b7e37c9e67b0eda0589ce263c200.zip |
Got rid of all strings used as exceptions
Diffstat (limited to 'src')
-rw-r--r-- | src/nbblib/bs.py | 2 | ||||
-rw-r--r-- | src/nbblib/main.py | 17 | ||||
-rw-r--r-- | src/nbblib/plugins.py | 12 | ||||
-rw-r--r-- | src/nbblib/vcs.py | 2 |
4 files changed, 29 insertions, 4 deletions
diff --git a/src/nbblib/bs.py b/src/nbblib/bs.py index cb498cb..c7a33be 100644 --- a/src/nbblib/bs.py +++ b/src/nbblib/bs.py @@ -43,7 +43,7 @@ class BSSourceTree(object): def detect(cls, vcs_tree, context): """Find BS tree type and return it""" if len(BSSourceTree.plugins) < 1: - raise "No BS source tree classes registered" + raise NoPluginsRegistered(cls) matches = PluginDict() for key, klass in BSSourceTree.plugins.items(): try: diff --git a/src/nbblib/main.py b/src/nbblib/main.py index 079d743..19582ed 100644 --- a/src/nbblib/main.py +++ b/src/nbblib/main.py @@ -109,7 +109,20 @@ def print_version(context): def print_help(context): print __doc__ % context, + + +class PropertySetAgainError(Exception): + def __str__(self): + return "Property cannot be set more than once" + +class InvalidPropertyValue(Exception): + def __init__(self, value): + super(InvalidPropertyValue, self).__init__() + self.value = value + def __str__(self): + return "Property cannot be set to invalid value '%s'" % self.value + class Property(object): def __init__(self, **kwargs): @@ -126,9 +139,9 @@ class Property(object): def __set__(self, instance, value): # print "Property.__set__", instance, value if hasattr(self, 'value'): - raise "Property cannot be set more than once" + raise PropertySetAgainError() elif not self.isvalid(value): - raise "Property cannot be set to invalid value '%s'" % value + raise InvalidPropertyValue else: self.value = self.convert(value) def __str__(self): diff --git a/src/nbblib/plugins.py b/src/nbblib/plugins.py index bd6839b..1b7a653 100644 --- a/src/nbblib/plugins.py +++ b/src/nbblib/plugins.py @@ -1,3 +1,6 @@ +import sys + + class DuplicatePluginName(Exception): pass @@ -35,6 +38,15 @@ class PluginDict(object): # Slightly modified go store plugins as dict. ######################################################################## + +class NoPluginsRegistered(Exception): + def __init__(self, cls): + super(NoPluginsRegistered, self).__init__() + self.cls = cls + def __str__(self): + return "No %s plugins registered" % (self.cls.__name__) + + class GenericPluginMeta(type): def __init__(cls, name, bases, attrs): if not hasattr(cls, 'plugins'): diff --git a/src/nbblib/vcs.py b/src/nbblib/vcs.py index b0aee5b..a3e4867 100644 --- a/src/nbblib/vcs.py +++ b/src/nbblib/vcs.py @@ -73,7 +73,7 @@ class VCSourceTree(object): def detect(cls, srcdir, context): """Detect VCS tree type and return object representing it""" if len(VCSourceTree.plugins) < 1: - raise "No VC source tree classes registered" + raise NoPluginsRegistered(cls) matches = PluginDict() for key, klass in VCSourceTree.plugins.items(): try: |