From b5e9f7b0f5f8b7e37c9e67b0eda0589ce263c200 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Mon, 23 Jun 2008 03:23:37 +0200 Subject: Got rid of all strings used as exceptions --- src/nbblib/bs.py | 2 +- src/nbblib/main.py | 17 +++++++++++++++-- src/nbblib/plugins.py | 12 ++++++++++++ src/nbblib/vcs.py | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) (limited to 'src') 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: -- cgit