Merge lp://staging/~malizor/update-manager/ppa-changelogs into lp://staging/update-manager

Proposed by Nicolas Delvaux
Status: Merged
Merged at revision: 2730
Proposed branch: lp://staging/~malizor/update-manager/ppa-changelogs
Merge into: lp://staging/update-manager
Diff against target: 141 lines (+67/-4)
3 files modified
UpdateManager/Core/MyCache.py (+59/-4)
debian/changelog (+7/-0)
debian/control (+1/-0)
To merge this branch: bzr merge lp://staging/~malizor/update-manager/ppa-changelogs
Reviewer Review Type Date Requested Status
Colin Watson (community) Needs Fixing
Review via email: mp+297119@code.staging.launchpad.net

Commit message

Retrieve Changelogs from PPA sources if python3-launchpadlib is installed.

This uses the approach suggested by Colin Watson in LP: #253119.

Description of the change

Retrieve Changelogs from PPA sources if python3-launchpadlib is installed.

This uses the approach suggested by Colin Watson in LP: #253119.

I don't think it would be reasonable to add python3-launchpadlib to the hard dependency list: it would pull it and its dependencies into the default install, which is an additional 3269kB on Xenial.

Therefore, I only set python3-launchpadlib as a suggest dependency and I made the whole feature optional: if launchpadlib is not installed, nothing change except for a new warning in logs to suggest to install the library.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

Thanks for working on this, I appreciate it a lot. Generally, this looks good to me, but I have some comments which you'll find in line. You might also want to add a changelog entry to debian/changelog.

Revision history for this message
Colin Watson (cjwatson) wrote :

I would honestly just depend on python3-launchpadlib. Yes, we don't have anything in the desktop requiring it right now, but that isn't a strong reason not to add it; and without it, most people will continue not to see PPA changelogs, which seems more compelling to me.

Other than that, this seems like a good start and the use of the LP API seems mostly right, but there are a few details to fix up. Thanks!

review: Needs Fixing
Revision history for this message
Nicolas Delvaux (malizor) wrote :
Download full text (4.0 KiB)

Thanks for your comments so far.
I will try to adress them as soon as I'm back in front of a computer, which should be next week.

Le 15/06/16 02:34 Colin Watson a écrit :

Review: Needs Fixing

I would honestly just depend on python3-launchpadlib. Yes, we don't have anything in the desktop requiring it right now, but that isn't a strong reason not to add it; and without it, most people will continue not to see PPA changelogs, which seems more compelling to me.

Other than that, this seems like a good start and the use of the LP API seems mostly right, but there are a few details to fix up. Thanks!

Diff comments:

> === modified file 'UpdateManager/Core/MyCache.py'
> --- UpdateManager/Core/MyCache.py 2014-06-26 07:03:08 +0000
> +++ UpdateManager/Core/MyCache.py 2016-06-10 23:11:06 +0000
> @@ -268,6 +274,52 @@
> alllines = alllines + line
> return alllines
>
> + def _extract_ppa_changelog_uri(self, name):
> + """Return the changelog URI from the Launchpad API
> +
> + Return None in case of an error.
> + """
> + if Launchpad is None:
> + logging.warning("Please install 'python3-launchpadlib' to enable "
> + "changelog retrieval for PPAs.")
> + return
> + cdt = self[name].candidate
> + for uri in cdt.uris:
> + match = re.search('http.*/(.*)/(.*)/ubuntu/.*', uri)

This should use urllib.parse as the first step, and should only do anything if the hostname is ppa.launchpad.net.

> + if match is not None:
> + user, ppa = match.group(1), match.group(2)
> + break
> + else:
> + logging.error('Unable to extract the changelog from the PPA')
> + return
> +
> + # Login on launchpad if we are not already
> + if self.launchpad is None:
> + try:
> + self.launchpad = Launchpad.login_anonymously('update-manager',
> + 'production',
> + version='devel')
> + except:

Never use bare except. To catch everything that's reasonable to catch in most cases, use "except Exception:".

> + logging.exception("Unable to connect to Launchpad to retrieve "
> + "the changelog")
> + return
> +
> + archive = self.launchpad.archives.getByReference(
> + reference='~%s/ubuntu/%s' % (user, ppa)
> + )
> + if archive is None:
> + logging.error('Unable to extract the changelog from the PPA')
> + return
> +
> + spph = archive.getPublishedSources(source_name=cdt.source_name,
> + exact_match=True,
> + version=cdt.version)

It would be more conventional to use "spphs" given that this is plural.

> + if not spph:
> + logging.error('Unable to extract the changelog from the PPA')
> + return
> +
> + return spph[0].changelogUrl()

Why would a KeyError be relevant? Testing that the collection is non-empty should be enough to ensure that spphs[0] works, and there's no reason to suppose that .changelogUrl() will raise a KeyError. It may be worth catching HTTP exceptions (I forget the exact details), though, as temporary Launchpad outages shouldn't cause update-manager to explode.

> +
> def _guess_third_party_changelogs_uri_by_source(self, name):
> pkg = self[name]
> deb_uri = pkg.candidate.uri
> @@ -314,14 +366,21 @@
> if news:
> self.all_news[name] = news
>
> - def _fetch_changelog_for_third_party_package(self, name):
> + def _fetch_changelog_for_third_party_package(self, name, ori...

Read more...

2729. By Nicolas Delvaux

Attempt to retrieve Changelogs from PPA sources (LP: #253119)

2730. By Nicolas Delvaux

Add a new entry to debian/changelog

Revision history for this message
Nicolas Delvaux (malizor) wrote :

I fixed what you suggested:

* Move the try/except block to the calling function, to catch all API errors
* Different messages for different errors (and end them with periods!)
* Check that candidate URI hostname matches ppa.launchpad.net
* Do not use bare excepts
* Use "spphs" instead of the singular form
* Add a missing break
* Add an entry in debian/changelog

Revision history for this message
Brian Murray (brian-murray) wrote :

Thanks for making those fixes. I have one more question in-line.

Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: