Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

If I want my application to store a few settings, that persist when an application closes, then where should I store them?

I'm not talking anything complicated: two booleans and a string (although in the future I might want to store more complex settings)

I've heard gconf, dconf, gsettings, etc all mentioned. What is the "preferred" method? Preferably one that's nice and easy in Python.

share|improve this question
    
Related :askubuntu.com/questions/42438/… –  Tachyons Oct 5 '12 at 15:00

3 Answers 3

up vote 6 down vote accepted

gconf is deprecated, so for a new project I would not use it. dconf is a backend for storing the settings, as an application developer you should normally not have to bother with it.

What you seem to need is gsettings, a high-level API (API documentation for C) to store/retrieve settings without bothering how/where they are actually stored. gsettings is part of gio, which is one of the core packages of gnome (like glib and gobject). This blog post gives a short introduction how to use it with Python.

If you do not want any dependencies on gio (e.g. you are not developing a GNOME application) and want to store simple config files, I'd suggest to use the $HOME/.config directory (or whatever directory defined by $XDG_CONFIG_DIRS) instead of $HOME/.your_appname, in line with the freedesktop spec.

share|improve this answer

Application runs system wide

the appropriate place to store settings would be:

/etc/[application]/

where a subdirectory is optional.


Application runs in a per user mode

settings should be stored in the user HOME, preferably in a hidden directory:

/home/<user>/<.application>/

See also the Debian FHS.


Applications running in X-Desktop

Applications for the X-Desktop (e.g. GNOME, KDE, Unity, Xfce) should refer to the XDG Base Directory Specification where the following file locations are defined in local variables:

  • $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

  • $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

  • $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be seperated with a colon ':'.

  • If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.

  • $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory. The directories in $XDG_CONFIG_DIRS should be seperated with a colon ':'. If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used.

share|improve this answer
    
No, they should be in /home/<user>/.config/application/ –  Anonymous Oct 28 '11 at 10:02
    
@Anonymous: It would be cool to have a reference for this. Present Debian policy requires FHS 2.3 with the exception that applications are recommended to store user settings in a dot file (or directory) in user's HOME. –  Takkat Oct 28 '11 at 11:05

Quickly, which is is one of the newer helpers for application development for Ubuntu, defaults to storing all preferences with desktopcouch. The advantage is that those settings can be synchronized with other installations via the Ubuntu One tools.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.