Thanks
That is what I am looking for
cropr

On 23 jan, 10:03, Mike Orr <[email protected]> wrote:
> On Fri, Jan 23, 2009 at 12:31 AM, cropr <[email protected]> wrote:
>
> > I want to add some administrative console tools next to my 0.9.7
> > Pylons application (e.g. a backup/restore).  I want to make use of
> > some parameter settings in the development.ini or production.ini,
> > but I don't need any wsgi stuff.  What is the best and easiest way to
> > start up the console application
>
> The easiest way is to make a package for your scripts and run them
> with "python -m"; e.g.,
>
>     python -m myapp.scripts.maintain   development.ini
>
> .  A more difficult way is to create paster plugins, but these will
> only be available if the current directory is the application.
>
> You can read the configuration and set up logging like this:
>
> import logging, os, sys
> from paste.deploy.converters import asbool
> from paste.deploy.loadwsgi import NicerConfigParser
> ini_file =  sys.argv[1]
> ini_dir = os.path.dirname(os.path.abspath(ini_file))
> logging.config.fileConfig(ini_file)
> cp = NicerConfigParser(ini_file)
> global_conf = cp.defaults()
> cp._defaults.setdefault("here", ini_dir)
> cp._defaults.setdefault("__file__", ini_file)
> dburl = cp.get("app:main", "sqlalchemy.url")
> verbose = asbool(cp.get("my-section", "verbose"))
>
> To parse a configuration section into a dict:
>
> def get_config(cp, section):
>     defaults = cp.defaults()
>     ret = {}
>     for key in cp.options(section):
>         value = cp.get(section, key)
>         if key.startswith("set "):   # Override a global option
>             global_key = key[4:]
>             defaults[global_key] = value
>         elif key in defaults:
>             pass   # Don't include variables that were copied from
> defaults, unless you want them
>         else:
>            ret[key] = value
>     return ret, defaults
>
> --
> Mike Orr <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to