Merge lp:~jtatum/mago/gconf into lp:~mago-contributors/mago/mago-1.0

Proposed by James Tatum
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jtatum/mago/gconf
Merge into: lp:~mago-contributors/mago/mago-1.0
Diff against target: None lines
To merge this branch: bzr merge lp:~jtatum/mago/gconf
Reviewer Review Type Date Requested Status
Ara Pulido Approve
Rick McBride Approve
Javier Collado (community) Approve
Review via email: mp+10945@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Tatum (jtatum) wrote :

Adding a gconf wrapper for mago. I needed to use gconf while writing some test cases. I believe there are uses for gconf beyond test cases, so I placed the wrapper on the same level as other global utility classes: in the mago directory itself. I also added a check to determine if accessibility is enabled. This check uses one of the gconf static convenience methods.

lp:~jtatum/mago/gconf updated
111. By James Tatum <jtatum@jtatum-karmic>

Adding gconfwrapper to mago package

Revision history for this message
Nagappan Alagappan (nagappan) wrote :

> Adding a gconf wrapper for mago. I needed to use gconf while writing some test
> cases. I believe there are uses for gconf beyond test cases, so I placed the
> wrapper on the same level as other global utility classes: in the mago
> directory itself. I also added a check to determine if accessibility is
> enabled. This check uses one of the gconf static convenience methods.

Nice work :)

The import text size is increasing, can we just import utils and use utils.function ?

Revision history for this message
Rick McBride (rmcbride) wrote :

This is a really cool addition. The check for AT-SPI presence is also helpful.

I'm not marking this as anything, as I'm not in the contributors team yet, and I'm not sure what the review protocol is for this project.

The test does work though, and the code looks good!

Revision history for this message
Javier Collado (javier.collado) wrote :

Hello,

It looks fine to me. I also believe this is going to be useful for other tests. Thanks.

There's just one small problem when running the test that is available in the gconfwrapper module because class name is missing. Please see diff below:

=== modified file 'mago/gconfwrapper.py'
--- mago/gconfwrapper.py 2009-08-29 13:21:45 +0000
+++ mago/gconfwrapper.py 2009-09-01 15:06:53 +0000
@@ -164,9 +164,9 @@
     c['baz']=3.1

     print c['foo'], c['bar'], c['baz']
- print "Accessibility: %s" % get_item('/desktop/gnome/interface/accessibility')
+ print "Accessibility: %s" % GConf.get_item('/desktop/gnome/interface/accessibility')
     GConf.set_item('/apps/test-gconf/foobar', True)
     GConf.set_item('/apps/test-gconf/barfoo', False)

Best regards,
    Javier

review: Approve
lp:~jtatum/mago/gconf updated
112. By James Tatum <jtatum@jtatum-karmic>

Updating tests in gconfwrapper.py

Revision history for this message
James Tatum (jtatum) wrote :

> There's just one small problem when running the test that is available in the
> gconfwrapper module because class name is missing. Please see diff below:
[...]

Thanks, Javier! Good catch. I did not completely update the tests after applying the staticmethod decorator to get_item and set_item. Fixed in r112.

Revision history for this message
Rick McBride (rmcbride) wrote :

> This is a really cool addition. The check for AT-SPI presence is also helpful.
>
> I'm not marking this as anything, as I'm not in the contributors team yet, and
> I'm not sure what the review protocol is for this project.
>
> The test does work though, and the code looks good!

review: Approve
lp:~jtatum/mago/gconf updated
113. By James Tatum

Updating docstrings for epydoc goodness

Revision history for this message
James Tatum (jtatum) wrote :

Good news! r113 contains plenty of epydoc goodness for your perusal and amusement.

lp:~jtatum/mago/gconf updated
114. By James Tatum

Moving exception class inside GConf class

Revision history for this message
Ara Pulido (ara) wrote :

