difficulties load paste app config

35 views
Skip to first unread message

Max Ischenko

unread,
Apr 17, 2007, 3:20:21 AM4/17/07
to pylons-discuss
Hello,

I am trying to add a few project-specific commands to be available in
paster via paste.script entry point. Naturally, I need to access
project's configuration settings from within my commands.

I have copied code from websetup:setup_config but it works strangely.
Here is the code (abridged):

class InitDatabase(command.Command):
def command(self):
name = self.args[0]
app_conf = appconfig('config:'+name, relative_to=conf_dir)
print app_conf

I have three ini files: development.ini, test.ini and staging.ini.

For test.ini it works as it should, printing 21 entries. For
development.ini it only finds 7 entries (from DEFAULT). For
staging.ini it raises an error:


File "/home/max/projects/dou-trunk/site/doupy/doupy/websetup.py",
line 54, in command
app_conf = appconfig('config:'+name, relative_to=conf_dir)
File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
paste/deploy/loadwsgi.py", line 205, in appconfig
return context.config()
File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
paste/deploy/loadwsgi.py", line 609, in config
conf = AttrDict(self.global_conf)
TypeError: iteration over non-sequence

I suppose I am doing it in the wrong way. What is a correct way to
load application's paste config?

I also tried this:

def command(self):
filename = os.path.join(conf_dir, self.args[0])
wsgi_app = paste.deploy.loadapp('config:%s' % filename)

It loads but attempt to access config
print paste.deploy.CONFIG['app_conf']
yields infamous TypeError: No configuration has been registered for
this process or thread

Max.

Ian Bicking

unread,
Apr 17, 2007, 11:53:51 AM4/17/07
to pylons-...@googlegroups.com
Max Ischenko wrote:
> File "/home/max/projects/dou-trunk/site/doupy/doupy/websetup.py",
> line 54, in command
> app_conf = appconfig('config:'+name, relative_to=conf_dir)
> File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
> paste/deploy/loadwsgi.py", line 205, in appconfig
> return context.config()
> File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
> paste/deploy/loadwsgi.py", line 609, in config
> conf = AttrDict(self.global_conf)
> TypeError: iteration over non-sequence
>
> I suppose I am doing it in the wrong way. What is a correct way to
> load application's paste config?

Are you using filter-with? I've seen problems with that and appconfig,
but I haven't been able fit it yet. Using filter-app/next works, though.

--
Ian Bicking | ia...@colorstudy.com | http://blog.ianbicking.org
| Write code, do good | http://topp.openplans.org/careers

Max Ischenko

unread,
Apr 18, 2007, 12:30:05 AM4/18/07
to pylons-...@googlegroups.com
Hello Ian,

On 4/17/07, Ian Bicking wrote:
Max Ischenko wrote:
>   File "/home/max/projects/dou-trunk/site/doupy/doupy/websetup.py",
> line 54, in command
>     app_conf = appconfig('config:'+name, relative_to=conf_dir)
>   File "/usr/lib/python2.4/site-packages/PasteDeploy- 1.3-py2.4.egg/
> paste/deploy/loadwsgi.py", line 205, in appconfig
>     return context.config()
>   File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
> paste/deploy/loadwsgi.py", line 609, in config
>     conf = AttrDict(self.global_conf)
> TypeError: iteration over non-sequence
>
> I suppose I am doing it in the wrong way. What is a correct way to
> load application's paste config?

Are you using filter-with?  I've seen problems with that and appconfig,
but I haven't been able fit it yet.  Using filter-app/next works, though.

OK, i have rewritten it using pipeline: idiom. The TypeError is gone but the app_conf returned still shows only 7 DEFAULT entries and none of my application keys.

Here is my ini file:

[DEFAULT]
debug = true
email_to = y...@yourdomain.com
smtp_server = localhost
error_email_from = paste@localhost

