You don't have to create an entry-point though.
What I've done is add the following code to my XXX/model/__init__.py:

def config_from_ini(ini_name):
    """
    Returns a configuration object from a path to an INI file.
    """
    # Store the config obj as a global, for later use.
    global config
    config = appconfig('config:%s' % os.path.join(
        os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath
(__file__)))),
        ini_name))
    return config

def init_model_from_ini(ini_or_config):
    """
    Initialize model from either an INI file path or a config object.
    """
    if isinstance(ini_or_config, basestring):
        config = config_from_ini(ini_or_config)
    else:
        config = ini_or_config
    engine = create_engine(config['sqlalchemy.url'])
    init_model(engine)
    return engine

Then in my command-line scripts (crons, batch jobs etc.) I add the
following line:

engine = init_model_from_ini(ini_name)

where `ini_name` is taken from a command-line argument, but could be
hardwired (e.g. "XXX/deployment.ini").

I can also get the config object as `XXX.model.config`, which is
useful when I have my own config directives to retrieve.

Would it be useful that I contribute that code in a bug report?

Regards

Antoine.

--

You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.


Reply via email to