Merge lp:~luke-stanley/command-not-found/command-not-found into lp:~command-not-found-developers/command-not-found/trunk

Proposed by voltlick
Status: Needs review
Proposed branch: lp:~luke-stanley/command-not-found/command-not-found
Merge into: lp:~command-not-found-developers/command-not-found/trunk
Diff against target: 61 lines (+30/-18)
1 file modified
CommandNotFound/ (+30/-18)
To merge this branch: bzr merge lp:~luke-stanley/command-not-found/command-not-found
Reviewer Review Type Date Requested Status
Zygmunt Krynicki Needs Fixing
Review via email:

Description of the change

Allows many more people to more easily install packages by prompting to install without them having to know about any flag to configure but also prompting if they want to disable assistance installing. (It's very easy to disable, and it still asks for permission each time of course.)
Instead of a more tricky environment switch it checks if ~/.config/DISABLE_COMMAND_NOT_FOUND_INSTALL_PROMPT exists to disable help or looks for touch ~/.config/COMMAND_NOT_FOUND_INSTALL_PROMPT to see that it is needed.

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


Thanks for your contribution. I don't think this can land as-is. Using ~/.config/*COMMAND_NOT_FOUND_* is certainly not in good tone (all-upper-caps, not using XDG_CONFIG_HOME).

I'm not sure if we should change how c-n-f operates in the way you've proposed. What I'd like to see instead is:

Use ConfigParser/configparser to load and write command-not-found settings from $XDG_CONFIG_HOME/command-not-found.conf. Have a few options that decide on what you want. Ensure that we're error resiliant (parser, issues, sane deefaults).

I cannot write that code myself at this time (busy) but if you're willing to iterate on your proposal this can eventually be merged.

Lastly. I'd like to see some discussion on <email address hidden> about this change. It's not major but just ask if anyone would oppose this change. It should be okay but for something that affects everyone using Ubuntu, it's worth to check.

If you need to chat about any of this in real time feel free to ping me (zyga) on #ubuntu-devel at any time. Thanks

review: Needs Fixing

Unmerged revisions

155. By voltlick

prompts the user once to ask for their preference on being asked about installing

154. By Michael Vogt call version 0.3 as its a python*3* verison ;)

153. By Michael Vogt

merged python3 port lp:~cjwatson/command-not-found/python3, thanks to Colin Watson

152. By Zygmunt Krynicki

Merge support for building pot files when running ./ sdist

151. By Michael Vogt

merge from ubuntu but remove fixes we don't need

150. By Michael Vogt

cherry pick fixes from ubuntu

149. By Michael Vogt

merged lp:~mvo/command-not-found/remove-debian-dir

148. By Michael Vogt

merged lp:~mvo/command-not-found/install-prompt-env

147. By Michael Vogt

fix java recommends (LP: #853688)

146. By Zygmunt Krynicki

Merge improved zsh support from Alex Jurkiewicz

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CommandNotFound/'
2--- CommandNotFound/ 2012-06-13 16:09:46 +0000
3+++ CommandNotFound/ 2013-06-14 16:55:32 +0000
4@@ -202,27 +202,39 @@
5 xidx = -1
6 #
7 return (yidx - xidx) or ((x > y) - (x < y))
9- def install_prompt(self, package_name):
10- if not "COMMAND_NOT_FOUND_INSTALL_PROMPT" in os.environ:
11- return
12- if package_name:
13- prompt = _("Do you want to install it? (N/y)")
14- if sys.version >= '3':
15- answer = input(prompt)
16- else:
17- answer = raw_input(prompt)
18+ def yes_or_no(self,prompt):
19+ "Give prompt and return bool"
20+ if sys.version >= '3':
21+ answer = input(prompt)
22+ else:
23+ answer = raw_input(prompt)
24 if sys.stdin.encoding and isinstance(answer, str):
25 # Decode the answer so that we get an unicode value
26 answer = answer.decode(sys.stdin.encoding)
27- if answer.lower() == _("y"):
28- if posix.geteuid() == 0:
29- command_prefix = ""
30- else:
31- command_prefix = "sudo "
32- install_command = "%sapt-get install %s" % (command_prefix, package_name)
33- print("%s" % install_command, file=sys.stdout)
34-, shell=False)
35+ if answer.lower() == _("y"):
36+ return True
37+ else:
38+ return False
39+ def install_prompt(self, package_name):
40+ if package_name and not os.path.exists(os.path.expanduser("~/.config/DISABLE_COMMAND_NOT_FOUND_INSTALL_PROMPT")):
41+ wants_help_in_general = False
42+ if not os.path.exists(os.path.expanduser("~/.config/COMMAND_NOT_FOUND_INSTALL_PROMPT")):
43+ wants_help_in_general = self.yes_or_no("Do you want to be offered the option to install packages when they are not found? (N/y)")
44+ if wants_help_in_general == False:
45+ print ('To disable this prompt, you may enter this:')
46+ print ("touch ~/.config/DISABLE_COMMAND_NOT_FOUND_INSTALL_PROMPT")
47+ if wants_help_in_general == True:
48+ os.system("touch ~/.config/COMMAND_NOT_FOUND_INSTALL_PROMPT")
49+ print ('Your preference has been set')
50+ if (os.path.exists(os.path.expanduser("~/.config/COMMAND_NOT_FOUND_INSTALL_PROMPT"))) or (wants_help_in_general == True):
51+ if self.yes_or_no(_("Do you want to install it? (N/y)")):
52+ if posix.geteuid() == 0:
53+ command_prefix = ""
54+ else:
55+ command_prefix = "sudo "
56+ install_command = "%sapt-get install %s" % (command_prefix, package_name)
57+ print("%s" % install_command, file=sys.stdout)
58+, shell=False)
60 def advise(self, command, ignore_installed=False):
61 " give advice where to find the given command to stderr "


People subscribed via source and target branches