[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 5000

[composite:main]
use = egg:Paste#urlmap
/ = thepipe

[pipeline:thepipe]
pipeline = proxy-prefix printdebug mainapp

[app:mainapp]
use = egg:doupy
cache_dir = %(here)s/data
# ....

[filter:printdebug]
use = egg:Paste#printdebug

[filter:proxy-prefix]
use = egg:PasteDeploy#prefix
prefix = /_pylons


Max.

Ian Bicking

unread,
Apr 18, 2007, 12:45:48 AM4/18/07
to pylons-...@googlegroups.com
Max Ischenko wrote:
> Hello Ian,

>
> On 4/17/07, *Ian Bicking* wrote:
>
> Max Ischenko wrote:
> > File "/home/max/projects/dou-trunk/site/doupy/doupy/websetup.py",
> > line 54, in command
> > app_conf = appconfig('config:'+name, relative_to=conf_dir)
> > File "/usr/lib/python2.4/site-packages/PasteDeploy- 1.3-py2.4.egg/
> > paste/deploy/loadwsgi.py", line 205, in appconfig
> > return context.config()
> > File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
> > paste/deploy/loadwsgi.py", line 609, in config
> > conf = AttrDict(self.global_conf)
> > TypeError: iteration over non-sequence
> >
> > I suppose I am doing it in the wrong way. What is a correct way to
> > load application's paste config?
>
> Are you using filter-with? I've seen problems with that and appconfig,
> but I haven't been able fit it yet. Using filter-app/next works,
> though.
>
>
> OK, i have rewritten it using pipeline: idiom. The TypeError is gone but
> the app_conf returned still shows only 7 DEFAULT entries and none of my
> application keys.

You'll have to point to your #mainapp configuration section; it can't
really figure out which of the sections represents the main application.
Hmm... it's kind of hard to do that generally, but I suppose it would
be possible if you weren't using any composite sections.

Anyway, what I'd really like to do instead of the setup-app stuff is
have paster just do an internal web request, and you'd write the setup
as a controller in your application (probably a controller class written
for this particular use case).

Max Ischenko

unread,
Apr 18, 2007, 12:55:54 AM4/18/07
to pylons-...@googlegroups.com
Hi,

On 4/18/07, Ian Bicking <ia...@colorstudy.com> wrote:
> OK, i have rewritten it using pipeline: idiom. The TypeError is gone but
> the app_conf returned still shows only 7 DEFAULT entries and none of my
> application keys.

You'll have to point to your #mainapp configuration section; it can't
really figure out which of the sections represents the main application.
  Hmm... it's kind of hard to do that generally, but I suppose it would
be possible if you weren't using any composite sections.

I see. For my project, I ditched  composite: (it was more of an experiment) and now it works just fine. The development.ini#mainapp also worked, btw.

Thanks for helping me out.

Anyway, what I'd really like to do instead of the setup-app stuff is
have paster just do an internal web request, and you'd write the setup
as a controller in your application (probably a controller class written
for this particular use case).

Clever, though I am not sure about if this buys you much. If you need to do web-based install/configuration you can just use normal controllers after initial setup (manual, setup-app or whatever).

Max.

Ian Bicking

unread,
Apr 18, 2007, 12:41:58 PM4/18/07
to pylons-...@googlegroups.com
Max Ischenko wrote:
> Anyway, what I'd really like to do instead of the setup-app stuff is
> have paster just do an internal web request, and you'd write the setup
> as a controller in your application (probably a controller class written
> for this particular use case).
>
>
> Clever, though I am not sure about if this buys you much. If you need to
> do web-based install/configuration you can just use normal controllers
> after initial setup (manual, setup-app or whatever).

It doesn't buy you much, but it's also not very hard to implement. I'm
more thinking about the conventions we should build up; preferably ones
that don't involve lots of new code. So this technique would lean
heavily on the existing infrastructure (config files, controllers, etc).

It could be used for initial setup as well, except for actually making a
blank configuration file. Running it from a script means that you could
run just one request as root, which is useful for setup.

I've thought also about a description of available management commands
too, located somewhere by convention. Say /.app-admin/description.xml,
looking like:

<management>
<url action="../setup" method="POST">
<a rel="tag" href="http://pythonpaste.org/actions/setup">setup</a>
<description>
Run to setup the application
</description>
</url>
<url action="../ping" method="GET">
<a rel="tag" href="http://pylonshq.com/actions/ping">ping</a>
<description>
Query this URL to see if the application is alive
</description>
</url>
<url action="../check" method="GET">
<description>
Runs a complete check on the installation (permissions, database,
etc).
</description>
</url>
<url action="../migrate-data" method="POST">
<description>
Run this to upgrade the data.
</description>
</url>
</management>

And I can imagine more standard operations than just these; some ad-hoc,
some tagged to indicate they have a specific meaning (that can be
consumed by automated tools). One could potentially aggregate these
descriptions from multiple applications (maybe just via XInclude) to
represent the administrative options available for a complete site.

Chris Shenton

unread,
Apr 19, 2007, 11:53:27 AM4/19/07
to pylons-...@googlegroups.com
Ian Bicking <ia...@colorstudy.com> writes:

> what I'd really like to do instead of the setup-app stuff is have
> paster just do an internal web request, and you'd write the setup as
> a controller in your application (probably a controller class
> written for this particular use case).

This sounds like it could be very helpful because it would allow
non-webapp portions of the overall application (e.g., asynchronous
data harvesting and conversion, incoming email processing...) to get
at the save config vars that the webapp used.

Shannon -jj Behrens

unread,
Apr 19, 2007, 4:25:11 PM4/19/07
to pylons-...@googlegroups.com
On 4/18/07, Ian Bicking <ia...@colorstudy.com> wrote:
>

(playfully)
Wait a minute! I came to Pylons to get *away from* XML situps!

;-)
-jj

--
http://jjinux.blogspot.com/