Really nice addition to the Mago library. I will merge any time soon.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mago/cmd/main.py'
2--- mago/cmd/main.py 2009-06-25 22:23:20 +0000
3+++ mago/cmd/main.py 2009-08-31 21:10:58 +0000
4@@ -12,9 +12,16 @@
5 from . import globals
6 from .runner import TestSuiteRunner
7 from .parser import parse_options
8-from .utils import safe_make_directory, safe_run_command
9+from .utils import safe_make_directory, safe_run_command, accessibility_enabled
10 from .discovery import discover_applications
11
12+def validate_environment():
13+ """
14+ Check environmental settings and ensure that the system is setup for mago
15+ """
16+ if not accessibility_enabled():
17+ raise Exception, ("Accessibility must be enabled to use mago. "
18+ "Enable it in the assisstive technologies panel and restart X.")
19
20 def process_application(app_data, target_directory):
21 """
22@@ -111,6 +118,8 @@
23 # Get shared directory based on the directory in which binary is located
24 options = parse_options(args)
25 configure_logging(options.log_level, options.log)
26+
27+ validate_environment()
28
29 logging.debug('MAGO_SHARE: %s' % globals.MAGO_SHARE)
30 logging.debug('MAGO_PATH: %s' % ':'.join(globals.MAGO_PATH))
31
32=== modified file 'mago/cmd/utils.py'
33--- mago/cmd/utils.py 2009-06-09 07:23:10 +0000
34+++ mago/cmd/utils.py 2009-08-31 21:10:58 +0000
35@@ -5,6 +5,13 @@
36 import os, logging
37 from stat import ST_MODE, S_IMODE
38 from subprocess import Popen, PIPE
39+from ..gconfwrapper import GConf
40+
41+def accessibility_enabled():
42+ """
43+ Check gconf key to determine if accessibility is enabled.
44+ """
45+ return GConf.get_item('/desktop/gnome/interface/accessibility')
46
47 def safe_change_mode(path, mode):
48 """
49
50=== added file 'mago/gconfwrapper.py'
51--- mago/gconfwrapper.py 1970-01-01 00:00:00 +0000
52+++ mago/gconfwrapper.py 2009-08-29 13:21:45 +0000
53@@ -0,0 +1,172 @@
54+# GConf wrapper
55+# Modified from Johan Dahlin's code:
56+# http://www.daa.com.au/pipermail/pygtk/2002-August/003220.html
57+import gconf
58+from gconf import VALUE_BOOL, VALUE_INT, VALUE_STRING, VALUE_FLOAT
59+from types import StringType, IntType, FloatType, BooleanType
60+
61+class GConfError(Exception):
62+ pass
63+
64+class GConf:
65+ """
66+ This class provides a handy interface for manipulating a gconf key.
67+
68+ interface=GConf("/desktop/gnome/interface/")
69+ print interface["accessibility"]
70+ interface["gtk_theme"]="Human"
71+ """
72+ def __init__ (self, domain):
73+ self._domain = domain
74+ self._gconf_client = gconf.client_get_default ()
75+
76+ def __getitem__ (self, attr):
77+ return self.get_value (attr)
78+
79+ def __setitem__ (self, key, val):
80+ self.set_value (key, val)
81+
82+ def _get_type (self, key):
83+ KeyType = type (key)
84+ if KeyType == StringType:
85+ return 'string'
86+ elif KeyType == IntType:
87+ return 'int'
88+ elif KeyType == FloatType:
89+ return 'float'
90+ elif KeyType == BooleanType:
91+ return 'bool'
92+ else:
93+ raise GConfError, 'unsupported type: %s' % str (KeyType)
94+
95+ # Public functions
96+
97+ def set_domain (self, domain):
98+ self._domain = domain
99+
100+ def get_domain (self):
101+ return self._domain
102+
103+ def get_gconf_client (self):
104+ return self._gconf_client
105+
106+ def get_value (self, key):
107+ '''returns the value of key `key' '''
108+ if '/' in key:
109+ raise GConfError, 'key must not contain /'
110+
111+ value = self._gconf_client.get (self._domain + key)
112+ ValueType = value.type
113+ if ValueType == VALUE_BOOL:
114+ return value.get_bool ()
115+ elif ValueType == VALUE_INT:
116+ return value.get_int ()
117+ elif ValueType == VALUE_STRING:
118+ return value.get_string ()
119+ elif ValueType == VALUE_FLOAT:
120+ return value.get_float ()
121+
122+ def set_value (self, key, value):
123+ '''sets the value of key `key' to `value' '''
124+ value_type = self._get_type (value)
125+
126+ if '/' in key:
127+ raise GConfError, 'key must not contain /'
128+
129+ func = getattr (self._gconf_client, 'set_' + value_type)
130+ apply (func, (self._domain + key, value))
131+
132+ def get_string (self, key):
133+ if '/' in key:
134+ raise GConfError, 'key must not contain /'
135+
136+ return self._gconf_client.get_string (self._domain + key)
137+
138+ def set_string (self, key, value):
139+ if type (value) != StringType:
140+ raise GConfError, 'value must be a string'
141+ if '/' in key:
142+ raise GConfError, 'key must not contain /'
143+
144+ self._gconf_client.set_string (self._domain + key, value)
145+
146+ def get_bool (self, key):
147+ if '/' in key:
148+ raise GConfError, 'key must not contain /'
149+
150+ return self._gconf_client.get_bool (self._domain + key)
151+
152+ def set_bool (self, key, value):
153+ if type (value) != IntType and \
154+ (key != 0 or key != 1):
155+ raise GConfError, 'value must be a boolean'
156+ if '/' in key:
157+ raise GConfError, 'key must not contain /'
158+
159+ self._gconf_client.set_bool (self._domain + key, value)
160+
161+ def get_int (self, key):
162+ if '/' in key:
163+ raise GConfError, 'key must not contain /'
164+
165+ return self._gconf_client.get_int (self._domain + key)
166+
167+ def set_int (self, key, value):
168+ if type (value) != IntType:
169+ raise GConfError, 'value must be an int'
170+ if '/' in key:
171+ raise GConfError, 'key must not contain /'
172+
173+ self._gconf_client.set_int (self._domain + key, value)
174+
175+ def get_float (self, key):
176+ if '/' in key:
177+ raise GConfError, 'key must not contain /'
178+
179+ return self._gconf_client.get_float (self._domain + key)
180+
181+ def set_float (self, key, value):
182+ if type (value) != FloatType:
183+ raise GConfError, 'value must be an float'
184+
185+ if '/' in key:
186+ raise GConfError, 'key must not contain /'
187+
188+ self._gconf_client.set_float (self._domain + key, value)
189+
190+ # Some even simpler methods for the truly lazy
191+ @staticmethod
192+ def get_item(key):
193+ """
194+ Pass this a key and it will return the value.
195+ print "Accessibility: %s" % GConf.get_item("/desktop/gnome/interface/accessibility")
196+ """
197+ dirname="%s/" % key.rpartition('/')[0]
198+ keyname=key.rpartition('/')[2]
199+ g=GConf(dirname)
200+ return g[keyname]
201+
202+ @staticmethod
203+ def set_item(key, value):
204+ """
205+ Set key to value provided:
206+ GConf.set_item("/desktop/gnome/interface/accessibility", True)
207+ """
208+ dirname="%s/" % key.rpartition('/')[0]
209+ keyname=key.rpartition('/')[2]
210+ g=GConf(dirname)
211+ g[keyname]=value
212+
213+def test():
214+ c=GConf ('/apps/test-gconf/')
215+ c['foo']='1'
216+ c['bar']=2
217+ c['baz']=3.1
218+
219+ print c['foo'], c['bar'], c['baz']
220+ print "Accessibility: %s" % get_item('/desktop/gnome/interface/accessibility')
221+ GConf.set_item('/apps/test-gconf/foobar', True)
222+ GConf.set_item('/apps/test-gconf/barfoo', False)
223+
224+if __name__ == '__main__':
225+ test()
226\ No newline at end of file

Subscribers

People subscribed via source and target branches

to status/vote changes: