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
=== modified file 'CommandNotFound/CommandNotFound.py'
--- CommandNotFound/CommandNotFound.py 2011-08-25 09:49:51 +0000
+++ CommandNotFound/CommandNotFound.py 2011-12-02 15:58:26 +0000
@@ -9,6 +9,9 @@
9import posix9import posix
10import string10import string
11import sys11import sys
12import subprocess
13import locale
14import re
1215
13_ = gettext.translation("command-not-found", fallback=True).ugettext16_ = gettext.translation("command-not-found", fallback=True).ugettext
1417
@@ -189,6 +192,15 @@
189 xidx = -1192 xidx = -1
190 return (yidx - xidx) or cmp(x, y)193 return (yidx - xidx) or cmp(x, y)
191194
195 def install_prompt(self, package_name):
196 if package_name:
197 pattern = re.compile(locale.nl_langinfo(locale.YESEXPR).decode(locale.getlocale(locale.LC_CTYPE)[1]))
198 answer = raw_input(_("Do you want to install it? (y/N)")).decode(locale.getlocale(locale.LC_CTYPE)[1])
199 if re.match(pattern, answer):
200 install_command = "sudo apt-get install %s" % package_name
201 print >> sys.stdout, "%s" % install_command
202 subprocess.call(install_command.split(), shell=False)
203
192 def advise(self, command, ignore_installed=False):204 def advise(self, command, ignore_installed=False):
193 " give advice where to find the given command to stderr "205 " give advice where to find the given command to stderr "
194 def _in_prefix(prefix, command):206 def _in_prefix(prefix, command):
@@ -238,6 +250,7 @@
238 elif self.user_can_sudo:250 elif self.user_can_sudo:
239 print >> sys.stderr, _("You can install it by typing:")251 print >> sys.stderr, _("You can install it by typing:")
240 print >> sys.stderr, "sudo apt-get install %s" % packages[0][0]252 print >> sys.stderr, "sudo apt-get install %s" % packages[0][0]
253 self.install_prompt(packages[0][0])
241 else:254 else:
242 print >> sys.stderr, _("To run '%(command)s' please ask your administrator to install the package '%(package)s'") % {'command': command, 'package': packages[0][0]}255 print >> sys.stderr, _("To run '%(command)s' please ask your administrator to install the package '%(package)s'") % {'command': command, 'package': packages[0][0]}
243 if not packages[0][1] in self.sources_list:256 if not packages[0][1] in self.sources_list:
244257
=== modified file 'command-not-found'
--- command-not-found 2011-09-20 13:48:59 +0000
+++ command-not-found 2011-12-02 15:58:26 +0000
@@ -23,6 +23,7 @@
23def enable_i18n():23def enable_i18n():
24 cnf = gettext.translation("command-not-found", fallback=True)24 cnf = gettext.translation("command-not-found", fallback=True)
25 cnf.install(unicode=True)25 cnf.install(unicode=True)
26 locale.setlocale(locale.LC_ALL, '')
2627
2728
28def fix_sys_argv(encoding=None):29def fix_sys_argv(encoding=None):

Subscribers

People subscribed via source and target branches