How can I find out if a GSettings schema exists or not before trying to use it?

If the GSettings schema exists and has been compiled, there is usually no problem reading it. However, if it does not exist, an error usually occurs that cannot be processed. Try this in a Python file or console:

from gi.repository import Gio try: settings = Gio.Settings("com.example.doesnotexist") except: print "Couldn't load those settings!" 

I get as wide as possible with except , but this is the error that occurs.

(process: 10248): GLib-GIO-ERROR **: configuration scheme com.example.doesnotexist not installed

Basically I want to find out if the com.example.doesnotexist schema com.example.doesnotexist or not; if not, then ask the user to run my installation script before using my application. Any other suggestions on this subject are welcome.

+6
source share
1 answer

You can use GSettingsSchemaSource . For instance:

 > from gi.repository import Gio > source = Gio.SettingsSchemaSource.get_default() > source.lookup("org.gnome.Epiphany", True) <GSettingsSchema at 0xa462800> > source.lookup("com.example.doesnotexist", True) > 

According to the documentation, the lookup should return NULL ( None ) if the schema does not exist, but NoneType is returned in PyGObject. In any case, you can use it to check for the presence or absence of a circuit.

+4
source

All Articles