Skip to content

Instantly share code, notes, and snippets.

@backerman
Created November 23, 2011 20:57
Show Gist options
  • Save backerman/1389894 to your computer and use it in GitHub Desktop.
Save backerman/1389894 to your computer and use it in GitHub Desktop.
Display extra info on login screen
#!/usr/bin/python
import gtkhtml2
import gtk
import sys
import os
import atexit
import socket
from jinja2 import Template
def write_pid():
filename="/var/run/login_info_{0}.pid".format(os.environ["DISPLAY"])
pid = str(os.getpid())
try:
file(filename,'w+').write("{0}\n".format(pid))
atexit.register(remove_pid, filename)
except:
print "Unable to create PID file", filename
def remove_pid(filename):
try:
os.remove(filename)
except:
print "Failed to remove", filename
def render(html):
"""
Render the provided template, returning ready-to-display HTML.
"""
template = Template(html)
return template.render({
"hostname": socket.gethostname(),
"ip_address": socket.gethostbyname(socket.gethostname()),
"kernel_version": os.uname()[2]})
def display(src="/var/lib/gdm/information.html"):
doc = gtkhtml2.Document()
doc.clear()
try:
f = open(src, "r")
except OSError:
print "failed to open"
exit
rendered_html = render(f.read())
f.close()
doc.open_stream(u'text/html')
doc.write_stream(rendered_html)
doc.close_stream()
view = gtkhtml2.View()
view.set_document(doc)
window = gtk.Window()
window.add(view)
window.set_keep_above(True)
window.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST)
window.set_default_size(400, 150)
window.set_decorated(False)
window.show_all()
width, height = window.get_size()
window.move(gtk.gdk.screen_width() - width - 25, gtk.gdk.screen_height() - height - 50)
gtk.main()
write_pid()
if len(sys.argv) > 1:
display(sys.argv[1])
else:
display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment