Merge lp:~manishsinha/software-properties/list-ppa-names-for-user-or-team into lp:software-properties

Status: Merged
Merged at revision: 727
Proposed branch: lp:~manishsinha/software-properties/list-ppa-names-for-user-or-team
Merge into: lp:software-properties
Diff against target: 52 lines (+24/-1)
2 files modified
add-apt-repository (+23/-1)
softwareproperties/__init__.py (+1/-0)
To merge this branch: bzr merge lp:~manishsinha/software-properties/list-ppa-names-for-user-or-team
Reviewer Review Type Date Requested Status
Daniel Holbach (community) Needs Fixing
Review via email: mp+81634@code.launchpad.net

Commit message

When the PPA name is provided wrong, then via launchpadlib, it is checked if the user or team exists.
If it exists, then notify the user that PPA does not exist.

In case the user/team has a PPA, then list down the PPAs
In case the user/team does not have a PPA, show an message - "The team named 'cheers' does not have any PPA"

Note: Using people.is_team the user passed clearly marked as team or user.

=======================
Example error messages:

$ sudo ./add-apt-repository ppa:mhr3/foo
Cannot add PPA: 'ppa:mhr3/foo'.
The user named mhr3 has no PPA named foo
Please choose from the following available PPAs:
* test-ppa: Testing PPA

$ sudo ./add-apt-repository ppa:cheers/foo
Cannot add PPA: 'ppa:cheers/foo'.
The team named 'cheers' does not have any PPA

Description of the change

When the PPA name is provided wrong, then via launchpadlib, it is checked if the user or team exists.
If it exists, then notify the user that PPA does not exist.

In case the user/team has a PPA, then list down the PPAs
In case the user/team does not have a PPA, show an message - "The team named 'cheers' does not have any PPA"

Note: Using people.is_team the user passed clearly marked as team or user.

=======================
Example error messages:

$ sudo ./add-apt-repository ppa:mhr3/foo
Cannot add PPA: 'ppa:mhr3/foo'.
The user named mhr3 has no PPA named foo
Please choose from the following available PPAs:
* test-ppa: Testing PPA

$ sudo ./add-apt-repository ppa:cheers/foo
Cannot add PPA: 'ppa:cheers/foo'.
The team named 'cheers' does not have any PPA

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

I think this is fine, I just would like to move the code into its own function for easier readability/testability.

Revision history for this message
Daniel Holbach (dholbach) wrote :

Marking as 'needs fixing', based on the above comment.

review: Needs Fixing
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

@Daniel
MIchael has said that he will fix it himself (since right now I don't have a working internet connection at home and most ports blocked at my workplace)

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-11-08 14:51:16 +0000
3+++ add-apt-repository 2011-11-08 20:10:29 +0000
4@@ -7,6 +7,7 @@
5
6 from softwareproperties.SoftwareProperties import SoftwareProperties
7 from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line
8+from softwareproperties import lp_application_name
9 from aptsources.sourceslist import SourceEntry
10 from optparse import OptionParser
11 from gettext import gettext as _
12@@ -90,9 +91,30 @@
13 ppa_info = get_ppa_info_from_lp(user, ppa_name)
14 except HTTPError:
15 print _("Cannot add PPA: '%s'.") % line
16- print _("Please check that the PPA name or format is correct.")
17 if user.startswith("~"):
18 print _("Did you mean 'ppa:%s/%s' ?" %(user[1:], ppa_name))
19+ sys.exit(1) # Exit because the user cannot be correct
20+ # If the PPA does not exist, then try to find if the user/team
21+ # exists. If it exists, list down the PPAs
22+ try:
23+ from launchpadlib.launchpad import Launchpad
24+ lp = Launchpad.login_anonymously(lp_application_name, "production")
25+ try:
26+ user_inst = lp.people[user]
27+ entity_name = "team" if user_inst.is_team else "user"
28+ if len(user_inst.ppas) > 0:
29+ print _("The %s named '%s' has no PPA named '%s'"
30+ %(entity_name, user, ppa_name))
31+ print _("Please choose from the following available PPAs:")
32+ for ppa in user_inst.ppas:
33+ print _("* %s: %s" %(ppa.name, ppa.displayname))
34+ else:
35+ print _("The %s named '%s' does not have any PPA"
36+ %(entity_name, user))
37+ except KeyError:
38+ pass
39+ except ImportError:
40+ print _("Please check that the PPA name or format is correct.")
41 sys.exit(1)
42 if options.remove:
43 print _("You are about to remove the following PPA from your system:")
44
45=== modified file 'softwareproperties/__init__.py'
46--- softwareproperties/__init__.py 2011-07-18 14:52:00 +0000
47+++ softwareproperties/__init__.py 2011-11-08 20:10:29 +0000
48@@ -36,3 +36,4 @@
49 "max_age" : "APT::Archives::MaxAge"
50 }
51
52+lp_application_name = "software-properties"