[Pythonmac-SIG] Where to put data

Chris Barker Chris.Barker at noaa.gov
Tue Dec 21 18:05:38 CET 2004


Charles Hartman wrote:
> With an earlier app I wanted an external data file and everybody told me 
> to make it internal to the program (the app's Resources, I guess) 
> instead. I couldn't, then. Now with a new app I want to do just that, 
> but I'm not sure *how* to do it!
> 
> It's a file of data -- a Python dictionary object, after it's loaded 
> into memory -- which will grow and change as the app is used; when the 
> app terminates the data ought to be saved  with it for next time. In 
> this case I don't want users fiddling with it apart from the app.

Just a few thoughts. All these systems are multi-user systems, though 
Linux is the only one that really enforces that behavior in common use. 
OS-X is second, and Windows is alarmingly sloppy.

What this means is that, in general, an application will be installed to 
a system location, and can be run by multiple users. In this case, a 
distinction needs to be made between user data and configuration, and 
system data and configuration. Most Unix software has both, and the 
usual behavior is to load the system data, then load the users data, 
perhaps overriding the system data in various ways.

The system data is stored in a system location, and can only be changed 
by the super user. The location of the system data on Linux is usually 
in /etc/ or somewhere in either /usr or /usr/local (depending on how 
it's installed)  often in /usr/share or /usr/local/share. Take a look at 
the Linux File system Hierarchy Standard for a description of what to 
put in share vs lib, vs whatever. In general, what seems like an overly 
complicated system is designed to accommodate things like networked file 
systems and heterogeneous networks. If  you don't need all that, you can 
also just put your data into /usr/local/MyApp.

User data is generally stored in $HOME/.MyApp

On OS-X, there is /Library/MyApp and $HOME/Library/MyApp for system and 
user data. You also might want to put system data in the Application 
Bundle, but that won't work for user data, as the user can't change an 
Application bundle that's installed in the system (at least I hope they 
can't!)

I think if you use the wxConfig system, you'll get the appropriate 
behavior for user data on all systems, at least for config files.

At the app level, everywhere inside your app, you can have a set of 
application-level variables that store something like:

UserDataDir
SystemDataDir

etc.

At startup, you'll need to set these, and that may well require platform 
specific code. One way to do this on Linux (that I've used) is to have a 
default hard coded (say /usr/local/MyApp/DataDir). I also have the app 
look for an environment variable, if it's set, then I use that for the 
DataDir, if not, I use the default. That way, you can deliver a start-up 
script that sets the appropriate variable, and then starts your app. All 
your users (or your installer program) have to do is customize the 
start-up script if they want to install in a non-standard location.

Well, I got a little long winded, but I hope there was something helpful 
here.

-Chris














-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Pythonmac-SIG mailing list