1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Browser views for distributions."""
__metaclass__ = type
__all__ = [
'DerivativeDistributionOverviewMenu',
'DistributionAddView',
'DistributionArchiveMirrorsRSSView',
'DistributionArchiveMirrorsView',
'DistributionArchivesView',
'DistributionChangeMembersView',
'DistributionChangeMirrorAdminView',
'DistributionCountryArchiveMirrorsView',
'DistributionDisabledMirrorsView',
'DistributionEditView',
'DistributionFacets',
'DistributionNavigation',
'DistributionPPASearchView',
'DistributionPackageSearchView',
'DistributionPendingReviewMirrorsView',
'DistributionPublisherConfigView',
'DistributionReassignmentView',
'DistributionSeriesView',
'DistributionDerivativesView',
'DistributionSeriesMirrorsRSSView',
'DistributionSeriesMirrorsView',
'DistributionSetActionNavigationMenu',
'DistributionSetBreadcrumb',
'DistributionSetContextMenu',
'DistributionSetFacets',
'DistributionSetNavigation',
'DistributionSetView',
'DistributionSpecificationsMenu',
'DistributionUnofficialMirrorsView',
'DistributionView',
]
from collections import defaultdict
import datetime
from zope.component import getUtility
from zope.event import notify
from zope.formlib import form
from zope.interface import implements
from zope.lifecycleevent import ObjectCreatedEvent
from zope.security.interfaces import Unauthorized
from canonical.launchpad.browser.feeds import FeedsMixin
from canonical.launchpad.components.decoratedresultset import (
DecoratedResultSet,
)
from canonical.launchpad.helpers import english_list
from canonical.launchpad.webapp import (
ApplicationMenu,
canonical_url,
ContextMenu,
enabled_with_permission,
GetitemNavigation,
LaunchpadView,
Link,
Navigation,
NavigationMenu,
redirection,
StandardLaunchpadFacets,
stepthrough,
)
from canonical.launchpad.webapp.batching import BatchNavigator
from canonical.launchpad.webapp.breadcrumb import Breadcrumb
from canonical.launchpad.webapp.interfaces import ILaunchBag
from lp.answers.browser.faqtarget import FAQTargetNavigationMixin
from lp.answers.browser.questiontarget import (
QuestionTargetFacetMixin,
QuestionTargetTraversalMixin,
)
from lp.app.browser.launchpadform import (
action,
custom_widget,
LaunchpadFormView,
)
from lp.app.errors import NotFoundError
from lp.app.widgets.image import ImageChangeWidget
from lp.archivepublisher.interfaces.publisherconfig import (
IPublisherConfig,
IPublisherConfigSet,
)
from lp.blueprints.browser.specificationtarget import (
HasSpecificationsMenuMixin,
)
from lp.bugs.browser.bugtask import BugTargetTraversalMixin
from lp.bugs.browser.structuralsubscription import (
expose_structural_subscription_data_to_js,
StructuralSubscriptionMenuMixin,
StructuralSubscriptionTargetTraversalMixin,
)
from lp.registry.browser import (
add_subscribe_link,
RegistryEditFormView,
)
from lp.registry.browser.announcement import HasAnnouncementsView
from lp.registry.browser.menu import (
IRegistryCollectionNavigationMenu,
RegistryCollectionActionMenuBase,
)
from lp.registry.browser.pillar import PillarBugsMenu
from lp.registry.browser.objectreassignment import ObjectReassignmentView
from lp.registry.interfaces.distribution import (
IDerivativeDistribution,
IDistribution,
IDistributionMirrorMenuMarker,
IDistributionSet,
)
from lp.registry.interfaces.distributionmirror import (
IDistributionMirrorSet,
MirrorContent,
MirrorSpeed,
)
from lp.registry.interfaces.series import SeriesStatus
from lp.services.geoip.helpers import (
ipaddress_from_request,
request_country,
)
from lp.services.propertycache import cachedproperty
from lp.soyuz.browser.packagesearch import PackageSearchViewBase
from lp.soyuz.enums import ArchivePurpose
from lp.soyuz.interfaces.archive import IArchiveSet
class DistributionNavigation(
GetitemNavigation, BugTargetTraversalMixin, QuestionTargetTraversalMixin,
FAQTargetNavigationMixin, StructuralSubscriptionTargetTraversalMixin):
usedfor = IDistribution
@redirection('+source', status=301)
def redirect_source(self):
return canonical_url(self.context)
@stepthrough('+mirror')
def traverse_mirrors(self, name):
return self.context.getMirrorByName(name)
@stepthrough('+source')
def traverse_sources(self, name):
return self.context.getSourcePackage(name)
@stepthrough('+milestone')
def traverse_milestone(self, name):
return self.context.getMilestone(name)
@stepthrough('+announcement')
def traverse_announcement(self, name):
return self.context.getAnnouncement(name)
@stepthrough('+spec')
def traverse_spec(self, name):
return self.context.getSpecification(name)
@stepthrough('+archive')
def traverse_archive(self, name):
return self.context.getArchive(name)
class DistributionSetNavigation(Navigation):
usedfor = IDistributionSet
def traverse(self, name):
# Raise a 404 on an invalid distribution name
distribution = self.context.getByName(name)
if distribution is None:
raise NotFoundError(name)
return self.redirectSubTree(canonical_url(distribution))
class DistributionFacets(QuestionTargetFacetMixin, StandardLaunchpadFacets):
usedfor = IDistribution
enable_only = [
'overview',
'branches',
'bugs',
'answers',
'specifications',
'translations',
]
def specifications(self):
text = 'Blueprints'
summary = 'Feature specifications for %s' % self.context.displayname
return Link('', text, summary)
class DistributionSetBreadcrumb(Breadcrumb):
"""Builds a breadcrumb for an `IDistributionSet`."""
text = 'Distributions'
class DistributionSetFacets(StandardLaunchpadFacets):
usedfor = IDistributionSet
enable_only = ['overview', ]
class DistributionSetContextMenu(ContextMenu):
usedfor = IDistributionSet
links = ['products', 'distributions', 'people', 'meetings']
def distributions(self):
return Link('/distros/', 'View distributions')
def products(self):
return Link('/projects/', 'View projects')
def people(self):
return Link('/people/', 'View people')
def meetings(self):
return Link('/sprints/', 'View meetings')
class DistributionMirrorsNavigationMenu(NavigationMenu):
usedfor = IDistributionMirrorMenuMarker
facet = 'overview'
links = ('cdimage_mirrors',
'archive_mirrors',
'disabled_mirrors',
'pending_review_mirrors',
'unofficial_mirrors',
)
@property
def distribution(self):
"""Helper method to return the distribution object.
self.context is the view, so return *its* context.
"""
return self.context.context
def cdimage_mirrors(self):
text = 'CD mirrors'
return Link('+cdmirrors', text, icon='info')
def archive_mirrors(self):
text = 'Archive mirrors'
return Link('+archivemirrors', text, icon='info')
def newmirror(self):
text = 'Register mirror'
return Link('+newmirror', text, icon='add')
def _userCanSeeNonPublicMirrorListings(self):
"""Does the user have rights to see non-public mirrors listings?"""
user = getUtility(ILaunchBag).user
return (self.distribution.full_functionality
and user is not None
and user.inTeam(self.distribution.mirror_admin))
def disabled_mirrors(self):
text = 'Disabled mirrors'
enabled = self._userCanSeeNonPublicMirrorListings()
return Link('+disabledmirrors', text, enabled=enabled, icon='info')
def pending_review_mirrors(self):
text = 'Pending-review mirrors'
enabled = self._userCanSeeNonPublicMirrorListings()
return Link(
'+pendingreviewmirrors', text, enabled=enabled, icon='info')
def unofficial_mirrors(self):
text = 'Unofficial mirrors'
enabled = self._userCanSeeNonPublicMirrorListings()
return Link('+unofficialmirrors', text, enabled=enabled, icon='info')
class DistributionLinksMixin(StructuralSubscriptionMenuMixin):
"""A mixin to provide common links to menus."""
@enabled_with_permission('launchpad.Edit')
def edit(self):
text = 'Change details'
return Link('+edit', text, icon='edit')
class DistributionNavigationMenu(NavigationMenu, DistributionLinksMixin):
"""A menu of context actions."""
usedfor = IDistribution
facet = 'overview'
@enabled_with_permission("launchpad.Admin")
def pubconf(self):
text = "Configure publisher"
return Link("+pubconf", text, icon="edit")
@cachedproperty
def links(self):
return ['edit', 'pubconf', 'subscribe_to_bug_mail', 'edit_bug_mail']
class DistributionOverviewMenu(ApplicationMenu, DistributionLinksMixin):
usedfor = IDistribution
facet = 'overview'
links = [
'edit',
'branding',
'driver',
'search',
'members',
'mirror_admin',
'reassign',
'addseries',
'series',
'derivatives',
'milestones',
'top_contributors',
'builds',
'cdimage_mirrors',
'archive_mirrors',
'pending_review_mirrors',
'disabled_mirrors',
'unofficial_mirrors',
'newmirror',
'announce',
'announcements',
'ppas',
'configure_answers',
'configure_blueprints',
'configure_translations',
]
@enabled_with_permission('launchpad.Edit')
def branding(self):
text = 'Change branding'
return Link('+branding', text, icon='edit')
@enabled_with_permission('launchpad.Edit')
def driver(self):
text = 'Appoint driver'
summary = 'Someone with permission to set goals for all series'
return Link('+driver', text, summary, icon='edit')
@enabled_with_permission('launchpad.Edit')
def reassign(self):
text = 'Change maintainer'
return Link('+reassign', text, icon='edit')
def newmirror(self):
text = 'Register a new mirror'
enabled = self.context.full_functionality
return Link('+newmirror', text, enabled=enabled, icon='add')
def top_contributors(self):
text = 'More contributors'
return Link('+topcontributors', text, icon='info')
def cdimage_mirrors(self):
text = 'CD mirrors'
return Link('+cdmirrors', text, icon='info')
def archive_mirrors(self):
text = 'Archive mirrors'
return Link('+archivemirrors', text, icon='info')
def _userCanSeeNonPublicMirrorListings(self):
"""Does the user have rights to see non-public mirrors listings?"""
user = getUtility(ILaunchBag).user
return (self.context.full_functionality
and user is not None
and user.inTeam(self.context.mirror_admin))
def disabled_mirrors(self):
text = 'Disabled mirrors'
enabled = self._userCanSeeNonPublicMirrorListings()
return Link('+disabledmirrors', text, enabled=enabled, icon='info')
def pending_review_mirrors(self):
text = 'Pending-review mirrors'
enabled = self._userCanSeeNonPublicMirrorListings()
return Link(
'+pendingreviewmirrors', text, enabled=enabled, icon='info')
def unofficial_mirrors(self):
text = 'Unofficial mirrors'
enabled = self._userCanSeeNonPublicMirrorListings()
return Link('+unofficialmirrors', text, enabled=enabled, icon='info')
@enabled_with_permission('launchpad.Edit')
def members(self):
text = 'Change members team'
return Link('+selectmemberteam', text, icon='edit')
@enabled_with_permission('launchpad.Edit')
def mirror_admin(self):
text = 'Change mirror admins'
enabled = self.context.full_functionality
return Link('+selectmirroradmins', text, enabled=enabled, icon='edit')
def search(self):
text = 'Search packages'
return Link('+search', text, icon='search')
@enabled_with_permission('launchpad.Admin')
def addseries(self):
text = 'Add series'
return Link('+addseries', text, icon='add')
def series(self):
text = 'All series'
return Link('+series', text, icon='info')
def derivatives(self):
text = 'All derivatives'
return Link('+derivatives', text, icon='info')
def milestones(self):
text = 'All milestones'
return Link('+milestones', text, icon='info')
@enabled_with_permission('launchpad.Edit')
def announce(self):
text = 'Make announcement'
summary = 'Publish an item of news for this project'
return Link('+announce', text, summary, icon='add')
def announcements(self):
text = 'Read all announcements'
enabled = bool(self.context.getAnnouncements())
return Link('+announcements', text, icon='info', enabled=enabled)
def builds(self):
text = 'Builds'
return Link('+builds', text, icon='info')
def ppas(self):
text = 'Personal Package Archives'
return Link('+ppas', text, icon='info')
@enabled_with_permission('launchpad.Edit')
def configure_answers(self):
text = 'Configure support tracker'
summary = 'Allow users to ask questions on this project'
return Link('+edit', text, summary, icon='edit')
@enabled_with_permission('launchpad.Edit')
def configure_blueprints(self):
text = 'Configure blueprints'
summary = 'Enable tracking of feature planning.'
return Link('+edit', text, summary, icon='edit')
@enabled_with_permission('launchpad.TranslationsAdmin')
def configure_translations(self):
text = 'Configure translations'
summary = 'Allow users to provide translations for this project.'
return Link('+configure-translations', text, summary, icon='edit')
class DerivativeDistributionOverviewMenu(DistributionOverviewMenu):
usedfor = IDerivativeDistribution
@enabled_with_permission('launchpad.Moderate')
def addseries(self):
text = 'Add series'
return Link('+addseries', text, icon='add')
class DistributionBugsMenu(PillarBugsMenu):
usedfor = IDistribution
facet = 'bugs'
@property
def links(self):
links = [
'bugsupervisor',
'securitycontact',
'cve',
'filebug',
]
add_subscribe_link(links)
return links
class DistributionSpecificationsMenu(NavigationMenu,
HasSpecificationsMenuMixin):
usedfor = IDistribution
facet = 'specifications'
links = ['listall', 'doc', 'assignments', 'new', 'register_sprint']
class DistributionPackageSearchView(PackageSearchViewBase):
"""Customised PackageSearchView for Distribution"""
def initialize(self):
"""Save the search type if provided."""
super(DistributionPackageSearchView, self).initialize()
# If the distribution contains binary packages, then we'll
# default to searches on binary names, but allow the user to
# select.
if self.context.has_published_binaries:
self.search_type = self.request.get("search_type", 'binary')
else:
self.search_type = 'source'
def contextSpecificSearch(self):
"""See `AbstractPackageSearchView`."""
if self.search_by_binary_name:
return self.context.searchBinaryPackages(self.text)
else:
non_exact_matches = self.context.searchSourcePackageCaches(
self.text)
# The searchBinaryPackageCaches() method returns tuples, so we
# use the DecoratedResultSet here to just get the
# DistributionSourcePackag objects for the template.
def tuple_to_package_cache(cache_name_tuple):
return cache_name_tuple[0]
non_exact_matches = DecoratedResultSet(
non_exact_matches, tuple_to_package_cache)
return non_exact_matches.config(distinct=True)
@property
def search_by_binary_name(self):
"""Return whether the search is on binary names.
By default, we search by binary names, as this produces much
better results. But the user may decide to search by sources, or
in the case of other distributions, it will be the only option.
"""
return self.search_type == "binary"
@property
def source_search_url(self):
"""Return the equivalent search on source packages.
By default, we search by binary names, but also provide a link
to the equivalent source package search in some circumstances.
"""
return "%s/+search?search_type=source&%s" % (
canonical_url(self.context),
self.request.get('QUERY_STRING'),
)
@cachedproperty
def exact_matches(self):
return self.context.searchBinaryPackages(
self.text, exact_match=True).order_by('name')
@property
def has_exact_matches(self):
return self.exact_matches.count() > 0
@property
def has_matches(self):
return self.matches > 0
@cachedproperty
def matching_binary_names(self):
"""Define the matching binary names for each result in the batch."""
names = {}
for package_cache in self.batchnav.currentBatch():
names[package_cache.name] = self._listFirstFiveMatchingNames(
self.text, package_cache.binpkgnames)
return names
def _listFirstFiveMatchingNames(self, match_text, space_separated_list):
"""Returns a comma-separated list of the first five matching items"""
name_list = space_separated_list.split(' ')
matching_names = [
name for name in name_list if match_text in name]
if len(matching_names) > 5:
matching_names = matching_names[:5]
matching_names.append('...')
return ", ".join(matching_names)
@cachedproperty
def distroseries_names(self):
"""Define the distroseries for each package name in exact matches."""
names = {}
for package_cache in self.exact_matches:
package = package_cache.distributionsourcepackage
# In the absense of Python3.0's set comprehension, we
# create a list, convert the list to a set and back again:
distroseries_list = [
pubrec.distroseries.name
for pubrec in package.current_publishing_records
if pubrec.distroseries.active]
distroseries_list = list(set(distroseries_list))
# Yay for alphabetical series names.
distroseries_list.sort()
names[package.name] = ", ".join(distroseries_list)
return names
@property
def display_exact_matches(self):
"""Return whether exact match results should be displayed."""
if not self.search_by_binary_name:
return False
if self.batchnav.start > 0:
return False
return self.has_exact_matches
class DistributionView(HasAnnouncementsView, FeedsMixin):
"""Default Distribution view class."""
def initialize(self):
super(DistributionView, self).initialize()
expose_structural_subscription_data_to_js(
self.context, self.request, self.user)
def linkedMilestonesForSeries(self, series):
"""Return a string of linkified milestones in the series."""
# Listify to remove repeated queries.
milestones = list(series.milestones)
if len(milestones) == 0:
return ""
linked_milestones = []
for milestone in milestones:
linked_milestones.append(
"<a href=%s>%s</a>" % (
canonical_url(milestone), milestone.name))
return english_list(linked_milestones)
@cachedproperty
def latest_derivatives(self):
"""The 5 most recent derivatives."""
return self.context.derivatives[:5]
class DistributionArchivesView(LaunchpadView):
@property
def batchnav(self):
"""Return the batch navigator for the archives."""
return BatchNavigator(self.archive_list, self.request)
@cachedproperty
def archive_list(self):
"""Returns the list of archives for the given distribution.
The context may be an IDistroSeries or a users archives.
"""
results = getUtility(IArchiveSet).getArchivesForDistribution(
self.context, purposes=[ArchivePurpose.COPY], user=self.user,
exclude_disabled=False)
return results.order_by('date_created DESC')
class DistributionPPASearchView(LaunchpadView):
"""Search PPAs belonging to the Distribution in question."""
page_title = "Personal Package Archives"
def initialize(self):
self.name_filter = self.request.get('name_filter')
if isinstance(self.name_filter, list):
# This happens if someone hand-hacks the URL so that it has
# more than one name_filter field. We could do something
# like form.getOne() so that the request would be rejected,
# but we can acutally do better and join the terms supplied
# instead.
self.name_filter = " ".join(self.name_filter)
self.show_inactive = self.request.get('show_inactive')
@property
def label(self):
return 'Personal Package Archives for %s' % self.context.title
@property
def search_results(self):
"""Process search form request."""
if self.name_filter is None:
return None
# Preserve self.show_inactive state because it's used in the
# template and build a boolean field to be passed for
# searchPPAs.
show_inactive = (self.show_inactive == 'on')
ppas = self.context.searchPPAs(
text=self.name_filter, show_inactive=show_inactive,
user=self.user)
self.batchnav = BatchNavigator(ppas, self.request)
return self.batchnav.currentBatch()
@property
def number_of_registered_ppas(self):
"""The number of archives with PPA purpose.
It doesn't include private PPAs.
"""
return self.context.searchPPAs(show_inactive=True).count()
@property
def number_of_active_ppas(self):
"""The number of PPAs with at least one source publication.
It doesn't include private PPAs.
"""
return self.context.searchPPAs(show_inactive=False).count()
@property
def number_of_ppa_sources(self):
"""The number of sources published across all PPAs."""
return getUtility(IArchiveSet).getNumberOfPPASourcesForDistribution(
self.context)
@property
def number_of_ppa_binaries(self):
"""The number of binaries published across all PPAs."""
return getUtility(IArchiveSet).getNumberOfPPABinariesForDistribution(
self.context)
@property
def latest_ppa_source_publications(self):
"""Return the last 5 sources publication in the context PPAs."""
archive_set = getUtility(IArchiveSet)
return archive_set.getLatestPPASourcePublicationsForDistribution(
distribution=self.context)
@property
def most_active_ppas(self):
"""Return the last 5 most active PPAs."""
archive_set = getUtility(IArchiveSet)
return archive_set.getMostActivePPAsForDistribution(
distribution=self.context)
class DistributionSetActionNavigationMenu(RegistryCollectionActionMenuBase):
"""Action menu for `DistributionSetView`."""
usedfor = IDistributionSet
links = [
'register_team', 'register_project', 'register_distribution',
'create_account']
class DistributionSetView(LaunchpadView):
"""View for /distros top level collection."""
implements(IRegistryCollectionNavigationMenu)
page_title = 'Distributions registered in Launchpad'
@cachedproperty
def count(self):
return self.context.count()
class DistributionAddView(LaunchpadFormView):
schema = IDistribution
label = "Register a new distribution"
field_names = [
"name",
"displayname",
"title",
"summary",
"description",
"domainname",
"members",
"official_malone",
"blueprints_usage",
"official_rosetta",
"answers_usage",
]
@property
def page_title(self):
"""The page title."""
return self.label
@property
def cancel_url(self):
"""See `LaunchpadFormView`."""
return canonical_url(self.context)
@action("Save", name='save')
def save_action(self, action, data):
distribution = getUtility(IDistributionSet).new(
name=data['name'],
displayname=data['displayname'],
title=data['title'],
summary=data['summary'],
description=data['description'],
domainname=data['domainname'],
members=data['members'],
owner=self.user,
registrant=self.user,
)
notify(ObjectCreatedEvent(distribution))
self.next_url = canonical_url(distribution)
class DistributionEditView(RegistryEditFormView):
schema = IDistribution
field_names = [
'displayname',
'title',
'summary',
'description',
'bug_reporting_guidelines',
'bug_reported_acknowledgement',
'icon',
'logo',
'mugshot',
'official_malone',
'enable_bug_expiration',
'blueprints_usage',
'official_rosetta',
'answers_usage',
'translation_focus',
]
custom_widget('icon', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
custom_widget('logo', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
custom_widget('mugshot', ImageChangeWidget, ImageChangeWidget.EDIT_STYLE)
@property
def label(self):
"""See `LaunchpadFormView`."""
return 'Change %s details' % self.context.displayname
def validate(self, data):
"""Constrain bug expiration to Launchpad Bugs tracker."""
# enable_bug_expiration is disabled by JavaScript when official_malone
# is set False. The contraint is enforced here in case the JavaScript
# fails to load or activate.
official_malone = data.get('official_malone', False)
if not official_malone:
data['enable_bug_expiration'] = False
class DistributionSeriesBaseView(LaunchpadView):
"""A base view to list distroseries."""
@cachedproperty
def styled_series(self):
"""A list of dicts; keys: series, css_class, is_development_focus"""
all_series = []
for series in self._displayed_series:
all_series.append({
'series': series,
'css_class': self.getCssClass(series),
})
return all_series
def getCssClass(self, series):
"""The highlight, lowlight, or normal CSS class."""
if series.status == SeriesStatus.DEVELOPMENT:
return 'highlight'
elif series.status == SeriesStatus.OBSOLETE:
return 'lowlight'
else:
# This is normal presentation.
return ''
class DistributionSeriesView(DistributionSeriesBaseView):
"""A view to list the distribution series."""
label = 'Timeline'
show_add_series_link = True
show_milestones_link = True
@property
def _displayed_series(self):
return self.context.series
class DistributionDerivativesView(DistributionSeriesBaseView):
"""A view to list the distribution derivatives."""
label = 'Derivatives'
show_add_series_link = False
show_milestones_link = False
@property
def _displayed_series(self):
return self.context.derivatives
class DistributionChangeMirrorAdminView(RegistryEditFormView):
"""A view to change the mirror administrator."""
schema = IDistribution
field_names = ['mirror_admin']
@property
def label(self):
"""See `LaunchpadFormView`."""
return "Change the %s mirror administrator" % self.context.displayname
class DistributionChangeMembersView(RegistryEditFormView):
"""A view to change the members team."""
schema = IDistribution
field_names = ['members']
@property
def label(self):
"""See `LaunchpadFormView`."""
return "Change the %s members team" % self.context.displayname
class DistributionCountryArchiveMirrorsView(LaunchpadView):
"""A text/plain page that lists the mirrors in the country of the request.
If there are no mirrors located in the country of the request, we fallback
to the main Ubuntu repositories.
"""
implements(IDistributionMirrorMenuMarker)
def render(self):
request = self.request
if not self.context.full_functionality:
request.response.setStatus(404)
return u''
ip_address = ipaddress_from_request(request)
country = request_country(request)
mirrors = getUtility(IDistributionMirrorSet).getBestMirrorsForCountry(
country, MirrorContent.ARCHIVE)
body = "\n".join(mirror.base_url for mirror in mirrors)
request.response.setHeader('content-type', 'text/plain;charset=utf-8')
if country is None:
country_name = 'Unknown'
else:
country_name = country.name
request.response.setHeader('X-Generated-For-Country', country_name)
request.response.setHeader('X-Generated-For-IP', ip_address)
# XXX: Guilherme Salgado 2008-01-09 bug=173729: These are here only
# for debugging.
request.response.setHeader(
'X-REQUEST-HTTP_X_FORWARDED_FOR',
request.get('HTTP_X_FORWARDED_FOR'))
request.response.setHeader(
'X-REQUEST-REMOTE_ADDR', request.get('REMOTE_ADDR'))
return body.encode('utf-8')
class DistributionMirrorsView(LaunchpadView):
implements(IDistributionMirrorMenuMarker)
show_freshness = True
show_mirror_type = False
description = None
@cachedproperty
def mirror_count(self):
return self.mirrors.count()
def _sum_throughput(self, mirrors):
"""Given a list of mirrors, calculate the total bandwidth
available.
"""
throughput = 0
# this would be a wonderful place to have abused DBItem.sort_key ;-)
for mirror in mirrors:
if mirror.speed == MirrorSpeed.S128K:
throughput += 128
elif mirror.speed == MirrorSpeed.S256K:
throughput += 256
elif mirror.speed == MirrorSpeed.S512K:
throughput += 512
elif mirror.speed == MirrorSpeed.S1M:
throughput += 1000
elif mirror.speed == MirrorSpeed.S2M:
throughput += 2000
elif mirror.speed == MirrorSpeed.S10M:
throughput += 10000
elif mirror.speed == MirrorSpeed.S45M:
throughput += 45000
elif mirror.speed == MirrorSpeed.S100M:
throughput += 100000
elif mirror.speed == MirrorSpeed.S1G:
throughput += 1000000
elif mirror.speed == MirrorSpeed.S2G:
throughput += 2000000
elif mirror.speed == MirrorSpeed.S4G:
throughput += 4000000
elif mirror.speed == MirrorSpeed.S10G:
throughput += 10000000
elif mirror.speed == MirrorSpeed.S20G:
throughput += 20000000
else:
# need to be made aware of new values in
# interfaces/distributionmirror.py MirrorSpeed
return 'Indeterminate'
if throughput < 1000:
return str(throughput) + ' Kbps'
elif throughput < 1000000:
return str(throughput / 1000) + ' Mbps'
else:
return str(throughput / 1000000) + ' Gbps'
@cachedproperty
def total_throughput(self):
return self._sum_throughput(self.mirrors)
def getMirrorsGroupedByCountry(self):
"""Given a list of mirrors, create and return list of dictionaries
containing the country names and the list of mirrors on that country.
This list is ordered by country name.
"""
mirrors_by_country = defaultdict(list)
for mirror in self.mirrors:
mirrors_by_country[mirror.country.name].append(mirror)
return [dict(country=country,
mirrors=mirrors,
number=len(mirrors),
throughput=self._sum_throughput(mirrors))
for country, mirrors in sorted(mirrors_by_country.items())]
class DistributionArchiveMirrorsView(DistributionMirrorsView):
heading = 'Official Archive Mirrors'
description = ('These mirrors provide repositories and archives of all '
'software for the distribution.')
@cachedproperty
def mirrors(self):
return self.context.archive_mirrors_by_country
@cachedproperty
def mirror_count(self):
return len(self.mirrors)
class DistributionSeriesMirrorsView(DistributionMirrorsView):
heading = 'Official CD Mirrors'
description = ('These mirrors offer ISO images which you can download '
'and burn to CD to make installation disks.')
show_freshness = False
@cachedproperty
def mirrors(self):
return self.context.cdimage_mirrors_by_country
@cachedproperty
def mirror_count(self):
return len(self.mirrors)
class DistributionMirrorsRSSBaseView(LaunchpadView):
"""A base class for RSS feeds of distribution mirrors."""
def initialize(self):
self.now = datetime.datetime.utcnow()
def render(self):
self.request.response.setHeader(
'content-type', 'text/xml;charset=utf-8')
body = LaunchpadView.render(self)
return body.encode('utf-8')
class DistributionArchiveMirrorsRSSView(DistributionMirrorsRSSBaseView):
"""The RSS feed for archive mirrors."""
heading = 'Archive Mirrors'
@cachedproperty
def mirrors(self):
return self.context.archive_mirrors
class DistributionSeriesMirrorsRSSView(DistributionMirrorsRSSBaseView):
"""The RSS feed for series mirrors."""
heading = 'CD Mirrors'
@cachedproperty
def mirrors(self):
return self.context.cdimage_mirrors
class DistributionMirrorsAdminView(DistributionMirrorsView):
def initialize(self):
"""Raise an Unauthorized exception if the user is not a member of this
distribution's mirror_admin team.
"""
# XXX: Guilherme Salgado 2006-06-16:
# We don't want these pages to be public but we can't protect
# them with launchpad.Edit because that would mean only people with
# that permission on a Distribution would be able to see them. That's
# why we have to do the permission check here.
if not (self.user and self.user.inTeam(self.context.mirror_admin)):
raise Unauthorized('Forbidden')
class DistributionUnofficialMirrorsView(DistributionMirrorsAdminView):
heading = 'Unofficial Mirrors'
@cachedproperty
def mirrors(self):
return self.context.unofficial_mirrors
class DistributionPendingReviewMirrorsView(DistributionMirrorsAdminView):
heading = 'Pending-review mirrors'
show_mirror_type = True
show_freshness = False
@cachedproperty
def mirrors(self):
return self.context.pending_review_mirrors
class DistributionDisabledMirrorsView(DistributionMirrorsAdminView):
heading = 'Disabled Mirrors'
@cachedproperty
def mirrors(self):
return self.context.disabled_mirrors
class DistributionReassignmentView(ObjectReassignmentView):
"""View class for changing distribution maintainer."""
ownerOrMaintainerName = 'maintainer'
class DistributionPublisherConfigView(LaunchpadFormView):
"""View class for configuring publisher options for a DistroSeries.
It redirects to the main distroseries page after a successful edit.
"""
schema = IPublisherConfig
field_names = ['root_dir', 'base_url', 'copy_base_url']
@property
def label(self):
"""See `LaunchpadFormView`."""
return 'Publisher configuration for %s' % self.context.title
@property
def page_title(self):
"""The page title."""
return self.label
@property
def cancel_url(self):
"""See `LaunchpadFormView`."""
return canonical_url(self.context)
@property
def initial_values(self):
"""If the config already exists, set up the fields with data."""
config = getUtility(
IPublisherConfigSet).getByDistribution(self.context)
values = {}
if config is not None:
for name in self.field_names:
values[name] = getattr(config, name)
return values
@action("Save")
def save_action(self, action, data):
"""Update the context and redirect to its overview page."""
config = getUtility(IPublisherConfigSet).getByDistribution(
self.context)
if config is None:
config = getUtility(IPublisherConfigSet).new(
distribution=self.context,
root_dir=data['root_dir'],
base_url=data['base_url'],
copy_base_url=data['copy_base_url'])
else:
form.applyChanges(config, self.form_fields, data, self.adapters)
self.request.response.addInfoNotification(
'Your changes have been applied.')
self.next_url = canonical_url(self.context)
|