Max Ischenko

unread,
Apr 20, 2007, 12:07:30 AM4/20/07
to pylons-...@googlegroups.com
On 4/19/07, Shannon -jj Behrens <jji...@gmail.com> wrote:

(playfully)
Wait a minute!  I came to Pylons to get *away from* XML situps!

Don't be a child!

Don't you know that the World Spy International obliged everyone to convert their sources to a single format (XML-based) so that their 5-year XML training program won't be wasted (and they can't affort to learn all this obscure languages like Python).

Max.


Shannon -jj Behrens

unread,
May 8, 2007, 7:59:18 PM5/8/07
to pylons-...@googlegroups.com, Ian Bicking
On 4/17/07, Ian Bicking <ia...@colorstudy.com> wrote:
>
> Max Ischenko wrote:
> > File "/home/max/projects/dou-trunk/site/doupy/doupy/websetup.py",
> > line 54, in command
> > app_conf = appconfig('config:'+name, relative_to=conf_dir)
> > File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
> > paste/deploy/loadwsgi.py", line 205, in appconfig
> > return context.config()
> > File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/
> > paste/deploy/loadwsgi.py", line 609, in config
> > conf = AttrDict(self.global_conf)
> > TypeError: iteration over non-sequence
> >
> > I suppose I am doing it in the wrong way. What is a correct way to
> > load application's paste config?
>
> Are you using filter-with? I've seen problems with that and appconfig,
> but I haven't been able fit it yet. Using filter-app/next works, though.

Ugh, I just ran into this. I feel like a car hitting a brick wall ;)

I have the following at the bottom of my .ini:

filter-with = proxy-prefix

[filter:proxy-prefix]
use = egg:PasteDeploy#prefix

force_port =
prefix =

The app works just fine, but "paster setup-app" doesn't:

paster setup-app acctmgr-staging.ini
debugging: global_conf: None
Traceback (most recent call last):
File "/usr/bin/paster", line 5, in ?
pkg_resources.run_script('PasteScript==1.3.4', 'paster')
File "/usr/lib/python2.4/site-packages/setuptools-0.6c3-py2.4.egg/pkg_resources.py",
line 407, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.4/site-packages/setuptools-0.6c3-py2.4.egg/pkg_resources.py",
line 1084, in run_script
execfile(script_filename, namespace, namespace)
File "/usr/lib/python2.4/site-packages/PasteScript-1.3.4-py2.4.egg/EGG-INFO/scripts/paster",
line 18, in ?
command.run()
File "/usr/lib/python2.4/site-packages/PasteScript-1.3.4-py2.4.egg/paste/script/command.py",
line 76, in run
invoke(command, command_name, options, args[1:])
File "/usr/lib/python2.4/site-packages/PasteScript-1.3.4-py2.4.egg/paste/script/command.py",
line 115, in invoke
exit_code = runner.run(args)
File "/usr/lib/python2.4/site-packages/PasteScript-1.3.4-py2.4.egg/paste/script/appinstall.py",
line 65, in run
return super(AbstractInstallCommand, self).run(new_args)
File "/usr/lib/python2.4/site-packages/PasteScript-1.3.4-py2.4.egg/paste/script/command.py",
line 210, in run
result = self.command()
File "/usr/lib/python2.4/site-packages/PasteScript-1.3.4-py2.4.egg/paste/script/appinstall.py",
line 443, in command
conf = appconfig(config_spec, relative_to=os.getcwd())
File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/paste/deploy/loadwsgi.py",


line 205, in appconfig
return context.config()
File "/usr/lib/python2.4/site-packages/PasteDeploy-1.3-py2.4.egg/paste/deploy/loadwsgi.py",

line 610, in config


conf = AttrDict(self.global_conf)
TypeError: iteration over non-sequence

Best Regards,
-jj

--
http://jjinux.blogspot.com/

Max Ischenko

unread,
May 9, 2007, 8:33:24 AM5/9/07
to pylons-...@googlegroups.com
On 5/9/07, Shannon -jj Behrens <jji...@gmail.com> wrote:
> Are you using filter-with?  I've seen problems with that and appconfig,
> but I haven't been able fit it yet.  Using filter-app/next works, though.

Ugh, I just ran into this.  I feel like a car hitting a brick wall ;)

Hmm. I thought it is closer to a lab's rat. ;)

The app works just fine, but "paster setup-app" doesn't:

    conf = AttrDict( self.global_conf)
TypeError: iteration over non-sequence

Well, I ended up re-writing my development ini using pipeline idiom:

 
[pipeline:main]
pipeline = proxy-prefix printdebug app


[filter:printdebug]
use = egg:Paste#printdebug

[filter:proxy-prefix]
use = egg:PasteDeploy#prefix
prefix = /_pylons

[app:app]
use = egg:doupy
...

Max.


Reply all
Reply to author
Forward
0 new messages