List Info

Thread: Reusing an app in another app




Reusing an app in another app
user name
2006-02-10 23:02:18
On Feb 9, 2006, at 6:44 PM, huydo wrote:

> I have a catwalk like application (written in pylons) I
would like to
> reuse in my other pylons apps ? what is the recommended
way to do this
> taking in mind that I need to configure the   model for
each
> application I use it in.

To pass the model config in, its best to use a config pair
in your  
config file, and use it in your application setup. Any
configuration  
for your [app:section] in the config file comes into the
config/ 
middleware.py as a keyword arg. As an example, in the
PylonsHQ site,  
since I knew the docs directory might change that was going
to be  
used, I provided an option in the config file for 'doc_dir',
then  
used it in the middleware file:
http://pylonshq.com/project/pylonshq/browser/pylonsh
q/trunk/ 
development.ini
http://pylonshq.com/project/pylonshq/browse
r/pylonshq/trunk/pylonshq/ 
config/middleware.py

The 'doc_dir' comes right into the middleware make_app
function.  
Alternatively, if you need to get to a configuration option
somewhere  
else, the entire dict of conf options is available during
run-time  
from paste, like so:
from paste.deploy.config import CONFIG
app_conf = CONFIG.current_conf()['app']

This is how the SQLObject database.py file that Pylons comes
with  
automatically picks out the sqlobject.dburi option from the
config file.

> At the moment I am running it as a separate server and
i configure the
> model appropriately depending on which model I want to
edit but I  
> would
> like tighter integration because of authorization, css
and all that
> stuff.

Using the config file, or mounting the other Pylons app
within the  
main one sort of does what you want. You can unify
authentication if  
its done in the middleware, or config file, the css stuff is
a little  
trickier. I'm going through right now trying some different
methods  
for a good solution and will get back shortly on this aspect
with  
more details.

Cheers,
Ben
Reusing an app in another app
user name
2006-02-11 00:21:33
Ben Bangert wrote:
>
> On Feb 9, 2006, at 6:44 PM, huydo wrote:
>
>> I have a catwalk like application (written in
pylons) I would like to
>> reuse in my other pylons apps ? what is the
recommended way to do this
>> taking in mind that I need to configure the   model
for each
>> application I use it in.
>
> To pass the model config in, its best to use a config
pair in your 
> config file, and use it in your application setup. Any
configuration 
> for your [app:section] in the config file comes into
the 
> config/middleware.py as a keyword arg. As an example,
in the PylonsHQ 
> site, since I knew the docs directory might change that
was going to 
> be used, I provided an option in the config file for
'doc_dir', then 
> used it in the middleware file:
> http://pylonshq.com/project/pylonshq/
browser/pylonshq/trunk/development.ini 
>
> http://pylonshq.com/pro
ject/pylonshq/browser/pylonshq/trunk/pylonshq/config/middlew
are.py 
>
>
> The 'doc_dir' comes right into the middleware make_app
function. 
> Alternatively, if you need to get to a configuration
option somewhere 
> else, the entire dict of conf options is available
during run-time 
> from paste, like so:
> from paste.deploy.config import CONFIG
> app_conf = CONFIG.current_conf()['app']
>
Thanks ben. Looking at your hella project, I saw this and am
using the 
config like this.
> This is how the SQLObject database.py file that Pylons
comes with 
> automatically picks out the sqlobject.dburi option from
the config file.
>
>> At the moment I am running it as a separate server
and i configure the
>> model appropriately depending on which model I want
to edit but I would
>> like tighter integration because of authorization,
css and all that
>> stuff.
>
> Using the config file, or mounting the other Pylons app
within the 
> main one sort of does what you want. You can unify
authentication if 
> its done in the middleware, or config file, the css
stuff is a little 
> trickier. I'm going through right now trying some
different methods 
> for a good solution and will get back shortly on this
aspect with more 
> details.
>

I guess this is where I am a bit confused, probably because
I am so 
unfamiliarly with paste.

Given two projects

/project1/development.ini
/project1/project1......

/project2/development.ini
/project2/project2

how do i mount project1 inside project2 ? Sorry if this is
OT and I'll 
accept a "go RTM" if you would just point me to
which manual would be 
relevant.

thanks

Huy
> Cheers,
> Ben

Reusing an app in another app
user name
2006-02-14 00:03:39
Huy Do wrote:
 Given two projects
>
> /project1/development.ini
> /project1/project1......
>
> /project2/development.ini
> /project2/project2
>
> how do i mount project1 inside project2 ? Sorry if this
is OT and I'll
> accept a "go RTM" if you would just point
me to which manual would be
> relevant.

There's two different approaches, the second of which
won't be
available until the latest branch is merged. The first,
which you can
use right now, is to use Paste to composit the applications.
You can
then "mount" the applications at various URL's
under your webapp.

Given two projects named like above, you would create a
development.ini
file like this:

[DEFAULT]
debug = true
email_to = youyourdomain.com
smtp_server = localhost
error_email_from = pasteexceptions.com

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

[composit:main]
use = egg:Paste#urlmap
/ = app1
/app2 = app2

[app:app1]
use = egg:app1
cache_dir = /cache/app1

[app:app2]
use = egg:app2
cache_dir = /cache/app2


Please note you will need to be using the latest Pylons from
svn, as I
noticed the WSGIHandler was being created improperly which
would affect
multiple Pylons apps in the same process.

More docs on compositing apps through the config file are
here:
http://pythonpaste.org/deploy/#composite-applications

I will also be putting up detailed documentation on how to
use
applications together on the website in the coming week
which will
detail using application composition to share session data,
login data,
etc.

HTH,
Ben

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )