Merge lp:~jibel/magomatic/magomatic-xprop into lp:magomatic

Proposed by Jean-Baptiste Lallement
Status: Merged
Merged at revision: 4
Proposed branch: lp:~jibel/magomatic/magomatic-xprop
Merge into: lp:magomatic
Diff against target: 123 lines (+60/-8)
2 files modified
bin/magomatic (+56/-6)
magomatic/magomatic.py (+4/-2)
To merge this branch: bzr merge lp:~jibel/magomatic/magomatic-xprop
Reviewer Review Type Date Requested Status
Nagappan Alagappan Approve
Review via email: mp+40093@code.launchpad.net

Description of the change

This avoids searching for the command and window name to introspect.

To post a comment you must log in.
Revision history for this message
Nagappan Alagappan (nagappan) wrote :

Changes looks fine to me. Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/magomatic'
2--- bin/magomatic 2010-10-22 12:05:31 +0000
3+++ bin/magomatic 2010-11-04 13:47:45 +0000
4@@ -8,7 +8,8 @@
5 import logging
6 import optparse
7 import os
8-import sys
9+import sys, subprocess
10+from re import search
11
12 import gettext
13 from gettext import gettext as _
14@@ -32,6 +33,51 @@
15 logging.DEBUG,
16 )
17
18+def xprop():
19+ (command, appname) = (None, None)
20+ (wmname, wmtype) = (None, None)
21+ print "\
22+Please select the window about which you would like information \n\
23+by clicking the mouse in that window."
24+
25+ try:
26+ sp = subprocess.Popen(['xprop','_NET_WM_PID', 'WM_NAME',
27+ '_NET_WM_WINDOW_TYPE'], stdin=None,
28+ stdout=subprocess.PIPE, stderr=None)
29+ except OSError, e:
30+ return [127, str(e)]
31+ out = sp.communicate()[0]
32+ for line in out.split('\n'):
33+ m = search('([^\(]+).* = (.+)', line)
34+ if m:
35+ wmprop = m.group(1)
36+ wmvalue = m.group(2)
37+
38+ if wmprop.startswith('_NET_WM_PID'):
39+ try:
40+ f = open('/proc/%d/comm' % int(wmvalue), 'rb')
41+ command = f.read().strip()
42+ f.close()
43+ except IOError, e:
44+ # Parent process may not exists anymore when it forks
45+ if e.errno == 2: # File does not exist
46+ return (None, None)
47+ else:
48+ raise IOError,e
49+ elif wmprop.startswith('WM_NAME'):
50+ # Remove quotes and spaces to match naming conventions of ldtp
51+ wmname = wmvalue[1:-1].replace(' ','')
52+ elif wmprop.startswith('_NET_WM_WINDOW_TYPE'):
53+ if 'NORMAL' in wmvalue:
54+ wmtype = 'frm'
55+ elif 'DIALOG' in wmvalue:
56+ wmtype = 'dlg'
57+
58+ if wmname and wmtype:
59+ appname = wmtype + wmname
60+
61+ return (command, appname)
62+
63 if __name__ == "__main__":
64
65 version = magomaticconfig.__magomatic_data_directory__
66@@ -46,11 +92,15 @@
67 (options, args) = parser.parse_args()
68
69 if len(args) != 2:
70- parser.error("Incorrect number of arguments")
71+ # Run xprop to guess the window name and binary
72+ (app_launcher, main_window) = xprop()
73+ if not app_launcher or not main_window:
74+ print "E: Unable to find information about that window."
75+ sys.exit(1)
76+ else:
77+ app_launcher = args[0]
78+ main_window = args[1]
79
80- app_launcher = args[0]
81- main_window = args[1]
82-
83 # set the verbosity
84 if options.debug_mode:
85 options.logging_level = 3
86@@ -61,4 +111,4 @@
87 magomatic.create_app_folder()
88 magomatic.discover_application()
89
90- logging.debug(_('end of prog'))
91\ No newline at end of file
92+ logging.debug(_('end of prog'))
93
94=== modified file 'magomatic/magomatic.py'
95--- magomatic/magomatic.py 2010-11-03 21:44:45 +0000
96+++ magomatic/magomatic.py 2010-11-04 13:47:45 +0000
97@@ -15,7 +15,7 @@
98 """
99 """
100
101- def __init__(self, launcher, main_window, white_list=["menu_item", "push_button"]):
102+ def __init__(self, launcher, main_window, white_list=["menu_item", "push_button", "text"]):
103 self.launcher = launcher
104 self.appname = re.sub('\W', '_', self.launcher)
105 self.main_window = main_window
106@@ -64,7 +64,8 @@
107
108 def discover_application(self):
109
110- ldtp.launchapp(self.launcher)
111+ if not ldtp.guiexist(self.main_window):
112+ ldtp.launchapp(self.launcher)
113 ldtp.waittillguiexist(self.main_window)
114 app = ooldtp.context(self.main_window)
115
116@@ -81,6 +82,7 @@
117
118 if role in self.white_list:
119 constant = re.sub('\W', '_', component.upper())
120+ constant = constant[:3] + "_" + constant[3:] # Split prefix for clarity
121 constants += " " + constant +" = _('" + component + "')\n"
122
123 app_file = os.path.join(self.app_folder, "application/" + self.appname + ".py")

Subscribers

People subscribed via source and target branches