Maximiliano Bertacchini has proposed merging 
lp:~maxiberta/launchpad/new-snap-select-processors into lp:launchpad.

Commit message:
Add processor selection in new Snap form.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~maxiberta/launchpad/new-snap-select-processors/+merge/298242

Add processor selection in new Snap form.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of 
lp:~maxiberta/launchpad/new-snap-select-processors into lp:launchpad.
=== modified file 'lib/lp/snappy/browser/snap.py'
--- lib/lp/snappy/browser/snap.py	2016-05-28 00:21:40 +0000
+++ lib/lp/snappy/browser/snap.py	2016-06-29 21:46:52 +0000
@@ -340,7 +340,8 @@
             log_oops(e, self.request)
 
 
-class SnapAddView(LaunchpadFormView, SnapAuthorizeMixin):
+class SnapAddView(
+        LaunchpadFormView, SnapAuthorizeMixin, EnableProcessorsMixin):
     """View for creating snap packages."""
 
     page_title = label = 'Create a new snap package'
@@ -369,6 +370,16 @@
                 self.context.information_type in PRIVATE_INFORMATION_TYPES):
                 raise SnapPrivateFeatureDisabled
 
+    def setUpFields(self):
+        """See `LaunchpadFormView`."""
+        super(SnapAddView, self).setUpFields()
+        processors = getUtility(ISnapSet).availableProcessors()
+        self.form_fields += self.createEnabledProcessors(
+            processors,
+            u"The architectures that this snap package builds for. Some "
+            u"architectures are restricted and may only be enabled or "
+            u"disabled by administrators.")
+
     @property
     def cancel_url(self):
         return canonical_url(self.context)
@@ -432,7 +443,8 @@
             data['store_distro_series'].distro_series, data['name'],
             private=private, store_upload=data['store_upload'],
             store_series=data['store_distro_series'].snappy_series,
-            store_name=data['store_name'], **kwargs)
+            store_name=data['store_name'], processors=data['processors'],
+            **kwargs)
         if data['store_upload']:
             self.requestAuthorization(snap)
         else:
@@ -636,7 +648,7 @@
                         data['processors'].append(processor)
                     elif processor.name in widget.disabled_items:
                         # This processor is restricted and currently
-                        # enabled.  Leave it untouched.
+                        # enabled. Leave it untouched.
                         data['processors'].append(processor)
 
 

=== modified file 'lib/lp/snappy/browser/tests/test_snap.py'
--- lib/lp/snappy/browser/tests/test_snap.py	2016-05-28 00:21:40 +0000
+++ lib/lp/snappy/browser/tests/test_snap.py	2016-06-29 21:46:52 +0000
@@ -160,6 +160,28 @@
             self.snappyseries = self.factory.makeSnappySeries(
                 usable_distro_series=[self.distroseries])
 
+    def setUpDistroSeries(self):
+        """Set up a distroseries with some available processors."""
+        distroseries = self.factory.makeUbuntuDistroSeries()
+        processor_names = ["386", "amd64", "hppa"]
+        for name in processor_names:
+            processor = getUtility(IProcessorSet).getByName(name)
+            self.factory.makeDistroArchSeries(
+                distroseries=distroseries, architecturetag=name,
+                processor=processor)
+        with admin_logged_in():
+            self.factory.makeSnappySeries(usable_distro_series=[distroseries])
+        return distroseries
+
+    def assertProcessorControls(self, processors_control, enabled, disabled):
+        matchers = [
+            MatchesStructure.byEquality(optionValue=name, disabled=False)
+            for name in enabled]
+        matchers.extend([
+            MatchesStructure.byEquality(optionValue=name, disabled=True)
+            for name in disabled])
+        self.assertThat(processors_control.controls, MatchesSetwise(*matchers))
+
     def test_initial_distroseries(self):
         # The initial distroseries is the newest that is current or in
         # development.
@@ -363,6 +385,47 @@
             }
         self.assertEqual(expected_args, parse_qs(parsed_location[3]))
 
