aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dogtail-detect-session
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dogtail-detect-session')
-rw-r--r--scripts/dogtail-detect-session66
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/dogtail-detect-session b/scripts/dogtail-detect-session
new file mode 100644
index 00000000000..8160201361e
--- /dev/null
+++ b/scripts/dogtail-detect-session
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+"""
+dogtail-detect session
+
+This script checks for some main pieces of a running GNOME session,
+specifically gnome-panel and metacity.
+
+It checks to see that the gnome-panel node has at least some child nodes.
+For example, the main gnome-panel node by default has two direct descendents:
+the top panel, and the bottom panel.
+Metacity's existence is also checked. However, metacity currently never has
+any child nodes.
+
+If a proper session is running, the scripts exits with a status of 0.
+If no session is found, a non-zero exit code is returned.
+
+Author: Zack Cerza <zcerza@redhat.com>
+"""
+
+__author__ = "Zack Cerza <zcerza@redhat.com>"
+
+from dogtail.procedural import *
+import sys
+
+
+def GNOME():
+ """
+ "Is an accessibility-enabled GNOME session running?"
+ """
+ running = False
+ try:
+ assert focus.desktop
+ assert focus.desktop.children
+
+ focus.application('gnome-panel')
+ assert focus.application.children
+
+ focus.application('metacity')
+ print focus.application.node
+ assert focus.application.node
+ running = True
+ print "GNOME Session detected."
+ except AttributeError or AssertionError or FocusError:
+ print "ERROR: No session found."
+ return running
+
+
+def KDE():
+ """
+ "Is an accessibility-enabled KDE session running?"
+ """
+ running = False
+ return running
+
+
+def JustSomeApps():
+ """
+ "Is at least one accessibility-enabled application running?"
+ """
+ assert focus.desktop
+ assert focus.desktop.children
+
+if GNOME() or KDE() or JustSomeApps():
+ sys.exit()
+else:
+ sys.exit(1)