diff options
author | Martin Pitt <martinpitt@gnome.org> | 2013-07-24 14:59:13 +0200 |
---|---|---|
committer | Martin Pitt <martinpitt@gnome.org> | 2013-07-24 14:59:13 +0200 |
commit | 21e8b62d46a856cc5acef97607604855f52334c7 (patch) | |
tree | 1a873a5baadb903d685e934969e0be0a65728bdc | |
parent | 8c0889a6bd4dd63fbb53f33b8068565e2ffb2674 (diff) |
mpi2hwdb.py: Output UTF-8 independently of locale
Ensure that we ignore the locale and thus the default output encoding, so
that we build the output files in UTF-8.
https://bugs.freedesktop.org/show_bug.cgi?id=67242
-rwxr-xr-x | tools/mpi2hwdb.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tools/mpi2hwdb.py b/tools/mpi2hwdb.py index a519798..1e03e1e 100755 --- a/tools/mpi2hwdb.py +++ b/tools/mpi2hwdb.py @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -import sys, configparser, os.path +import sys, configparser, os.path, os def parse_mpi(mpi): '''Print hwdb file for given ConfigParser object.''' @@ -36,9 +36,11 @@ def parse_mpi(mpi): except configparser.NoOptionError: continue + block = '' + try: m = cp.get('Device', 'product') - print('#', m) + block += '# ' + m + '\n' except configparser.NoOptionError: pass @@ -57,8 +59,8 @@ def parse_mpi(mpi): for vid, pids in usbids.items(): for pid in pids: - print('usb:v%sp%s*'% (vid.upper(), pid.upper())) - print(' ID_MEDIA_PLAYER=%s' % os.path.splitext(os.path.basename(mpi))[0]) + block += 'usb:v%sp%s*\n' % (vid.upper(), pid.upper()) + block += ' ID_MEDIA_PLAYER=%s\n' % os.path.splitext(os.path.basename(mpi))[0] # do we have an icon? try: @@ -68,8 +70,12 @@ def parse_mpi(mpi): except configparser.NoOptionError: pass - # terminate line - print() + # empty line between blocks + block += '\n' + + # write bytes so that we are independent of the locale + os.write(sys.stdout.fileno(), block.encode('UTF-8')) + except configparser.NoOptionError: pass |