tags:

views:

155

answers:

1

Is there a standard way of accessing Gnome configuration information (i.e. ~/.gconf) using Python?

Updated: please provide a short example.

+2  A: 

Python GConf, also check out packages like python-gconf and/or gnome-python-gconf in your distros package repo:

/usr/share/doc/python-gconf/examples/

Or browse the svn at http://svn.gnome.org/viewvc/gnome-python/trunk/examples/gconf/ for the examples.

On Fedora12 (my distro) it is called gnome-python2-gconf-2.28.0-1.fc12.x86_64.rpm, but it may be in a generic gnome-python2 package.

An example of GConf key editing (background wallpaper) in Python:

#! /usr/bin/python

import gtk
import gtk.glade
import gconf

class GConfExample:
    def __init__(self):
        self.client = gconf.client_get_default()

    def get_key(self, key):
        return client.get_string(key)

    def set_key(self, key, val):
        client.set_string(key, str(val))

Found http://therning.org/magnus/archives/57 , and I trimmed out the GTK stuff. Of course, this would make some good getitem and setitem usage to map for example:

mygconf['/path/to/key'];

Also some good information here about using the API. Of course, my example is poor, but illustrates the simplicity of the API. Here are more methods:

foo = self.gconf_client.get_string("/path/to/my/config/data/foo")
bar = self.gconf_client.get_int("/path/to/my/config/data/bar")
baz = self.gconf_client.get_bool("/path/to/my/config/data/baz")

And each get_* has an equivalent setter set_* in most cases.

Aiden Bell
........... thanks!
jldupont