1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
from dogtail.procedural import focus, FocusError
"""
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>"
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 GNOME 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?"
"""
return focus.desktop and focus.desktop.children
if GNOME() or KDE() or JustSomeApps():
sys.exit()
else:
sys.exit(1)
|