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.
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 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.
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).
> 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).
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.
> 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.
(playfully)
Wait a minute! I came to Pylons to get *away from* XML situps!
;-)
-jj
(playfully)
Wait a minute! I came to Pylons to get *away from* XML situps!
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
> 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 ;)
The app works just fine, but "paster setup-app" doesn't:
conf = AttrDict( self.global_conf)
TypeError: iteration over non-sequence