Changeset 540

Show
Ignore:
Timestamp:
05/11/2008 10:01:42 PM (2 months ago)
Author:
athomas
Message:
  • Work around some problems with startup ordering. There has to be a better way to
    do this, but it works for now.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ape/trunk/ape/commandline.py

    r537 r540  
    159159    options, args = parser.parse_args(args) 
    160160 
     161    wrapped = cls.trigger_startup_listeners 
     162    def wrapper(self): 
     163        for name, option in ape.Option.registry.iteritems(): 
     164            optparse_option = _to_optparse_option(app.config, option) 
     165            parser.add_option(optparse_option) 
     166 
     167        options, args = parser.parse_args(argv[1:]) 
     168        return wrapped(self) 
     169    cls.trigger_startup_listeners = wrapper 
     170 
    161171    app = cls( 
    162         application_name=name, config_file=options.config, defer_startup=True, 
     172        config_file=options.config, application_name=name, defer_startup=True, 
    163173        logging_uri=options.logging, debug=options.debug, **kwargs 
    164174        ) 
    165175 
    166     for name, option in ape.Option.registry.iteritems(): 
    167         optparse_option = _to_optparse_option(app.config, option) 
    168         parser.add_option(optparse_option) 
    169  
    170     options, args = parser.parse_args(argv[1:]) 
    171176    if not defer_startup: 
    172177        app.startup() 
  • ape/trunk/ape/engine.py

    r539 r540  
    5858 
    5959    # Class defaults 
     60    entry_point_name = None 
    6061    application_name = None 
    6162    config_file = None 
     
    6364    _active_engine = None 
    6465 
    65     def __init__(self, application_name=None, config_file=None, 
     66    def __init__(self, config_file=None, application_name=None, 
    6667                 defer_startup=False, logging_uri=None, debug=None): 
    6768        """Construct a new Engine. 
     
    9798        self.log.debug('APE: Starting %s', self.application_name) 
    9899        self.load_plugins(plugin_paths=self.plugin_paths) 
     100        self.trigger_startup_listeners() 
     101        Engine._active_engine = self 
     102 
     103    def trigger_startup_listeners(self): 
     104        """Call startup listeners. 
     105 
     106        Mostly useful for hooking into startup process. 
     107        """ 
    99108        for listener in self.lifecycle_listeners: 
    100109            listener.engine_startup() 
    101         Engine._active_engine = self 
    102110 
    103111    def shutdown(self): 
     
    116124        """Load all Agate plugins registered through setuptools.""" 
    117125        if entry_point_name is None: 
    118             entry_point_name = self.application_name + '.plugins' 
     126            entry_point_name = self.entry_point_name 
    119127        if plugin_paths is None: 
    120             plugin_paths = [] 
     128            plugin_paths = self.plugin_paths 
    121129 
    122130        distributions, errors = pkg_resources.working_set.find_plugins(