Merge lp:~roadmr/checkbox/fix-gconf-resource into lp:checkbox

Proposed by Daniel Manrique
Status: Merged
Merged at revision: 1533
Proposed branch: lp:~roadmr/checkbox/fix-gconf-resource
Merge into: lp:checkbox
Diff against target: 66 lines (+10/-7)
2 files modified
debian/changelog (+3/-1)
scripts/gconf_resource (+7/-6)
To merge this branch: bzr merge lp:~roadmr/checkbox/fix-gconf-resource
Reviewer Review Type Date Requested Status
Marc Tardif (community) Approve
Review via email: mp+116664@code.launchpad.net

Description of the change

Fixes the attached bug by changing the decoding charset.

I moved a bit of code around to factor command execution out of the get_gconf function, mainly to ease testing. I didn't find a way or place to put a proper test of the function :( Suggestions welcome, but the code seems to work now. To test it, download the gconf.txt file from the bug (comment #3), and replace COMMAND with something like "cat gconf.txt". Change the encoding from ascii to utf-8 and viceversa to see things pass/fail.

To post a comment you must log in.
Revision history for this message
Marc Tardif (cr3) wrote :

Hm, I remember specifically setting the encoding to ascii but I was probably only thinking about the keys. I now see that the values can conceivably be encoded in utf-8!

The changes look good but I made a couple modifications while merging:

1. The parentheses around the check_output were not necessary for the arguments to be split on multiple lines.
2. The length of the command and its arguments was short, so they didn't really need to be split in the first place :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-07-24 18:45:55 +0000
3+++ debian/changelog 2012-07-25 14:36:24 +0000
4@@ -11,6 +11,8 @@
5 (LP: #1028065)
6 * Instruct Chromium browser to accept file:// URLs so it can correctly
7 open the checkbox submission.xml report (LP: #1026614)
8+ * scripts/gconf_resource: decode gconf output as utf-8 rather than ascii
9+ (LP: #1022593)
10
11 [Jeff Marcom]
12 * Added timeout to job call for disk smart test.
13@@ -18,7 +20,7 @@
14 [Marc Tardif]
15 * Escaping encoded strings in udevadm output (LP: #1025381)
16
17- -- Daniel Manrique <roadmr@ubuntu.com> Tue, 24 Jul 2012 13:32:37 -0400
18+ -- Daniel Manrique <roadmr@ubuntu.com> Wed, 25 Jul 2012 10:22:40 -0400
19
20 checkbox (0.14.2) quantal; urgency=low
21
22
23=== modified file 'scripts/gconf_resource'
24--- scripts/gconf_resource 2012-05-31 20:43:58 +0000
25+++ scripts/gconf_resource 2012-07-25 14:36:24 +0000
26@@ -21,7 +21,7 @@
27 import sys
28 import posixpath
29
30-from subprocess import Popen, PIPE
31+from subprocess import check_output, PIPE
32
33 from checkbox.lib.conversion import string_to_type
34
35@@ -33,7 +33,7 @@
36 SOURCE = "~/.gconf"
37
38
39-def get_gconf(command):
40+def get_gconf(output):
41 id = None
42 id_pattern = re.compile(r"\s+(?P<id>\/.+):")
43 key_value_pattern = re.compile(r"\s+(?P<key>[\w\-]+) = (?P<value>.*)")
44@@ -42,9 +42,7 @@
45 # TODO: add support for multi-line values
46
47 gconf = {}
48- output = (Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
49- .communicate()[0])
50- for line in output.decode("ascii").split("\n"):
51+ for line in output.decode("utf-8").split("\n"):
52 if not line:
53 continue
54
55@@ -80,7 +78,10 @@
56 def main():
57 source = posixpath.expanduser(SOURCE)
58 command = COMMAND.replace("$source", source)
59- gconf = get_gconf(command)
60+ command_output = (check_output(command,
61+ stderr=PIPE,
62+ shell=True))
63+ gconf = get_gconf(command_output)
64
65 for name, value in gconf.items():
66 print("name: %s" % name)

Subscribers

People subscribed via source and target branches