Merge lp:~xintx-ua/command-not-found/add-install-support into lp:~command-not-found-developers/command-not-found/trunk

Proposed by Serhiy
Status: Merged
Merged at revision: 144
Proposed branch: lp:~xintx-ua/command-not-found/add-install-support
Merge into: lp:~command-not-found-developers/command-not-found/trunk
Diff against target: 49 lines (+14/-0)
2 files modified
CommandNotFound/CommandNotFound.py (+13/-0)
command-not-found (+1/-0)
To merge this branch: bzr merge lp:~xintx-ua/command-not-found/add-install-support
Reviewer Review Type Date Requested Status
Zygmunt Krynicki Approve
Review via email: mp+84257@code.launchpad.net

Description of the change

Adding installation support.

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

21 + locale.setlocale(locale.LC_ALL, '')

Why are you setting this?

+ if return_code not in (0,256): #256 = user rejected installation
29 + print >> sys.stderr, _("A problem occured during installation. apt-get returned %d") % return_code

I would just do if return_code != 0, I don't know if there is any value as the failing installation probably leaves enough information to the user anyway.

145. By Serhiy

Fixes localized YESEXPR.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Two more comments:

1) Get the input encoding from locale.getlocale(locale.LC_CTYPE)[1], don't hardcode UTF-8

Come to think of it perhaps that's the same way we should get the input string encoding (not locale.getpreferredencoding(), anyway, it's not something you need to fix in this patch.

2) Run pyflakes and pep8 on this code, it will show you a number of stylistic issues, I can fix that myself but I usually recommend submitters to do it if they can.

146. By Serhiy

Deletes apt-get install exit status handling.

147. By Serhiy

Fixes encoding handling.

148. By Serhiy

Clean-up TODO.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1 apart from the locale.YESEXPR that is unusable IMHO. There is no way to display the pattern in a readable manner and there is no way to synchronize local translation to the value returned by the locale system. I'll patch this away and merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CommandNotFound/CommandNotFound.py'
2--- CommandNotFound/CommandNotFound.py 2011-08-25 09:49:51 +0000
3+++ CommandNotFound/CommandNotFound.py 2011-12-02 15:58:26 +0000
4@@ -9,6 +9,9 @@
5 import posix
6 import string
7 import sys
8+import subprocess
9+import locale
10+import re
11
12 _ = gettext.translation("command-not-found", fallback=True).ugettext
13
14@@ -189,6 +192,15 @@
15 xidx = -1
16 return (yidx - xidx) or cmp(x, y)
17
18+ def install_prompt(self, package_name):
19+ if package_name:
20+ pattern = re.compile(locale.nl_langinfo(locale.YESEXPR).decode(locale.getlocale(locale.LC_CTYPE)[1]))
21+ answer = raw_input(_("Do you want to install it? (y/N)")).decode(locale.getlocale(locale.LC_CTYPE)[1])
22+ if re.match(pattern, answer):
23+ install_command = "sudo apt-get install %s" % package_name
24+ print >> sys.stdout, "%s" % install_command
25+ subprocess.call(install_command.split(), shell=False)
26+
27 def advise(self, command, ignore_installed=False):
28 " give advice where to find the given command to stderr "
29 def _in_prefix(prefix, command):
30@@ -238,6 +250,7 @@
31 elif self.user_can_sudo:
32 print >> sys.stderr, _("You can install it by typing:")
33 print >> sys.stderr, "sudo apt-get install %s" % packages[0][0]
34+ self.install_prompt(packages[0][0])
35 else:
36 print >> sys.stderr, _("To run '%(command)s' please ask your administrator to install the package '%(package)s'") % {'command': command, 'package': packages[0][0]}
37 if not packages[0][1] in self.sources_list:
38
39=== modified file 'command-not-found'
40--- command-not-found 2011-09-20 13:48:59 +0000
41+++ command-not-found 2011-12-02 15:58:26 +0000
42@@ -23,6 +23,7 @@
43 def enable_i18n():
44 cnf = gettext.translation("command-not-found", fallback=True)
45 cnf.install(unicode=True)
46+ locale.setlocale(locale.LC_ALL, '')
47
48
49 def fix_sys_argv(encoding=None):

Subscribers

People subscribed via source and target branches