Merge lp:~zyga/command-not-found/fix-839609 into lp:~command-not-found-developers/command-not-found/trunk

Proposed by Zygmunt Krynicki
Status: Merged
Merged at revision: 141
Proposed branch: lp:~zyga/command-not-found/fix-839609
Merge into: lp:~command-not-found-developers/command-not-found/trunk
Diff against target: 69 lines (+19/-4)
2 files modified
command-not-found (+18/-3)
setup.py (+1/-1)
To merge this branch: bzr merge lp:~zyga/command-not-found/fix-839609
Reviewer Review Type Date Requested Status
Zygmunt Krynicki Approve
Review via email: mp+75440@code.launchpad.net

Description of the change

This branch fixes a rather urgent bug that is present in virtually all locales (bug 839609) and updates internal version numbers to match reality

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1 (mvo merged this in)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'command-not-found'
2--- command-not-found 2011-08-25 09:49:51 +0000
3+++ command-not-found 2011-09-14 22:14:49 +0000
4@@ -5,12 +5,13 @@
5 from __future__ import absolute_import
6
7
8-__version__ = "0.2.21"
9+__version__ = "0.2.43"
10 BUG_REPORT_URL = "https://bugs.launchpad.net/command-not-found/+filebug"
11
12 try:
13+ import gettext
14+ import locale
15 import sys
16- import gettext
17 from optparse import OptionParser
18
19 from CommandNotFound.util import crash_guard
20@@ -24,6 +25,17 @@
21 cnf.install(unicode=True)
22
23
24+def fix_sys_argv(encoding=None):
25+ """
26+ Fix sys.argv to have only unicode strings, not binary strings.
27+ This is required by various places where such argument might be
28+ automatically coerced to unicode string for formatting
29+ """
30+ if encoding is None:
31+ encoding = locale.getpreferredencoding()
32+ sys.argv = [arg.decode(encoding) for arg in sys.argv]
33+
34+
35 class LocaleOptionParser(OptionParser):
36 """
37 OptionParser is broken as its implementation of _get_encoding() uses
38@@ -40,6 +52,7 @@
39
40 def main():
41 enable_i18n()
42+ fix_sys_argv()
43 parser = LocaleOptionParser(
44 version=__version__,
45 usage=_("%prog [options] <command-name>"))
46@@ -52,7 +65,9 @@
47 (options, args) = parser.parse_args()
48 if len(args) == 1:
49 cnf = CommandNotFound(options.data_dir)
50- if not cnf.advise(args[0], options.ignore_installed):
51+ # Note: we need to encode program name to utf-8 as gdbm does not seem
52+ # to handle unicode strings.
53+ if not cnf.advise(args[0].encode('utf-8'), options.ignore_installed):
54 print >>sys.stderr, _("%s: command not found") % args[0]
55
56 if __name__ == "__main__":
57
58=== modified file 'setup.py'
59--- setup.py 2011-08-10 12:45:45 +0000
60+++ setup.py 2011-09-14 22:14:49 +0000
61@@ -16,7 +16,7 @@
62
63 setup(
64 name='command-not-found',
65- version='0.1',
66+ version='0.2.43',
67 packages=['CommandNotFound'],
68 scripts=['command-not-found'],
69 data_files=[

Subscribers

People subscribed via source and target branches