+    def test_create_new_snap_display_processors(self):
+        branch = self.factory.makeAnyBranch()
+        distroseries = self.setUpDistroSeries()
+        browser = self.getViewBrowser(
+            branch, view_name="+new-snap", user=self.person)
+        processors = browser.getControl(name="field.processors")
+        self.assertContentEqual(
+            ["Intel 386 (386)", "AMD 64bit (amd64)", "HPPA Processor (hppa)"],
+            [extract_text(option) for option in processors.displayOptions])
+        self.assertContentEqual(["386", "amd64", "hppa"], processors.options)
+        self.assertContentEqual([], processors.value)
+
+    def test_create_new_snap_display_restricted_processors(self):
+        # A restricted processor is shown disabled in the UI.
+        branch = self.factory.makeAnyBranch()
+        distroseries = self.setUpDistroSeries()
+        proc_armhf = self.factory.makeProcessor(
+            name="armhf", restricted=True, build_by_default=False)
+        self.factory.makeDistroArchSeries(
+            distroseries=distroseries, architecturetag="armhf",
+            processor=proc_armhf)
+        browser = self.getViewBrowser(
+            branch, view_name="+new-snap", user=self.person)
+        processors = browser.getControl(name="field.processors")
+        self.assertProcessorControls(
+            processors, ["386", "amd64", "hppa"], ["armhf"])
+
+    def test_create_new_snap_processors(self):
+        branch = self.factory.makeAnyBranch()
+        distroseries = self.setUpDistroSeries()
+        browser = self.getViewBrowser(
+            branch, view_name="+new-snap", user=self.person)
+        processors = browser.getControl(name="field.processors")
+        processors.value = ["386", "amd64"]
+        browser.getControl(name="field.name").value = "snap-name"
+        browser.getControl("Create snap package").click()
+        login_person(self.person)
+        snap = getUtility(ISnapSet).getByName(self.person, u"snap-name")
+        self.assertContentEqual(
+            ["386", "amd64"], [proc.name for proc in snap.processors])
+
     def test_initial_name_extraction_git(self):
         [git_ref] = self.factory.makeGitRefs()
         git_ref.repository.getBlob = FakeMethod(result='name: test-snap')

=== modified file 'lib/lp/snappy/interfaces/snap.py'
--- lib/lp/snappy/interfaces/snap.py	2016-05-28 00:21:40 +0000
+++ lib/lp/snappy/interfaces/snap.py	2016-06-29 21:46:52 +0000
@@ -543,3 +543,8 @@
 
         This only exists to keep lazr.restful happy.
         """
+
+    def availableProcessors():
+        """Return all architectures that are available to be enabled or
+        disabled for new snap packages.")
+        """

=== modified file 'lib/lp/snappy/model/snap.py'
--- lib/lp/snappy/model/snap.py	2016-05-28 00:21:40 +0000
+++ lib/lp/snappy/model/snap.py	2016-06-29 21:46:52 +0000
@@ -676,3 +676,12 @@
     def empty_list(self):
         """See `ISnapSet`."""
         return []
+
+    @classmethod
+    def availableProcessors(self):
+        """See `ISnapSet`."""
+        store = IMasterStore(Snap)
+        processors = store.find(
+            Processor,
+            Processor.id == DistroArchSeries.processor_id)
+        return processors.config(distinct=True)

=== modified file 'lib/lp/snappy/templates/snap-new.pt'
--- lib/lp/snappy/templates/snap-new.pt	2016-05-24 05:15:50 +0000
+++ lib/lp/snappy/templates/snap-new.pt	2016-06-29 21:46:52 +0000
@@ -49,6 +49,13 @@
             </p>
           </td>
         </tr>
+
+        <br/>
+
+        <tal:widget define="widget nocall:view/widgets/processors">
+          <metal:block use-macro="context/@@launchpad_form/widget_row" />
+        </tal:widget>
+
       </table>
     </metal:formbody>
   </div>

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : launchpad-reviewers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to