source: trunk/debathena/config/gdm-config/debian/debathena-nologin-monitor @ 25001

Revision 25001, 4.4 KB checked in by jdreed, 13 years ago (diff)
Remove test code, and add options to ensure this doesn't happen again
  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2#
3# An applet to monitor /etc/nologin
4
5import gio
6import dbus
7import dbus.mainloop.glib
8import gtk
9import gobject
10import sys
11import os
12import subprocess
13from optparse import OptionParser
14
15SM_DBUS_NAME = "org.gnome.SessionManager"
16SM_DBUS_PATH = "/org/gnome/SessionManager"
17SM_DBUS_INTERFACE = "org.gnome.SessionManager"
18SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate"
19APP_ID = "debathena-nologin-monitor"
20
21class GDMSucks:
22    def __init__(self, options):
23        self.debug = options.debug
24        self.guitest = options.guitest
25        self.sessionEnding = False
26        self.sessionBus = dbus.SessionBus()
27        try:
28            self.register_with_sm()
29            self.init_sm_client()
30        except:
31            print "Warning: Cannot register with session manager."
32       
33        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
34        self.window.set_property('can-focus', False)
35        box = gtk.VBox()
36        self.label = gtk.Label()
37        self.label.set_markup('<span font_desc="Sans Bold 24">Software updates are being applied.\n\nThis workstation is temporarily unavailable.\n\nPlease use another workstation.</span>')
38        self.label.set_property('can-focus', False)
39        self.label.set_justify(gtk.JUSTIFY_CENTER)
40        box.pack_start(self.label, True, True, 5)
41        self.window.add(box)
42        self.window.set_size_request(800, 600)
43        self.window.set_decorated(False)
44        self.window.set_position(gtk.WIN_POS_CENTER)
45        self.window.hide()
46        if self.guitest:
47            self.window.show_all()
48        try:
49            metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip()
50        except OSError:
51            # Assume cluster
52            metapackage = 'debathena-cluster'
53        if self.debug or metapackage == 'debathena-cluster':
54            self.gfile = gio.File("/var/run/athena-nologin")
55            self.monitor = self.gfile.monitor_file(gio.FILE_MONITOR_NONE, None)
56            self.monitor.connect("changed", self.directory_changed)
57
58    def directory_changed(self, monitor, file1, file2, evt_type):
59        if self.debug:
60            print str(evt_type), file1.get_path()
61        if evt_type == gio.FILE_MONITOR_EVENT_CREATED:
62            self.window.show_all()
63        if evt_type == gio.FILE_MONITOR_EVENT_DELETED:
64            self.window.hide()
65
66   # Connect to the session manager, and register our client.
67    def register_with_sm(self):
68        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
69        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
70        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
71        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
72
73    # Set up to handle signals from the session manager.
74    def init_sm_client(self):
75        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
76        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
77        self.smClient.connect_to_signal("QueryEndSession",
78                                         self.sm_on_QueryEndSession)
79        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
80        self.smClient.connect_to_signal("CancelEndSession",
81                                         self.sm_on_CancelEndSession)
82        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
83
84     # Here on a QueryEndSession signal from the session manager.
85    def sm_on_QueryEndSession(self, flags):
86        self.sessionEnding = True
87        # Response args: is_ok, reason.
88        self.smClient.EndSessionResponse(True, "")
89
90    # Here on an EndSession signal from the session manager.
91    def sm_on_EndSession(self, flags):
92        self.sessionEnding = True
93        # Response args: is_ok, reason.
94        self.smClient.EndSessionResponse(True, "")
95
96    # Here on a CancelEndSession signal from the session manager.
97    def sm_on_CancelEndSession(self):
98        self.sessionEnding = False
99
100    # Here on a Stop signal from the session manager.
101    def sm_on_Stop(self):
102        gtk.main_quit()
103
104def main(options):
105    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
106    GDMSucks(options)
107    gtk.main()
108
109if __name__ == '__main__':
110    parser = OptionParser()
111    parser.set_defaults(debug=False, guitest=False)
112    parser.add_option("--test", action="store_true", dest="debug")
113    parser.add_option("--test-gui", action="store_true", dest="guitest")
114    (options, args) = parser.parse_args()
115    main(options)
Note: See TracBrowser for help on using the repository browser.