Merge lp:~manishsinha/software-properties/fix-887249-handle-404-error into lp:software-properties

Status: Merged
Merged at revision: 726
Proposed branch: lp:~manishsinha/software-properties/fix-887249-handle-404-error
Merge into: lp:software-properties
Diff against target: 26 lines (+8/-1)
1 file modified
add-apt-repository (+8/-1)
To merge this branch: bzr merge lp:~manishsinha/software-properties/fix-887249-handle-404-error
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+81488@code.launchpad.net

Commit message

In case the user provides a wrong username or ppa name, then the exception is handled

* The exception handler checks that if the username starts with a ~, in this case
  it suggests does the user mean the username without a ~. e.g. if the user does
  sudo apt-add-repository ppa:~gnome3team/stable, then the script will ask the user
  if he means ppa:gnome3team/stable
* Even better friendlier messages can be provided, but for that it will introduce
  lauchpadlib as a dependency

Description of the change

In case the user provides a wrong username or ppa name, then the exception is handled

* The exception handler checks that if the username starts with a ~, in this case
  it suggests does the user mean the username without a ~. e.g. if the user does
  sudo apt-add-repository ppa:~gnome3team/stable, then the script will ask the user
  if he means ppa:gnome3team/stable
* Even better friendlier messages can be provided, but for that it will introduce
  lauchpadlib as a dependency

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'add-apt-repository'
2--- add-apt-repository 2011-10-18 19:16:25 +0000
3+++ add-apt-repository 2011-11-07 19:23:24 +0000
4@@ -10,6 +10,7 @@
5 from aptsources.sourceslist import SourceEntry
6 from optparse import OptionParser
7 from gettext import gettext as _
8+from urllib2 import HTTPError
9
10 def utf8(s):
11 """
12@@ -85,7 +86,13 @@
13 from softwareproperties.ppa import get_ppa_info_from_lp
14 user, sep, ppa_name = line.split(":")[1].partition("/")
15 ppa_name = ppa_name or "ppa"
16- ppa_info = get_ppa_info_from_lp(user, ppa_name)
17+ try:
18+ ppa_info = get_ppa_info_from_lp(user, ppa_name)
19+ except HTTPError:
20+ print _("Cannot add PPA. Please check that the PPA name or format is correct")
21+ if user.startswith("~"):
22+ print _("Did you mean ppa:%s/%s" %(user[1:], ppa_name))
23+ sys.exit(1)
24 if options.remove:
25 print _("You are about to remove the following PPA from your system:")
26 else: