Debian Codegraph @

scripts/dogtail-detect-session

raw ◀ ▶
1 Debian patch touch this file
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 import sys
4 from dogtail.procedural import focus, FocusError
5
6 """
7 dogtail-detect session
8
9 This script checks for some main pieces of a running GNOME session,
10 specifically gnome-panel and metacity.
11
12 It checks to see that the gnome-panel node has at least some child nodes.
13 For example, the main gnome-panel node by default has two direct descendents:
14 the top panel, and the bottom panel.
15 Metacity's existence is also checked. However, metacity currently never has
16 any child nodes.
17
18 If a proper session is running, the scripts exits with a status of 0.
19 If no session is found, a non-zero exit code is returned.
20
21 Author: Zack Cerza <[email protected]>
22 """
23
24 __author__ = "Zack Cerza <[email protected]>"
25
26
27 def GNOME():
28 """
29 "Is an accessibility-enabled GNOME session running?"
30 """
31
32 running = False
33 try:
34 assert focus.desktop
35 assert focus.desktop.children
36
37 focus.application("gnome-panel")
38 assert focus.application.children
39
40 focus.application("metacity")
41 print(focus.application.node)
42 assert focus.application.node
43 running = True
44 print("GNOME Session detected.")
45
•46 except (AttributeError or AssertionError or FocusError):
47 print("ERROR: No GNOME session found.")
48
49 return running
50
51
52 def KDE():
53 """
54 "Is an accessibility-enabled KDE session running?"
55 """
56
57 running = False
58 return running
59
60
61 def JustSomeApps():
•62 """
63 "Is at least one accessibility-enabled application running?"
64 """
65
66 return focus.desktop and focus.desktop.children
67
68
69 if GNOME() or KDE() or JustSomeApps():
70 sys.exit()
71 else:
72 sys.exit(1)