add InitError exception
This commit is contained in:
		
							parent
							
								
									3f0dc2ad9a
								
							
						
					
					
						commit
						e1e8169985
					
				
					 2 changed files with 15 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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()`.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue