From e1e816998595030729e829fd18bd5b43730fc1a5 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 1 Aug 2012 14:26:50 -0700 Subject: [PATCH] add InitError exception --- edbob/exceptions.py | 12 ++++++++++++ edbob/initialization.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/edbob/exceptions.py b/edbob/exceptions.py index 16ce3c5..a5a802e 100644 --- a/edbob/exceptions.py +++ b/edbob/exceptions.py @@ -42,6 +42,18 @@ class ConfigError(Exception): self.msg, self.option, self.section) +class InitError(Exception): + """ + Raised when initialization fails for a given module. + """ + + def __init__(self, module): + self.module = module + + def __str__(self): + return "Module '%s' has no init() function" % self.module.__name__ + + class LoadSpecError(Exception): """ Raised when something obvious goes wrong with :func:`edbob.load_spec()`. diff --git a/edbob/initialization.py b/edbob/initialization.py index e4c8ede..4a93344 100644 --- a/edbob/initialization.py +++ b/edbob/initialization.py @@ -35,6 +35,7 @@ from edbob.configuration import ( default_system_paths, default_user_paths, ) +from edbob.exceptions import InitError __all__ = ['init'] @@ -90,6 +91,8 @@ def init(appname='edbob', *args, **kwargs): for name in modules.split(','): name = name.strip() module = __import__(name, globals(), locals(), fromlist=['init']) + if not hasattr(module, 'init'): + raise InitError(module) getattr(module, 'init')(config) # config.inited.append(name)