[Tutor] where to put configuration files

Paul Tremblay phthenry@earthlink.net
Mon Jun 9 23:21:01 2003


On Mon, Jun 09, 2003 at 10:51:52AM -0700, Jeff Shannon wrote:
 
> 
> The wxWindows/wxPython cross-platform GUI library has a wxConfig class 
> which transparently handles storage in the appropriate place.  The 
> Python standard library has a ConfigParser module to assist in managing 
> configuration files, but it looks to have a lot less cross-platform 
> transparency than wxConfig (and doesn't look like it handles registry 
> information at all).  Still, you may want to investigate ConfigParser, 
> it might simplify your maintenance tasks.  (wxConfig will only simplify 
> things if you're already using the wxPython library.)  

Yes, I think I will have a look.

> 
> In general, I don't think you can do this safely cross-platform without 
> doing a check of what platform you're running on, and using a different 
> configuration back-end based on that.  However, if you're fairly 
> confident that your script will only be running on Unix, you're probably 
> fairly safe trying to write your config file somewhere into /etc 
> (probably in an application-specific subdirectory, i.e. 
> /etc/myapp/myapp.cfg).  Depending on the nature of the script, it might 
> also be a good idea to allow it to fall back on a config file in the 
> application's install directory (which might allow it to be installed in 
> the home directory of someone without root privelidges).  One way to 
> determine the install directory is to look at where your modules are 
> being imported from -- IIRC, modules have a __file__ attribute that will 
> give the path and filename that the module was loaded from.  It should 
> be fairly easy to extract the path and use that as a location for a 
> config file.

Sorry to be dense, but could you give me an example of using the
__file__ attribute? This would really sovle a lot of the problem. Most
applications (at least unix), have a .config file in the home directory.
(For example, .vimrc for vim.) 

The user will actually want to have easy access to the configuration
file. The directory /etc is for scary things like sendmail! 

Thanks

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************