Merge lp:~michael.nelson/launchpad/510331-syncsources-latest-pub into lp:launchpad
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Michael Nelson on 2010-02-01 | ||||
| Approved revision: | not available | ||||
| Merged at revision: | not available | ||||
| Proposed branch: | lp:~michael.nelson/launchpad/510331-syncsources-latest-pub | ||||
| Merge into: | lp:launchpad | ||||
| Diff against target: |
190 lines (+90/-22) 5 files modified
lib/lp/soyuz/doc/archive.txt (+11/-7) lib/lp/soyuz/interfaces/archive.py (+2/-2) lib/lp/soyuz/model/archive.py (+24/-11) lib/lp/soyuz/stories/webservice/xx-archive.txt (+9/-2) lib/lp/soyuz/tests/test_archive.py (+44/-0) |
||||
| To merge this branch: | bzr merge lp:~michael.nelson/launchpad/510331-syncsources-latest-pub | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Graham Binns (community) | code | 2010-01-26 | Approve on 2010-02-02 |
|
Review via email:
|
|||
Commit Message
Ensures that syncSources only chooses the latest *PUBLISHED* sources, rather than simply the latest sources.
| Michael Nelson (michael.nelson) wrote : | # |
| Graham Binns (gmb) wrote : | # |
Hi Michael,
This looks good to me. One minor nitpick, but otherwise it's fine to
land as-is.
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -1121,6 +1112,23 @@
>
> self._copySourc
>
> + def _collectLatestP
> + """Private helper to collect the latest published sources for an
> + archive.
> + """
> + sources = []
> + for name in source_names:
> + # Check to see if the source package exists, and raise a useful
> + # error if it doesn't.
What qualifies as "A useful error" here? It'd be nice to say in the
comment - or better still in the docstring - "will raise a FooBarError
if the source package doesn't exist."
> + getUtility(
> + # Grabbing the item at index 0 ensures it's the most recent
> + # publication.
> + sources.append(
> + from_archive.
> + name=name, exact_match=True,
> + status=
> + return sources
> +
> def _copySources(self, sources, to_pocket, to_series=None,
> include_
> """Private helper function to copy sources to this archive.
>
| Michael Nelson (michael.nelson) wrote : | # |
<noodles775> gmb: great. Did you have any thoughts about a better way to test the private method (as mentioned in the MP)?
<gmb> noodles775: Argh, must've skipped that bit of the mp. Sorry. Hang on...
<gmb> noodles775: So, no, I can't think of a better way (which is why I never balked at the use of rSP()). The only way I could think of is to test it indirectly, but I'd rather have the direct test myself.
<noodles775> Great, thanks for that.
| Michael Nelson (michael.nelson) wrote : | # |
Hi gmb,
I just got back to this branch, tested it, and had errors or the webservice branch that tested syncSource(s) through the API. The error was simply because the sources used in the test weren't in the published status, but it was 500ing, rather than a nice API error, so I've updated the code to avoid that also.
Here's the diff:
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -1127,10 +1127,11 @@
# Grabbing the item at index 0 ensures it's the most recent
# publication.
- sources.append(
- from_archive.
- name=name, exact_match=True,
- status=
+ published_sources = from_archive.
+ name=name, exact_match=True,
+ status=
+ if published_
+ sources.
return sources
def _copySources(self, sources, to_pocket, to_series=None,
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -576,9 +576,12 @@
... sourcename=
... archive=
+ >>> from lp.soyuz.
+ ... PackagePublishi
>>> ignore = test_publisher.
... sourcename=
- ... archive=
+ ... archive=
+ ... status=
>>> ignore = test_publisher.
... sourcename=
@@ -742,6 +745,8 @@
>>> private_publication = test_publisher.
... cprov.archive, 'foocomm', '1.0-1')
+ >>> private_
+ ... PackagePublishi
>>> logout()
@@ -908,8 +913,10 @@
version.
>>> login('<email address hidden>')
- >>> unused = test_publisher.
+ >>> subsequent_version = test_publisher.
... cprov.archive, 'foocomm', '1.0-2')
+ >>> subsequent_
+ ... PackagePublishi
>>> logout()
>>> print cprov_webservic
| Graham Binns (gmb) wrote : | # |
As discussed on IRC, you should test for `not foo.is_empty()` rather than `foo.count() > 0` as it's more efficient. Other than that, this change looks fine.
| Michael Nelson (michael.nelson) wrote : | # |
<noodles775> gmb, jtv: http://
<noodles775> Looks like is_empty isn't included on the ISQLObjectResultSet in storm.zope.
<gmb> ?!
<gmb> Oh, ah.
<gmb> I see.
<gmb> That's suboptimal.
<gmb> noodles775: In that case, just go back to using .count(). You could maybe file a tech-debt bug about changing getPublishedSou
<noodles775> Yep, thanks.

= Summary =
Fixes 510331 by ensuring that syncSources only finds pub records that are currently PUBLISHED.
== Proposed fix ==
== Pre-implementation notes ==
See note on the bug, as well as: syncSource( ) already allows you to specify the version... but with the solution you've suggested for syncSources()
<noodles> ok, sounds good. Also with bug 510331
<bigjools> noodles: yeah that one's easy
<noodles> IArchive.
<bigjools> ?
<noodles> it would mean that we'd not copy deleted sources even when there is no published one... is that expected?
<bigjools> yes, I think so
<noodles> OK. easy then.
<bigjools> well, would you expect it to?
<noodles> I'm imagining using the web ui, looking at a bunch of deleted sources and selecting them...
<bigjools> that's syncSource behaviour really
<bigjools> syncSources is more automatic
<bigjools> but we can make it explicit in the docstring
<noodles> OK.
== Implementation details ==
I wasn't sure of the best way to test the private helper method. I ended up going with removeSecurityP roxy() for the test, but would be happy to hear about a neater solution?
== Tests == stPublishedSour ces
bin/test -vvt doc/archive.txt -t TestCollectLate
== Demo and Q/A ==
We can Q/A this using the API on dogfood (or edge).
= Launchpad lint =
Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.
Linting changed files: soyuz/doc/ archive. txt soyuz/tests/ test_archive. py soyuz/model/ archive. py
lib/lp/
lib/lp/
lib/lp/
== Pylint notices ==
lib/lp/ soyuz/model/ archive. py .event' (No module named lifecycle)
1099: [C0301] Line too long (81/78) -- fixed.
14: [F0401] Unable to import 'lazr.lifecycle