Where should settings files be stored?
I'm writing an application in python (using wxPython for the gui) and I'm looking for a platform independent way to decide where to store application settings files. On linux systems, where is it customary to store application settings files? How about on Mac, and Windows (all modern versions)?
Ideally I'd like to have a module that provides a platform agnostic interface to locate these files. Does something like this already 开发者_StackOverflow社区exist?
wxPython has your back. You want wx.StandardPaths. There's a good example included with the wxPython demo.
There is a standard for this by freedesktop.org that you may find useful:
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
On linux, there's really not a standard way. A lot of programs, especially newer python programs I've seen, use ~/.config/appname/
. Of course the older ones like bash, vi, etc just add a hidden file in ~/
. It depends, what kind of settings are these?
Those are obviously user run programs. System programs generally store their config files somewhere in /etc/
Edit:
~/.config/appname/
seems to be more standard than I thought.
~ $ ll config total 84K drwxr-xr-x 2 falmarri 4.0K 2010-12-17 09:48 akonadi/ drwxr-xr-x 2 falmarri 4.0K 2010-12-04 15:48 autokey/ drwxr-xr-x 2 falmarri 4.0K 2010-11-06 01:45 autostart/ drwx------ 2 falmarri 4.0K 2010-11-23 22:32 enchant/ drwxr-xr-x 2 falmarri 4.0K 2010-11-25 21:13 FreeCAD/ drwx------ 2 falmarri 4.0K 2010-12-21 09:16 gtk-2.0/ drwx------ 3 falmarri 4.0K 2010-12-11 13:43 ibus/ drwxr-xr-x 2 falmarri 4.0K 2010-11-06 02:20 kde.org/ drwxr-xr-x 2 falmarri 4.0K 2010-11-06 02:46 qtcurve/ drwxr-xr-x 2 falmarri 4.0K 2010-11-17 13:49 Trolltech/ drwxr-xr-x 2 falmarri 4.0K 2010-11-17 23:29 vlc/ -rw-r--r-- 1 falmarri 31K 2010-12-21 20:51 Trolltech.conf -rw------- 1 falmarri 632 2010-11-06 01:40 user-dirs.dirs -rw-r--r-- 1 falmarri 5 2010-11-06 01:40 user-dirs.locale
精彩评论