summaryrefslogtreecommitdiff
path: root/src/test-open-session-with-parameters
blob: ce622ce5d734688ac07fc56a8e4ca1858f197511 (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
53
54
#!/usr/bin/env python
#
# Test opening a new session
#

import os
import gobject
import dbus
import dbus.glib

bus = dbus.SystemBus ()

manager_obj = bus.get_object ('org.freedesktop.ConsoleKit', '/org/freedesktop/ConsoleKit/Manager')

manager = dbus.Interface (manager_obj, 'org.freedesktop.ConsoleKit.Manager')

params = dbus.Array ([], signature = "sv")
params.append (("unix-user", dbus.Variant (730)))
params.append (("session-type", dbus.Variant ("gnome-session")))
#params.append (("x11-display", dbus.Variant (":0.0")))
params.append (("display-device", dbus.Variant ("/dev/tty8")))
params.append (("is-local", dbus.Variant (True)))
params.append (("bogus-property", dbus.Variant ("Something bogus")))
params.append (("cookie", dbus.Variant ("This should be ignored")))
params.append (("id", dbus.Variant ("This should be ignored too")))

cookie = manager.OpenSessionWithParameters (params)
os.environ['XDG_SESSION_COOKIE'] = cookie
print "Got cookie: %s" % cookie

seats = manager.GetSeats ()
for sid in seats:
    seat_obj = bus.get_object ('org.freedesktop.ConsoleKit', sid)
    seat = dbus.Interface (seat_obj, 'org.freedesktop.ConsoleKit.Seat')
    sessions = seat.GetSessions ()
    for ssid in sessions:
            session_obj = bus.get_object ('org.freedesktop.ConsoleKit', ssid)
            session = dbus.Interface (session_obj, 'org.freedesktop.ConsoleKit.Session')
            uid = session.GetUser ()

# Hmm looks like the proc environment doesn't get updated when
# os.environ is set.  So, we won't use GetCurrentSession.
#current_session = manager.GetCurrentSession ()
current_session = manager.GetSessionForCookie (cookie)
print "Current session: %s" % current_session

session_obj = bus.get_object ('org.freedesktop.ConsoleKit', ssid)
session = dbus.Interface (session_obj, 'org.freedesktop.ConsoleKit.Session')

mainloop = gobject.MainLoop ()

gobject.timeout_add (30000, mainloop.quit)

mainloop.run()