Advice on distutils and distribution policies

M

Mardy

Hi,
I've built a small project (http://eligante.sf.net) which I'm actually
trying to package using distutils.
The directory structure is going to be like this:

eligante/
eligante.py
sitobase.py
personas.py
[...other python files...]
modulos/
mbox.py
gaim.py
[...other python files...]
web/
indice.py
cerca.py
[...other python files...]
stylo.css
testata.html
[and maybe, in the future, other HTML files]

The python files in the eligante/web directory are intended to be called
by a webserver (now Apache, but soon I'll switch to the python
module CGIHTTPServer for simplicity) as CGIs. Currently, these CGIs read
the testata.html file and use it as the beginning of their output, while
the style.css is served by the HTTP server.

However, I don't know if this directory layout is suitable for
site-packages, since at a first glance it looks to me that datafiles might
not be welcome under it. Is it so?
In that case, where should I move the .html files, and how should I access
them from inside python?

If, on the other hand, this layout is OK for site-packages, how do I
instruct distutils to put the .html and .css files under the eligante/web
directory?

Sorry for the long post, and thanks in advance for any help or suggestion.
 
M

Magnus Lycka

Mardy said:
Hi,
I've built a small project (http://eligante.sf.net) which I'm actually
trying to package using distutils. ....
However, I don't know if this directory layout is suitable for
site-packages, since at a first glance it looks to me that datafiles might
not be welcome under it. Is it so?

In general, it's a good idea to keep code and data separated:

- Different people might need to access code and data. People who
add content to a web site shouldn't be able to make a mess of the
software that controls that web site (or vice versa).
- Lifecycles are different, so different backup strategies might apply.
- Directory structures such as /usr under unix are typically fairly
static on production systems, and there might be assumptions that
required space doesn't grow over time, whereas data, kept under
/var is expected to change more over time. Also, if e.g. web content
is kept in a separate disk partition, filling that partition won't
mess up other parts of the computer system.
- It should be easy to upgrade the software without messing up data.
It's practical if it's safe to e.g. do
"rm -rf /usr/lib/python2.3/site-packages/eligante" followed by
a new "python setup.py install" in case a sys admin thinks that
his old install was broken.

For a CGI-based app on e.g. a linux box with Apache, I think it would
be typical to partition things like this:

In an apache cgi-bin directory: The main Python CGI script(s) that
are called by the web server. These might be scripts that are modified
as a part of the installation process to e.g. point out data files.
These should be short files. Import a module, set up configuration
and run something in the imported module.

Under /usr/lib/python2.x/site-packages/ you keep the bulk of your
software (as described above).

HTML and CSS files that are to be handled directly by the web browser
is placed under Apache's DOCUMENT_ROOT etc. E.g.
$DOCUMENT_ROOT/eligante.

Data files that are read and processed by you own programs (i.e. not
directly by the web server) van be anywhere under /var, e.g.
/var/eligante.

In that case, where should I move the .html files, and how should I access
them from inside python?

Asolute path defined by an environment variable?

I think Apache defines a DOCUMENT_ROOT variable. You
could decide that your HTML files etc should reside in
some particular place relative to DOCUMENT_ROOT, and
use something like...

import os
SUB_FOLDER = 'my_folder'
dir = os.path.join(os.environ['DOCUMENT_ROOT'],SUB_FOLDER)

....to locate your files.

As I wrote above, hardcoding in a main CGI-script is also
common practice.
 
M

Mardy

Hi Magnus,
thanks a lot for your posting, you made me clear several things.
However, there something I still want to discuss:

Le die Mon, 21 Nov 2005 20:08:24 +0100, Magnus Lycka ha scribite:
[...]
In an apache cgi-bin directory: The main Python CGI script(s) that are
called by the web server. These might be scripts that are modified as a
part of the installation process to e.g. point out data files. These
should be short files. Import a module, set up configuration and run
something in the imported module.

Good point!
Under /usr/lib/python2.x/site-packages/ you keep the bulk of your
software (as described above).

HTML and CSS files that are to be handled directly by the web browser is
placed under Apache's DOCUMENT_ROOT etc. E.g. $DOCUMENT_ROOT/eligante.

Actually, for the moment, this is just the CSS file.
Data files that are read and processed by you own programs (i.e. not
directly by the web server) van be anywhere under /var, e.g.
/var/eligante.

And this is the HTML one (which is a template that is used by the python
scripts).
The number of HTML might even grow in the future, but it's extremely
unlikely they'll be ever more than 5.

I'm even thinking of including the HTML in a python file, that will save
me the trouble of storing it elsewhere.
The other files accessed by the webserver will be the CSS and eventually
some images (and the favicon). For these I'll follow your advice of
storing them under DOCUMENT_ROOT.
This variable, though, seems to be defined only in the processes spawned
by the webserver; so my guess is that I'll have to instruct the setup.py
script to ask the user where his webserver's document root is (either
interactively, or from the command line when invoking the setup script).
I guess this involves subclassing some Distutils class, does anyone have a
starter for this?
Thanks again for your help,
Alberto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top