Comment 44 for bug 1069019

Revision history for this message
Julian Andres Klode (juliank) wrote :

I believe we should fix this in software-properties. The most flexible way to do this is to use something like

if sys.getfilesystemencoding() == "ascii" and not "LANG" in os.environ:
    os.putenv("LANG", "C.UTF-8")
    with open("/etc/default/locale") as fobj:
        for line in fobj:
            line = line.split("#")[0].strip()
            if line:
                key, value = line.split("=", 1)
                os.putenv(key, value)

        os.execv(sys.argv[0], sys.argv)

before running other code in the dbus service. This will take care to setup the system's default locale settings and then re-exec() itself so that Python picks this up (it will not change filesystem encoding otherwise). In case no locale is set in /etc/default/locale, it falls back to LANG=C.UTF-8.

This can be changed to use systemd's localed later on (I do not know if it is currently installed), using:

 bus = dbus.SystemBus()
 localed = bus.get_object("org.freedesktop.locale1", "/org/freedesktop/locale1")
 loc = dbus.Interface(localed, 'org.freedesktop.locale1')
 props = dbus.Interface(localed, 'org.freedesktop.DBus.Properties')

 for locale in props.Get('org.freedesktop.locale1', 'Locale'):
  name, val = locale.split("=", 1)
  os.putenv(name, val)

to get the values instead of reading /etc/default/locale.