summaryrefslogtreecommitdiff
path: root/gnome-base/gdm/files/gdm-set-session
blob: 491b9a6787f3e53591d9cb62529b46a6572f2679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
"""Simple script that updates the default session in AccountServices"""

import sys
import time

from gi.repository import GLib as glib

import dbus
from dbus.mainloop.glib import DBusGMainLoop

ACCOUNTS_DBUS_NAME = "org.freedesktop.Accounts"
ACCOUNTS_DBUS_PATH = "/org/freedesktop/Accounts"
ACCOUNTS_USER_DBUS_NAME = "org.freedesktop.Accounts.User"

if __name__ == "__main__":

    try:
        username = sys.argv[1]
        session = sys.argv[2]
    except IndexError:
        sys.stderr.write("%s <username> <default session>\n")
        raise SystemExit(1)

    dbus_loop = DBusGMainLoop(set_as_default = True)
    loop = glib.MainLoop()
    glib.threads_init()

    def setup():
        try:
            system_bus = dbus.SystemBus(mainloop=dbus_loop)
            dbus_object = system_bus.get_object(
                ACCOUNTS_DBUS_NAME, ACCOUNTS_DBUS_PATH)

            iface = dbus.Interface(
                dbus_object, dbus_interface=ACCOUNTS_DBUS_NAME)

            user_path = iface.FindUserByName(username)

            dbus_object = system_bus.get_object(
                ACCOUNTS_DBUS_NAME, user_path)

            iface_usr = dbus.Interface(
                dbus_object, dbus_interface=ACCOUNTS_USER_DBUS_NAME)

            iface_usr.SetXSession(session)

        finally:
            loop.quit()

    glib.timeout_add(0, setup)
    loop.run()