41
41
from collections import defaultdict
44
from zope.app.form.browser.boolwidgets import CheckBoxWidget
44
45
from zope.component import getUtility
45
46
from zope.event import notify
46
47
from zope.formlib import form
47
48
from zope.interface import implements
48
49
from zope.lifecycleevent import ObjectCreatedEvent
50
from zope.schema import Bool
49
51
from zope.security.interfaces import Unauthorized
51
53
from canonical.launchpad.browser.feeds import FeedsMixin
83
85
from lp.app.errors import NotFoundError
84
86
from lp.app.widgets.image import ImageChangeWidget
87
from lp.app.widgets.itemswidgets import LabeledMultiCheckBoxWidget
85
88
from lp.archivepublisher.interfaces.publisherconfig import (
87
90
IPublisherConfigSet,
104
107
IRegistryCollectionNavigationMenu,
105
108
RegistryCollectionActionMenuBase,
110
from lp.registry.browser.objectreassignment import ObjectReassignmentView
107
111
from lp.registry.browser.pillar import PillarBugsMenu
108
from lp.registry.browser.objectreassignment import ObjectReassignmentView
109
112
from lp.registry.interfaces.distribution import (
110
113
IDerivativeDistribution,
125
128
from lp.services.propertycache import cachedproperty
129
from lp.soyuz.browser.archive import EnableRestrictedFamiliesMixin
126
130
from lp.soyuz.browser.packagesearch import PackageSearchViewBase
127
131
from lp.soyuz.enums import ArchivePurpose
128
132
from lp.soyuz.interfaces.archive import IArchiveSet
133
from lp.soyuz.interfaces.processor import IProcessorFamilySet
131
136
class DistributionNavigation(
772
777
return self.context.count()
775
class DistributionAddView(LaunchpadFormView):
780
class RequireVirtualizedBuildersMixin:
781
"""A mixin that provides require_virtualized field support"""
783
def createRequireVirtualized(self):
786
__name__='require_virtualized',
787
title=u"Require virtualized builders",
789
u"Only build the distribution's packages on virtual "
793
def updateRequireVirtualized(self, require_virtualized, archive):
794
if archive.require_virtualized != require_virtualized:
795
archive.require_virtualized = require_virtualized
798
class DistributionAddView(LaunchpadFormView,
799
RequireVirtualizedBuildersMixin,
800
EnableRestrictedFamiliesMixin):
777
802
schema = IDistribution
778
803
label = "Register a new distribution"
789
814
"official_rosetta",
817
custom_widget('require_virtualized', CheckBoxWidget)
818
custom_widget('enabled_restricted_families', LabeledMultiCheckBoxWidget)
794
821
def page_title(self):
795
822
"""The page title."""
796
823
return self.label
825
def validate(self, data):
826
self.validate_enabled_restricted_families(
827
data, ENABLED_RESTRICTED_FAMILITES_ERROR_MSG)
830
def initial_values(self):
831
proc_family_set = getUtility(IProcessorFamilySet)
832
restricted_families = set(proc_family_set.getRestricted())
834
'enabled_restricted_families': restricted_families,
835
'require_virtualized': False,
799
839
def cancel_url(self):
800
840
"""See `LaunchpadFormView`."""
801
841
return canonical_url(self.context)
843
def setUpFields(self):
844
"""See `LaunchpadFormView`."""
845
LaunchpadFormView.setUpFields(self)
846
self.form_fields += self.createRequireVirtualized()
847
self.form_fields += self.createEnabledRestrictedFamilies(
848
u'The restricted architecture families on which the '
849
"distribution's main archive can build.")
803
851
@action("Save", name='save')
804
852
def save_action(self, action, data):
805
853
distribution = getUtility(IDistributionSet).new(
814
862
registrant=self.user,
864
archive = distribution.main_archive
865
self.updateRequireVirtualized(data['require_virtualized'], archive)
866
if archive.require_virtualized is True:
867
archive.enabled_restricted_families = (
868
data['enabled_restricted_families'])
816
870
notify(ObjectCreatedEvent(distribution))
817
871
self.next_url = canonical_url(distribution)
820
class DistributionEditView(RegistryEditFormView):
874
ENABLED_RESTRICTED_FAMILITES_ERROR_MSG = (
875
u"This distribution's main archive can not be restricted to "
876
'certain architectures unless the archive is also set '
877
'to build on virtualized builders.')
880
class DistributionEditView(RegistryEditFormView,
881
RequireVirtualizedBuildersMixin,
882
EnableRestrictedFamiliesMixin):
822
884
schema = IDistribution
841
904
custom_widget('icon', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
842
905
custom_widget('logo', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
843
906
custom_widget('mugshot', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
907
custom_widget('require_virtualized', CheckBoxWidget)
908
custom_widget('enabled_restricted_families', LabeledMultiCheckBoxWidget)
847
912
"""See `LaunchpadFormView`."""
848
913
return 'Change %s details' % self.context.displayname
915
def setUpFields(self):
916
"""See `LaunchpadFormView`."""
917
RegistryEditFormView.setUpFields(self)
918
self.form_fields += self.createRequireVirtualized()
919
self.form_fields += self.createEnabledRestrictedFamilies(
920
u'The restricted architecture families on which the '
921
"distribution's main archive can build.")
924
def initial_values(self):
926
'require_virtualized':
927
self.context.main_archive.require_virtualized,
928
'enabled_restricted_families':
929
self.context.main_archive.enabled_restricted_families,
850
932
def validate(self, data):
851
933
"""Constrain bug expiration to Launchpad Bugs tracker."""
852
934
# enable_bug_expiration is disabled by JavaScript when official_malone
856
938
if not official_malone:
857
939
data['enable_bug_expiration'] = False
941
# Validate enabled_restricted_families.
942
self.validate_enabled_restricted_families(
944
ENABLED_RESTRICTED_FAMILITES_ERROR_MSG)
946
def change_archive_fields(self, data):
947
# Update context.main_archive.
948
new_require_virtualized = data.get('require_virtualized')
949
if new_require_virtualized is not None:
950
self.updateRequireVirtualized(
951
new_require_virtualized, self.context.main_archive)
952
del(data['require_virtualized'])
953
new_enabled_restricted_families = data.get(
954
'enabled_restricted_families')
955
if new_enabled_restricted_families is not None:
956
if (set(self.context.main_archive.enabled_restricted_families) !=
957
set(new_enabled_restricted_families)):
958
self.context.main_archive.enabled_restricted_families = (
959
new_enabled_restricted_families)
960
del(data['enabled_restricted_families'])
962
@action("Change", name='change')
963
def change_action(self, action, data):
964
self.change_archive_fields(data)
965
self.updateContextFromData(data)
860
968
class DistributionSeriesBaseView(LaunchpadView):
861
969
"""A base view to list distroseries."""