[24345] in Source-Commits
/svn/athena r23943 - in trunk/debathena/debathena: . console console/debian
daemon@ATHENA.MIT.EDU (Geoffrey Thomas)
Fri Jul 31 03:25:51 2009
Date: Fri, 31 Jul 2009 03:25:38 -0400
From: Geoffrey Thomas <geofft@MIT.EDU>
Message-Id: <200907310725.n6V7PcK6009311@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: geofft
Date: 2009-07-31 03:25:38 -0400 (Fri, 31 Jul 2009)
New Revision: 23943
Added:
trunk/debathena/debathena/console/
trunk/debathena/debathena/console/debathena-console
trunk/debathena/debathena/console/debathena-console.schemas
trunk/debathena/debathena/console/debian/
trunk/debathena/debathena/console/debian/changelog
trunk/debathena/debathena/console/debian/compat
trunk/debathena/debathena/console/debian/control.in
trunk/debathena/debathena/console/debian/copyright
trunk/debathena/debathena/console/debian/debathena-console.install
trunk/debathena/debathena/console/debian/rules
trunk/debathena/debathena/console/hide_console
trunk/debathena/debathena/console/show_console
Log:
Add debathena-console package.
This is the application for solving Trac #286 ("some equivalent of
console in this brave new world"), though not the configuration to hook
it into the login process, which should go in a separate package.
Added: trunk/debathena/debathena/console/debathena-console
===================================================================
--- trunk/debathena/debathena/console/debathena-console 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debathena-console 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,243 @@
+#!/usr/bin/env python
+"""Debathena Console viewer
+Written by quentin@mit.edu
+
+Based on pygtk textview example code
+"""
+
+import os
+import sys
+import time
+
+import gobject
+import gtk
+import gconf
+import dbus, dbus.service
+import _dbus_bindings as dbus_bindings
+import dbus.mainloop.glib
+import wnck
+
+NAME = 'Console'
+
+# Supported gconf options:
+# /apps/debathena-console/blink
+# /apps/debathena-console/auto_hide
+# /apps/debathena-console/start_visible
+
+DBUS_IFACE="edu.mit.debathena.console"
+DBUS_BUS="edu.mit.debathena.console"
+DBUS_OBJECT="/edu/mit/debathena/console"
+
+class ConsoleDBus(dbus.service.Object):
+ def __init__(self, show_me, hide_me):
+ self.show_me = show_me
+ self.hide_me = hide_me
+ session_bus = dbus.SessionBus()
+ bus_name = dbus.service.BusName(DBUS_BUS, bus=session_bus)
+ object_path = DBUS_OBJECT
+ dbus.service.Object.__init__(self, bus_name, object_path)
+
+ @dbus.service.method(DBUS_IFACE,
+ in_signature="b")
+ def set_visibility(self, visible):
+ if visible:
+ self.show_me(True)
+ else:
+ self.hide_me()
+
+class ConsoleViewer(gtk.Window):
+ def __init__(self, fds=[]):
+ # Create the toplevel window
+ gtk.Window.__init__(self)
+
+ self.connect('focus-in-event', self.on_focus)
+
+ self.set_focus_on_map(False)
+
+ client = gconf.client_get_default()
+ client.add_dir('/apps/debathena-console',
+ gconf.CLIENT_PRELOAD_ONELEVEL)
+ client.notify_add('/apps/debathena-console/blink',
+ self.new_blink)
+ client.notify_add('/apps/debathena-console/auto_hide',
+ self.new_auto_hide)
+ self.auto_hide_id = False
+ self.new_blink(client)
+ self.new_auto_hide(client)
+
+ self.systray = gtk.StatusIcon()
+ self.systray.set_from_stock("gtk-info")
+ self.systray.connect("activate", self.on_tray_activate, "activate")
+# self.systray.connect("popup-menu", self.on_tray_popupmenu, self.popupmenu)
+ self.systray.set_tooltip(NAME)
+
+
+ self.set_title(NAME)
+ self.set_default_size(640, 320)
+ self.set_border_width(0)
+
+ vbox = gtk.VBox(False, 0)
+ self.add(vbox)
+
+ self.view = gtk.TextView();
+ buffer = self.view.get_buffer()
+
+ self.view.set_editable(False)
+ self.view.set_cursor_visible(False)
+ # See http://www.pygtk.org/docs/pygtk/gtk-constants.html#gtk-wrap-mode-constants
+ self.view.set_wrap_mode(gtk.WRAP_CHAR)
+
+ sw = gtk.ScrolledWindow()
+ sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
+ sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+
+ vbox.pack_start(sw)
+
+ sw.add(self.view)
+
+ bbox = gtk.HButtonBox()
+ bbox.set_border_width(5)
+ bbox.set_layout(gtk.BUTTONBOX_END)
+ bbox.set_spacing(40)
+
+ vbox.pack_start(bbox, expand=False)
+
+ def hide_window(*args):
+ gobject.idle_add(self.hide_me)
+ return True
+
+ button = gtk.Button("Hide")
+ button.connect("clicked", hide_window)
+ bbox.add(button)
+ self.connect('delete-event', hide_window)
+
+ self.create_tags(buffer)
+ self.insert_text(buffer)
+
+ # NB: we do show_all on the vbox so the widgets are ready
+ # when we present_with_time() inside show_me()
+ vbox.show_all()
+
+ if (client.get_bool("/apps/debathena-console/start_visible")):
+ self.show_me()
+
+ self.start_listening(buffer, self.view, fds)
+
+ self.dbus_service = ConsoleDBus(self.show_me, self.hide_me)
+ dbus.SessionBus().request_name(DBUS_BUS, dbus_bindings.NAME_FLAG_DO_NOT_QUEUE)
+
+ def new_blink(self, client, *a):
+ self.blink = client.get_bool("/apps/debathena-console/blink")
+
+ def new_auto_hide(self, client, *a):
+ self.auto_hide = client.get_int("/apps/debathena-console/auto_hide")
+ if self.auto_hide == 0 and self.auto_hide_id:
+ gobject.source_remove(self.auto_hide_id)
+ self.auto_hide_id = False
+
+ def on_tray_activate(self, widget, data=None):
+ if self.is_active():
+ self.hide_me()
+ else:
+ self.show_me(True)
+
+ def show_me(self, focus=False):
+ screen = wnck.screen_get_default()
+
+ active = screen.get_active_window()
+ if focus:
+ self.show_all()
+ self.window.focus()
+ elif not self.has_toplevel_focus():
+ # we need to be shown, but we're in the back
+ self.present_with_time(int(time.time()))
+ # restore the active window
+ while gtk.events_pending():
+ gtk.main_iteration()
+ if active:
+ active.activate(int(time.time()))
+
+ if self.auto_hide > 0:
+ if self.auto_hide_id:
+ gobject.source_remove(self.auto_hide_id)
+ self.auto_hide_id = gobject.timeout_add(self.auto_hide * 1000, self.hide_me)
+
+ def hide_me(self):
+ self.window.lower()
+ self.hide()
+ if self.auto_hide_id:
+ gobject.source_remove(self.auto_hide_id)
+ self.auto_hide_id = False
+ return False
+
+ def on_focus(self, widget, event):
+ self.systray.set_blinking(False)
+ return False
+
+ def create_tags(self, text_buffer):
+ '''
+ Create the tags we use for text (stdout and stderr)
+ '''
+
+ import pango
+
+ # See http://www.pygtk.org/docs/pygtk/class-gtktexttag.html
+ default_args = {'family': 'monospace',
+ 'size_points': 12}
+
+ text_buffer.create_tag("stdout", **default_args)
+ text_buffer.create_tag("stderr", foreground="red", **default_args)
+ text_buffer.create_tag("xconsole", weight=pango.WEIGHT_BOLD, **default_args)
+
+ def insert_text(self, text_buffer):
+ '''
+ Insert some sample text demonstrating the tags
+ '''
+ # get start of buffer; each insertion will revalidate the
+ # iterator to point to just after the inserted text.
+ iter = text_buffer.get_end_iter()
+
+ text_buffer.insert_with_tags_by_name(iter, "This is stdout\n", "stdout")
+ text_buffer.insert_with_tags_by_name(iter, "This is stderr\n", "stderr")
+ text_buffer.insert_with_tags_by_name(iter, "This is more stdout\n", "stdout")
+
+ def start_listening(self, text_buffer, text_view, fds):
+ '''
+ Sets up a gobject event listener that adds text to the textview whenever
+ stdin has something to read
+ '''
+ def got_data(source, condition, tag):
+ data = source.read()
+ # act like tee, so the logs still end up in .xsession-errors
+ print data,
+ text_buffer.insert_with_tags_by_name(text_buffer.get_end_iter(),
+ data, tag)
+
+ text_view.scroll_to_mark(text_buffer.create_mark(None, text_buffer.get_end_iter(), False), 0, False)
+
+ if self.blink and not self.has_toplevel_focus():
+ self.systray.set_blinking(True)
+ elif not self.has_toplevel_focus():
+ self.show_me()
+
+ if source.closed:
+ return False # we got an eof
+ else:
+ return True # causes callback to remain in existence
+ import fcntl, os
+ for i in range(len(fds)):
+ f = os.fdopen(fds[i][1])
+ fcntl.fcntl(fds[i][1], fcntl.F_SETFL, os.O_NONBLOCK)
+ gobject.io_add_watch(f, gobject.IO_IN, got_data, fds[i][0])
+
+def main():
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ if len(sys.argv) >= 2:
+ type, fd = x.split(':')
+ ConsoleViewer(fds=[(type, int(fd)) for x in sys.argv[1:]])
+ else:
+ ConsoleViewer(fds=[("stdout", 0)])
+ gtk.main()
+
+if __name__ == '__main__':
+ main()
Property changes on: trunk/debathena/debathena/console/debathena-console
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/debathena/debathena/console/debathena-console.schemas
===================================================================
--- trunk/debathena/debathena/console/debathena-console.schemas 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debathena-console.schemas 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,34 @@
+<gconfschemafile>
+<schemalist>
+<schema>
+ <key>/schemas/apps/debathena-console/blink</key>
+ <owner>debathena-console</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>Blink on input</short>
+ <long>Blink the status icon whenever input is received.</long>
+ </locale>
+</schema>
+<schema>
+ <key>/schemas/apps/debathena-console/auto_hide</key>
+ <owner>debathena-console</owner>
+ <type>int</type>
+ <default>0</default>
+ <locale name="C">
+ <short>Hide after seconds</short>
+ <long>The interval, in seconds, after which the console window is hidden.</long>
+ </locale>
+</schema>
+<schema>
+ <key>/schemas/apps/debathena-console/start_visible</key>
+ <owner>debathena-console</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>Console is visible on startup</short>
+ <long>Determines whether the console is visible when it initially starts.</long>
+ </locale>
+</schema>
+</schemalist>
+</gconfschemafile>
Added: trunk/debathena/debathena/console/debian/changelog
===================================================================
--- trunk/debathena/debathena/console/debian/changelog 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debian/changelog 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,5 @@
+debathena-console (1.0) unstable; urgency=low
+
+ * Initial release.
+
+ -- Geoffrey Thomas <geofft@mit.edu> Fri, 31 Jul 2009 03:20:48 -0400
Added: trunk/debathena/debathena/console/debian/compat
===================================================================
--- trunk/debathena/debathena/console/debian/compat 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debian/compat 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1 @@
+4
Added: trunk/debathena/debathena/console/debian/control.in
===================================================================
--- trunk/debathena/debathena/console/debian/control.in 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debian/control.in 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,14 @@
+Source: debathena-console
+Section: debathena/x11
+Priority: extra
+Maintainer: Debathena Project <debathena@mit.edu>
+Build-Depends: @cdbs@, debhelper (>= 4.2.16)
+Standards-Version: 3.7.2
+
+Package: debathena-console
+Architecture: all
+Depends: ${misc:Depends}, dbus, python,
+ python-gtk2, python-gconf, python-dbus, python-gnome2-desktop,
+Description: Displays incremental input in a popup window
+ Python implementation of a console viewing program that allows
+ users to see important messages during their login session.
Added: trunk/debathena/debathena/console/debian/copyright
===================================================================
--- trunk/debathena/debathena/console/debian/copyright 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debian/copyright 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,18 @@
+The Athena source code was obtained from the Athena SVN repository at
+<svn://debathena.mit.edu/athena/trunk>, and is licensed as follows:
+
+ Copyright © 2009 by Quentin Smith.
+
+ Permission to use, copy, modify, and distribute this software and
+ its documentation for any purpose and without fee is hereby granted,
+ provided that the above copyright notice appear in all copies and
+ that both that copyright notice and this permission notice appear in
+ supporting documentation, and that the name of M.I.T. not be used in
+ advertising or publicity pertaining to distribution of the software
+ without specific, written prior permission. M.I.T. makes no
+ representations about the suitability of this software for any
+ purpose. It is provided "as is" without express or implied
+ warranty.
+
+The Debian packaging is Copyright © 2009 Geoffrey Thomas, and has the
+same license as the original software.
Added: trunk/debathena/debathena/console/debian/debathena-console.install
===================================================================
--- trunk/debathena/debathena/console/debian/debathena-console.install 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debian/debathena-console.install 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,4 @@
+debathena-console usr/bin
+show_console usr/bin
+hide_console usr/bin
+debathena-console.schemas etc/gconf/schemas
Added: trunk/debathena/debathena/console/debian/rules
===================================================================
--- trunk/debathena/debathena/console/debian/rules 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/debian/rules 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+include /usr/share/cdbs/1/rules/debhelper.mk
+binary-post-install/debathena-console::
+ dh_gconf -p$(cdbs_curpkg)
Property changes on: trunk/debathena/debathena/console/debian/rules
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/debathena/debathena/console/hide_console
===================================================================
--- trunk/debathena/debathena/console/hide_console 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/hide_console 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,2 @@
+#!/bin/sh
+dbus-send --session --dest=edu.mit.debathena.console --type=method_call /edu/mit/debathena/console edu.mit.debathena.console.set_visibility boolean:false
Property changes on: trunk/debathena/debathena/console/hide_console
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/debathena/debathena/console/show_console
===================================================================
--- trunk/debathena/debathena/console/show_console 2009-07-30 14:47:02 UTC (rev 23942)
+++ trunk/debathena/debathena/console/show_console 2009-07-31 07:25:38 UTC (rev 23943)
@@ -0,0 +1,2 @@
+#!/bin/sh
+dbus-send --session --dest=edu.mit.debathena.console --type=method_call /edu/mit/debathena/console edu.mit.debathena.console.set_visibility boolean:true
Property changes on: trunk/debathena/debathena/console/show_console
___________________________________________________________________
Name: svn:executable
+ *