launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #03085
[Merge] lp:~julian-edwards/launchpad/sync-correct-versions into lp:launchpad
Julian Edwards has proposed merging lp:~julian-edwards/launchpad/sync-correct-versions into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~julian-edwards/launchpad/sync-correct-versions/+merge/55129
= Summary =
Derived Distros feature ongoing work ...
== Proposed fix ==
The code that was syncing packages from the parent didn't take into account
the versions of the packages that were flagged up, this branch fixes that by
copying only the versions checked in the form.
== Implementation details ==
The act of copying packages for derived distros is identical to the existing
package copying for PPAs.
Therefore I've refactored the browser code for PPAs into a mixin so that it
can be re-used in the Derived Distros code.
== Tests ==
bin/test -cvv -t test_series_views -t xx-copy-packages.txt
== Demo and Q/A ==
Not really QA-able yet until the backend code to populate the
DistroSeriesDifferences table all works.
= Launchpad lint =
Lint is busticated again :/
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/registry/browser/distroseries.py
lib/lp/registry/browser/tests/test_series_views.py
lib/lp/soyuz/browser/archive.py
Traceback (most recent call last):
File "/usr/bin/pocketlint", line 4, in <module>
from pocketlint.formatcheck import main
File "/usr/lib/pymodules/python2.6/pocketlint/formatcheck.py", line 22, in <module>
from xml.etree.ElementTree import ParseError
ImportError: cannot import name ParseError
--
https://code.launchpad.net/~julian-edwards/launchpad/sync-correct-versions/+merge/55129
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/launchpad/sync-correct-versions into lp:launchpad.
=== modified file 'lib/lp/registry/browser/distroseries.py'
--- lib/lp/registry/browser/distroseries.py 2011-03-24 14:13:45 +0000
+++ lib/lp/registry/browser/distroseries.py 2011-03-28 12:12:48 +0000
@@ -84,15 +84,14 @@
from lp.registry.interfaces.distroseriesdifference import (
IDistroSeriesDifferenceSource,
)
+from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.registry.interfaces.series import SeriesStatus
from lp.services.features import getFeatureFlag
from lp.services.propertycache import cachedproperty
from lp.services.worlddata.interfaces.country import ICountry
from lp.services.worlddata.interfaces.language import ILanguageSet
+from lp.soyuz.browser.archive import PackageCopyingMixin
from lp.soyuz.browser.packagesearch import PackageSearchViewBase
-from lp.soyuz.interfaces.archive import (
- CannotCopy,
- )
from lp.soyuz.interfaces.queue import IPackageUploadSet
from lp.translations.browser.distroseries import (
check_distroseries_translations_viewable,
@@ -565,7 +564,7 @@
required=True)
-class DistroSeriesLocalDifferences(LaunchpadFormView):
+class DistroSeriesLocalDifferences(LaunchpadFormView, PackageCopyingMixin):
"""Present differences between a derived series and its parent."""
schema = IDifferencesFormSchema
field_names = ['selected_differences']
@@ -628,22 +627,19 @@
# synced' and write a job runner to do it in the background.
selected_differences = data['selected_differences']
- diffs = [
- diff.source_package_name.name
- for diff in selected_differences]
-
- try:
- self.context.main_archive.syncSources(
- diffs, from_archive=self.context.parent_series.main_archive,
- to_pocket='Release', to_series=self.context.name)
- except CannotCopy, e:
- self.request.response.addErrorNotification("Cannot copy: %s" % e)
- else:
- self.request.response.addNotification(
- "The following sources were synchronized: " +
- ", ".join(diffs))
-
- self.next_url = self.request.URL
+ sources = [
+ diff.parent_source_pub
+ for diff in selected_differences]
+
+ # PackageCopyingMixin.do_copy() does the work of copying and
+ # setting up on-page notifications.
+ if self.do_copy(
+ 'selected_differences', sources, self.context.main_archive,
+ self.context, PackagePublishingPocket.RELEASE,
+ include_binaries=False):
+ # The copy worked so we can redirect back to the page to
+ # show the results.
+ self.next_url = self.request.URL
def validate_sync(self, action, data):
"""Validate selected differences."""
=== modified file 'lib/lp/registry/browser/tests/test_series_views.py'
--- lib/lp/registry/browser/tests/test_series_views.py 2011-03-24 14:13:45 +0000
+++ lib/lp/registry/browser/tests/test_series_views.py 2011-03-28 12:12:48 +0000
@@ -404,8 +404,8 @@
self.assertEqual(0, len(view.errors))
notifications = view.request.response.notifications
self.assertEqual(1, len(notifications))
- self.assertEqual(
- "The following sources were synchronized: my-src-name",
+ self.assertIn(
+ "Packages copied to",
notifications[0].message)
# 302 is a redirect back to the same page.
self.assertEqual(302, view.request.response.getStatus())
=== modified file 'lib/lp/soyuz/browser/archive.py'
--- lib/lp/soyuz/browser/archive.py 2011-03-08 06:04:17 +0000
+++ lib/lp/soyuz/browser/archive.py 2011-03-28 12:12:48 +0000
@@ -23,6 +23,7 @@
'ArchiveView',
'ArchiveViewBase',
'make_archive_vocabulary',
+ 'PackageCopyingMixin',
'traverse_named_ppa',
]
@@ -1211,6 +1212,67 @@
_messageNoValue = _("vocabulary-copy-to-same-series", "The same series")
+class PackageCopyingMixin:
+ """A mixin class that adds helpers for package copying."""
+
+ def do_copy(self, sources_field_name, source_pubs, dest_archive,
+ dest_series, dest_pocket, include_binaries):
+ try:
+ copies = do_copy(
+ source_pubs, dest_archive, dest_series,
+ dest_pocket, include_binaries)
+ except CannotCopy, error:
+ messages = []
+ error_lines = str(error).splitlines()
+ if len(error_lines) == 1:
+ messages.append(
+ "<p>The following source cannot be copied:</p>")
+ else:
+ messages.append(
+ "<p>The following sources cannot be copied:</p>")
+ messages.append('<ul>')
+ messages.append(
+ "\n".join('<li>%s</li>' % line for line in error_lines))
+ messages.append('</ul>')
+
+ self.setFieldError(
+ sources_field_name, structured('\n'.join(messages)))
+ return False
+
+ # Preload BPNs to save queries when calculating display names.
+ needed_bpn_ids = set(
+ copy.binarypackagerelease.binarypackagenameID for copy in copies
+ if isinstance(copy, BinaryPackagePublishingHistory))
+ if needed_bpn_ids:
+ list(IStore(BinaryPackageName).find(
+ BinaryPackageName,
+ BinaryPackageName.id.is_in(needed_bpn_ids)))
+
+ # Present a page notification describing the action.
+ messages = []
+ destination_url = canonical_url(dest_archive) + '/+packages'
+ if len(copies) == 0:
+ messages.append(
+ '<p>All packages already copied to '
+ '<a href="%s">%s</a>.</p>' % (
+ destination_url,
+ dest_archive.displayname))
+ else:
+ messages.append(
+ '<p>Packages copied to <a href="%s">%s</a>:</p>' % (
+ destination_url,
+ dest_archive.displayname))
+ messages.append('<ul>')
+ messages.append(
+ "\n".join(['<li>%s</li>' % copy.displayname
+ for copy in copies]))
+ messages.append('</ul>')
+
+ notification = "\n".join(messages)
+ self.request.response.addNotification(structured(notification))
+ return True
+
+
def make_archive_vocabulary(archives):
terms = []
for archive in archives:
@@ -1220,7 +1282,8 @@
return SimpleVocabulary(terms)
-class ArchivePackageCopyingView(ArchiveSourceSelectionFormView):
+class ArchivePackageCopyingView(ArchiveSourceSelectionFormView,
+ PackageCopyingMixin):
"""Archive package copying view class.
This view presents a package selection slot in a POST form implementing
@@ -1371,61 +1434,14 @@
self.setFieldError('selected_sources', 'No sources selected.')
return
- try:
- copies = do_copy(
- selected_sources, destination_archive, destination_series,
- destination_pocket, include_binaries)
- except CannotCopy, error:
- messages = []
- error_lines = str(error).splitlines()
- if len(error_lines) == 1:
- messages.append(
- "<p>The following source cannot be copied:</p>")
- else:
- messages.append(
- "<p>The following sources cannot be copied:</p>")
- messages.append('<ul>')
- messages.append(
- "\n".join('<li>%s</li>' % line for line in error_lines))
- messages.append('</ul>')
-
- self.setFieldError(
- 'selected_sources', structured('\n'.join(messages)))
- return
-
- # Preload BPNs to save queries when calculating display names.
- needed_bpn_ids = set(
- copy.binarypackagerelease.binarypackagenameID for copy in copies
- if isinstance(copy, BinaryPackagePublishingHistory))
- if needed_bpn_ids:
- list(IStore(BinaryPackageName).find(
- BinaryPackageName,
- BinaryPackageName.id.is_in(needed_bpn_ids)))
-
- # Present a page notification describing the action.
- messages = []
- destination_url = canonical_url(destination_archive) + '/+packages'
- if len(copies) == 0:
- messages.append(
- '<p>All packages already copied to '
- '<a href="%s">%s</a>.</p>' % (
- destination_url,
- destination_archive.displayname))
- else:
- messages.append(
- '<p>Packages copied to <a href="%s">%s</a>:</p>' % (
- destination_url,
- destination_archive.displayname))
- messages.append('<ul>')
- messages.append(
- "\n".join(['<li>%s</li>' % copy.displayname
- for copy in copies]))
- messages.append('</ul>')
-
- notification = "\n".join(messages)
- self.request.response.addNotification(structured(notification))
-
- self.setNextURL()
+ # PackageCopyingMixin.do_copy() does the work of copying and
+ # setting up on-page notifications.
+ if self.do_copy(
+ 'selected_sources', selected_sources, destination_archive,
+ destination_series, destination_pocket, include_binaries):
+ # The copy worked so we can redirect back to the page to
+ # show the result.
+ self.setNextURL()
class ArchiveEditDependenciesView(ArchiveViewBase, LaunchpadFormView):