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

Revision 25358, 4.9 KB checked in by jdreed, 13 years ago (diff)
In gdm-config: * Only display the nologin-monitor window on startup if the file exists AND this is -cluster * Include a timestamp in the window
  • 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
13import time
14from optparse import OptionParser
15
16SM_DBUS_NAME = "org.gnome.SessionManager"
17SM_DBUS_PATH = "/org/gnome/SessionManager"
18SM_DBUS_INTERFACE = "org.gnome.SessionManager"
19SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate"
20APP_ID = "debathena-nologin-monitor"
21
22class GDMSucks:
23    def __init__(self, options):
24        self.debug = options.debug
25        self.guitest = options.guitest
26        self.sessionEnding = False
27        self.sessionBus = dbus.SessionBus()
28        try:
29            self.register_with_sm()
30            self.init_sm_client()
31        except:
32            print "Warning: Cannot register with session manager."
33       
34        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
35        self.window.set_property('can-focus', False)
36        box = gtk.VBox()
37        self.label = gtk.Label()
38        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.\n\n</span>(Update started at %s)' % (time.strftime("%Y-%m-%d %H:%M")))
39        self.label.set_property('can-focus', False)
40        self.label.set_justify(gtk.JUSTIFY_CENTER)
41        box.pack_start(self.label, True, True, 5)
42        self.window.add(box)
43        self.window.set_size_request(800, 600)
44        self.window.set_decorated(False)
45        self.window.set_position(gtk.WIN_POS_CENTER)
46        self.window.hide()
47        if self.guitest:
48            self.window.show_all()
49        try:
50            metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip()
51        except OSError:
52            # Assume cluster
53            metapackage = 'debathena-cluster'
54        if (self.debug or metapackage == 'debathena-cluster') and os.path.isfile("/var/run/athena-nologin"):
55            self.window.show_all()
56        if self.debug or metapackage == 'debathena-cluster':
57            self.gfile = gio.File("/var/run/athena-nologin")
58            self.monitor = self.gfile.monitor_file(gio.FILE_MONITOR_NONE, None)
59            self.monitor.connect("changed", self.directory_changed)
60
61    def directory_changed(self, monitor, file1, file2, evt_type):
62        if self.debug:
63            print str(evt_type), file1.get_path()
64        if evt_type == gio.FILE_MONITOR_EVENT_CREATED:
65            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.\n\n</span>(Update started at %s)' % (time.strftime("%Y-%m-%d %H:%M")))
66            self.window.show_all()
67        if evt_type == gio.FILE_MONITOR_EVENT_DELETED:
68            self.window.hide()
69
70   # Connect to the session manager, and register our client.
71    def register_with_sm(self):
72        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
73        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
74        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
75        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
76
77    # Set up to handle signals from the session manager.
78    def init_sm_client(self):
79        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
80        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
81        self.smClient.connect_to_signal("QueryEndSession",
82                                         self.sm_on_QueryEndSession)
83        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
84        self.smClient.connect_to_signal("CancelEndSession",
85                                         self.sm_on_CancelEndSession)
86        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
87
88     # Here on a QueryEndSession signal from the session manager.
89    def sm_on_QueryEndSession(self, flags):
90        self.sessionEnding = True
91        # Response args: is_ok, reason.
92        self.smClient.EndSessionResponse(True, "")
93
94    # Here on an EndSession signal from the session manager.
95    def sm_on_EndSession(self, flags):
96        self.sessionEnding = True
97        # Response args: is_ok, reason.
98        self.smClient.EndSessionResponse(True, "")
99
100    # Here on a CancelEndSession signal from the session manager.
101    def sm_on_CancelEndSession(self):
102        self.sessionEnding = False
103
104    # Here on a Stop signal from the session manager.
105    def sm_on_Stop(self):
106        gtk.main_quit()
107
108def main(options):
109    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
110    GDMSucks(options)
111    gtk.main()
112
113if __name__ == '__main__':
114    parser = OptionParser()
115    parser.set_defaults(debug=False, guitest=False)
116    parser.add_option("--test", action="store_true", dest="debug")
117    parser.add_option("--test-gui", action="store_true", dest="guitest")
118    (options, args) = parser.parse_args()
119    main(options)
Note: See TracBrowser for help on using the repository browser.