[Tutor] where to put data files

Erik Price erikprice@mac.com
Fri Feb 14 07:27:01 2003


On Friday, February 14, 2003, at 01:05  AM, Paul Tremblay wrote:

> But how do I do this? The line that will look for the character file
> will be in the actual script. When the user installs the modules,
> script, and data file, the installer will somewhow have to read the 
> path
> and change a line in the main script.
>
> In other words, if the user chooses /opt/program, the script will be 
> put
> in /opt/program/bin, the modules will be put in
> /opt/program/lib/python2.x/site-packages/rtf2xml/*, and the data file
> will be put in /opt/program/rtf_data/rtf_char_set.
>
> In one of the modules:
>
> read_obj = open(path_to_char_set)
> ## now read each line in and form a hash
>
> How do I insure that path will always find the actual charater file?

Sometimes people distribute a "meta-script" with their programs which 
assists with the installation process.  It is usually a very simple 
script called "configure" and the user can pass arguments like this:

     $ ./configure --target=/opt/program [followed by add'l args as 
necessary]

What the configure script does is entirely dependent on how it was 
written, but often it will write the user's input to a properties file 
of some sort.  This properties file is then consulted by the build tool 
(such as make or ant) to rewrite the constants representing paths and 
other configurable information, so that when the program is compiled, 
it "knows" where it is.  In other words, the point of the configure 
script is to rewrite some of the source code to customize it for the 
user's environment.

You could do something similar even though Python doesn't use a build 
tool, and in fact, perhaps someone already has.  You can write a very 
simple "installer" script that accepts a few arguments to determine 
where the user wants to put the file, and then the installer can copy 
the files to the locations you specify in the script.  The "installer" 
script can also re-write the file paths so that the script will work 
from wherever it is placed.  Hint:  this will be a lot easier to do if 
you keep the file paths and other information in a submodule file (say, 
one called "rtf2xml.constants").

I'm sure that there are other people with more experience distributing 
software on this list who can come up with some other ideas.


Erik




-- 
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org