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
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0211,E0213
"""Publishing interfaces."""
__metaclass__ = type
__all__ = [
'IArchiveSafePublisher',
'IBinaryPackageFilePublishing',
'IBinaryPackagePublishingHistory',
'IBinaryPackagePublishingHistoryPublic',
'ICanPublishPackages',
'IFilePublishing',
'IPublishingEdit',
'IPublishingSet',
'ISourcePackageFilePublishing',
'ISourcePackagePublishingHistory',
'ISourcePackagePublishingHistoryPublic',
'MissingSymlinkInPool',
'NotInPool',
'PoolFileOverwriteError',
'active_publishing_status',
'inactive_publishing_status',
'name_priority_map',
]
from lazr.restful.declarations import (
call_with,
export_as_webservice_entry,
export_operation_as,
export_read_operation,
export_write_operation,
exported,
operation_for_version,
operation_parameters,
operation_returns_collection_of,
REQUEST_USER,
)
from lazr.restful.fields import Reference
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import (
Bool,
Choice,
Date,
Datetime,
Int,
Text,
TextLine,
)
from lp import _
from lp.registry.interfaces.distroseries import IDistroSeries
from lp.registry.interfaces.person import IPerson
from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.soyuz.enums import (
PackagePublishingPriority,
PackagePublishingStatus,
)
from lp.soyuz.interfaces.binarypackagerelease import (
IBinaryPackageReleaseDownloadCount,
)
#
# Exceptions
#
class NotInPool(Exception):
"""Raised when an attempt is made to remove a non-existent file."""
class PoolFileOverwriteError(Exception):
"""Raised when an attempt is made to overwrite a file in the pool.
The proposed file has different content as the one in pool.
This exception is unexpected and when it happens we keep the original
file in pool and print a warning in the publisher log. It probably
requires manual intervention in the archive.
"""
class MissingSymlinkInPool(Exception):
"""Raised when there is a missing symlink in pool.
This condition is ignored, similarly to what we do for `NotInPool`,
since the pool entry requested to be removed is not there anymore.
The corresponding record is marked as removed and the process
continues.
"""
name_priority_map = {
'required': PackagePublishingPriority.REQUIRED,
'important': PackagePublishingPriority.IMPORTANT,
'standard': PackagePublishingPriority.STANDARD,
'optional': PackagePublishingPriority.OPTIONAL,
'extra': PackagePublishingPriority.EXTRA,
'': None,
}
#
# Base Interfaces
#
class ICanPublishPackages(Interface):
"""Denotes the ability to publish associated publishing records."""
def getPendingPublications(archive, pocket, is_careful):
"""Return the specific group of records to be published.
IDistroSeries -> ISourcePackagePublishing
IDistroArchSeries -> IBinaryPackagePublishing
'pocket' & 'archive' are mandatory arguments, they restrict the
results to the given value.
If the distroseries is already released, it automatically refuses
to publish records to RELEASE pocket.
"""
def publish(diskpool, log, archive, pocket, careful=False):
"""Publish associated publishing records targeted for a given pocket.
Require an initialized diskpool instance and a logger instance.
Require an 'archive' which will restrict the publications.
'careful' argument would cause the 'republication' of all published
records if True (system will DTRT checking hash of all
published files.)
Consider records returned by the local implementation of
getPendingPublications.
"""
class IArchiveSafePublisher(Interface):
"""Safe Publication methods"""
def setPublished():
"""Set a publishing record to published.
Basically set records to PUBLISHED status only when they
are PENDING and do not update datepublished value of already
published field when they were checked via 'careful'
publishing.
"""
class IPublishingView(Interface):
"""Base interface for all Publishing classes"""
files = Attribute("Files included in this publication.")
displayname = exported(
TextLine(
title=_("Display Name"),
description=_("Text representation of the current record.")),
exported_as="display_name")
age = Attribute("Age of the publishing record.")
component_name = exported(
TextLine(
title=_("Component Name"),
required=False, readonly=True))
section_name = exported(
TextLine(
title=_("Section Name"),
required=False, readonly=True))
def publish(diskpool, log):
"""Publish or ensure contents of this publish record
Skip records which attempt to overwrite the archive (same file paths
with different content) and do not update the database.
If all the files get published correctly update its status properly.
"""
def getIndexStanza():
"""Return archive index stanza contents
It's based on the locally provided buildIndexStanzaTemplate method,
which differs for binary and source instances.
"""
def buildIndexStanzaFields():
"""Build a map of fields and values to be in the Index file.
The fields and values ae mapped into a dictionary, where the key is
the field name and value is the value string.
"""
def requestObsolescence():
"""Make this publication obsolete.
:return: The obsoleted publishing record, either:
`ISourcePackagePublishingHistory` or
`IBinaryPackagePublishingHistory`.
"""
def getAncestry(archive=None, distroseries=None, pocket=None,
status=None):
"""Return the most recent publication of the same source or binary.
If a suitable ancestry could not be found, None is returned.
It optionally accepts parameters for adjusting the publishing
context, if not given they default to the current context.
:param archive: optional `IArchive`, defaults to the context archive.
:param distroseries: optional `IDistroSeries`, defaults to the
context distroseries.
:param pocket: optional `PackagePublishingPocket`, defaults to any
pocket.
:param status: optional `PackagePublishingStatus` or a collection of
them, defaults to `PackagePublishingStatus.PUBLISHED`
"""
def overrideFromAncestry():
"""Set the right published component from publishing ancestry.
Start with the publishing records and fall back to the original
uploaded package if necessary.
:raise: AssertionError if the context publishing record is not in
PENDING status.
"""
class IPublishingEdit(Interface):
"""Base interface for writeable Publishing classes."""
def requestDeletion(removed_by, removal_comment=None):
"""Delete this publication.
:param removed_by: `IPerson` responsible for the removal.
:param removal_comment: optional text describing the removal reason.
"""
@call_with(removed_by=REQUEST_USER)
@operation_parameters(
removal_comment=TextLine(title=_("Removal comment"), required=False))
@export_operation_as("requestDeletion")
@export_write_operation()
def api_requestDeletion(removed_by, removal_comment=None):
"""Delete this source and its binaries.
:param removed_by: `IPerson` responsible for the removal.
:param removal_comment: optional text describing the removal reason.
"""
# This is a special API method that allows a different code path
# to the regular requestDeletion(). In the case of sources
# getting deleted, it ensures source and binaries are both
# deleted in tandem.
class IFilePublishing(Interface):
"""Base interface for *FilePublishing classes"""
distribution = Int(
title=_('Distribution ID'), required=True, readonly=True,
)
distroseriesname = TextLine(
title=_('Series name'), required=True, readonly=True,
)
componentname = TextLine(
title=_('Component name'), required=True, readonly=True,
)
publishingstatus = Int(
title=_('Package publishing status'), required=True,
readonly=True,
)
pocket = Int(
title=_('Package publishing pocket'), required=True,
readonly=True,
)
archive = Int(
title=_('Archive ID'), required=True, readonly=True,
)
libraryfilealias = Int(
title=_('Binarypackage file alias'), required=True,
readonly=True,
)
libraryfilealiasfilename = TextLine(
title=_('File name'), required=True, readonly=True,
)
archive_url = Attribute('The on-archive URL for the published file.')
publishing_record = Attribute(
"Return the Source or Binary publishing record "
"(in the form of I{Source,Binary}PackagePublishingHistory).")
def publish(diskpool, log):
"""Publish or ensure contents of this file in the archive.
Create symbolic link to files already present in different component
or add file from librarian if it's not present. Update the database
to represent the current archive state.
"""
#
# Source package publishing
#
class ISourcePackageFilePublishing(IFilePublishing):
"""Source package release files and their publishing status"""
file_type_name = Attribute(
"The uploaded file's type; one of 'orig', 'dsc', 'diff' or 'other'")
sourcepackagename = TextLine(
title=_('Binary package name'), required=True, readonly=True,
)
sourcepackagepublishing = Int(
title=_('Sourcepackage publishing record id'), required=True,
readonly=True,
)
class ISourcePackagePublishingHistoryPublic(IPublishingView):
"""A source package publishing history record."""
id = Int(
title=_('ID'), required=True, readonly=True,
)
sourcepackagenameID = Int(
title=_('The DB id for the sourcepackagename.'),
required=False, readonly=False)
sourcepackagename = Attribute('The source package name being published')
sourcepackagereleaseID = Int(
title=_('The DB id for the sourcepackagerelease.'),
required=False, readonly=False)
sourcepackagerelease = Attribute(
'The source package release being published')
status = exported(
Choice(
title=_('Package Publishing Status'),
description=_('The status of this publishing record'),
vocabulary=PackagePublishingStatus,
required=False, readonly=False,
))
distroseriesID = Attribute("DB ID for distroseries.")
distroseries = exported(
Reference(
IDistroSeries,
title=_('The distro series being published into'),
required=False, readonly=False,
),
exported_as="distro_series")
component = Int(
title=_('The component being published into'),
required=False, readonly=False,
)
sectionID = Attribute("DB ID for the section")
section = Int(
title=_('The section being published into'),
required=False, readonly=False,
)
datepublished = exported(
Datetime(
title=_('The date on which this record was published'),
required=False, readonly=False,
),
exported_as="date_published")
scheduleddeletiondate = exported(
Datetime(
title=_('The date on which this record is scheduled for '
'deletion'),
required=False, readonly=False,
),
exported_as="scheduled_deletion_date")
pocket = exported(
Choice(
title=_('Pocket'),
description=_('The pocket into which this entry is published'),
vocabulary=PackagePublishingPocket,
required=True, readonly=True,
))
archive = exported(
Reference(
# Really IArchive (fixed in _schema_circular_imports.py).
Interface,
title=_('Archive ID'), required=True, readonly=True,
))
supersededby = Int(
title=_('The sourcepackagerelease which superseded this one'),
required=False, readonly=False,
)
datesuperseded = exported(
Datetime(
title=_('The date on which this record was marked superseded'),
required=False, readonly=False,
),
exported_as="date_superseded")
datecreated = exported(
Datetime(
title=_('The date on which this record was created'),
required=True, readonly=False,
),
exported_as="date_created")
datemadepending = exported(
Datetime(
title=_('The date on which this record was set as pending '
'removal'),
required=False, readonly=False,
),
exported_as="date_made_pending")
dateremoved = exported(
Datetime(
title=_('The date on which this record was removed from the '
'published set'),
required=False, readonly=False,
),
exported_as="date_removed")
removed_by = exported(
Reference(
IPerson,
title=_('The IPerson responsible for the removal'),
required=False, readonly=False,
))
removal_comment = exported(
Text(
title=_('Reason why this publication is going to be removed.'),
required=False, readonly=False,
))
meta_sourcepackage = Attribute(
"Return an ISourcePackage meta object correspondent to the "
"sourcepackagerelease attribute inside a specific distroseries")
meta_sourcepackagerelease = Attribute(
"Return an IDistributionSourcePackageRelease meta object "
"correspondent to the sourcepackagerelease attribute")
meta_supersededby = Attribute(
"Return an IDistributionSourcePackageRelease meta object "
"correspondent to the supersededby attribute. if supersededby "
"is None return None.")
meta_distroseriessourcepackagerelease = Attribute(
"Return an IDistroSeriesSourcePackageRelease meta object "
"correspondent to the sourcepackagerelease attribute inside "
"a specific distroseries")
source_package_name = exported(
TextLine(
title=_("Source Package Name"),
required=False, readonly=True))
source_package_version = exported(
TextLine(
title=_("Source Package Version"),
required=False, readonly=True))
package_creator = exported(
Reference(
IPerson,
title=_('Package Creator'),
description=_('The IPerson who created the source package.'),
required=False, readonly=True,
))
package_maintainer = exported(
Reference(
IPerson,
title=_('Package Maintainer'),
description=_('The IPerson who maintains the source package.'),
required=False, readonly=True,
))
package_signer = exported(
Reference(
IPerson,
title=_('Package Signer'),
description=_('The IPerson who signed the source package.'),
required=False, readonly=True,
))
newer_distroseries_version = Attribute(
"An `IDistroSeriosSourcePackageRelease` with a newer version of this "
"package that has been published in the main distribution series, "
"if one exists, or None.")
ancestor = Reference(
# Really ISourcePackagePublishingHistory (fixed in
# _schema_circular_imports.py).
Interface,
title=_('Ancestor'),
description=_('The previous release of this source package.'),
required=False, readonly=True)
creator = exported(
Reference(
IPerson,
title=_('Publication Creator'),
description=_('The IPerson who created this publication.'),
required=False, readonly=True
))
# Really IBinaryPackagePublishingHistory, see below.
@operation_returns_collection_of(Interface)
@export_read_operation()
def getPublishedBinaries():
"""Return all resulted `IBinaryPackagePublishingHistory`.
Follow the build record and return every PUBLISHED or PENDING
binary publishing record for any `DistroArchSeries` in this
`DistroSeries` and in the same `IArchive` and Pocket, ordered
by architecture tag.
:return: a list with all corresponding publishing records.
"""
def getBuiltBinaries():
"""Return all unique binary publications built by this source.
Follow the build record and return every unique binary publishing
record in the context `DistroSeries` and in the same `IArchive`
and Pocket.
There will be only one entry for architecture independent binary
publications.
:return: a list containing all unique
`IBinaryPackagePublishingHistory`.
"""
# Really IBuild (fixed in _schema_circular_imports.py)
@operation_returns_collection_of(Interface)
@export_read_operation()
def getBuilds():
"""Return a list of `IBuild` objects in this publishing context.
The builds are ordered by `DistroArchSeries.architecturetag`.
:return: a list of `IBuilds`.
"""
def getFileByName(name):
"""Return the file with the specified name.
Only supports 'changelog' at present.
"""
@export_read_operation()
def changesFileUrl():
"""The .changes file URL for this source publication.
:return: the .changes file URL for this source (a string).
"""
@export_read_operation()
@operation_for_version('devel')
def changelogUrl():
"""The URL for this source package release's changelog.
:return: the changelog file URL for this source (a string).
"""
def getUnpublishedBuilds(build_states=None):
"""Return a resultset of `IBuild` objects in this context that are
not published.
Note that this is convenience glue for
PublishingSet.getUnpublishedBuildsForSources - and that method should
be considered authoritative.
:param build_states: list of build states to which the result should
be limited. Defaults to BuildStatus.FULLYBUILT if none are
specified.
:return: a result set of `IBuilds`.
"""
def createMissingBuilds(architectures_available=None, pas_verify=None,
logger=None):
"""Create missing Build records for a published source.
P-a-s should be used when accepting sources to the PRIMARY archive
(in drescher). It explicitly ignores given P-a-s for sources
targeted to PPAs.
:param architectures_available: options list of `DistroArchSeries`
that should be considered for build creation; if not given
it will be calculated in place, all architectures for the
context distroseries with available chroot.
:param pas_verify: optional Package-architecture-specific (P-a-s)
object, to be used, when convinient, for creating builds;
:param logger: optional context Logger object (used on DEBUG level).
:return: a list of `Builds` created for this source publication.
"""
def getSourceAndBinaryLibraryFiles():
"""Return a list of `LibraryFileAlias` for all source and binaries.
All the source files and all binary files ever published to the
same archive context are returned as a list of LibraryFileAlias
records.
:return: a list of `ILibraryFileAlias`.
"""
def supersede(dominant=None, logger=None):
"""Supersede this publication.
:param dominant: optional `ISourcePackagePublishingHistory` which is
triggering the domination.
:param logger: optional object to which debug information will be
logged.
"""
def changeOverride(new_component=None, new_section=None):
"""Change the component and/or section of this publication
It is changed only if the argument is not None.
Return the overridden publishing record, either a
`ISourcePackagePublishingHistory` or
`IBinaryPackagePublishingHistory`.
"""
def copyTo(distroseries, pocket, archive, overrides=None, creator=None):
"""Copy this publication to another location.
:param distroseries: The `IDistroSeries` to copy the source
publication into.
:param pocket: The `PackagePublishingPocket` to copy into.
:param archive: The `IArchive` to copy the source publication into.
:param overrides: A tuple of override data as returned from a
`IOverridePolicy`.
:param creator: the `IPerson` to use as the creator for the copied
publication.
:return: a `ISourcePackagePublishingHistory` record representing the
source in the destination location.
"""
def getStatusSummaryForBuilds():
"""Return a summary of the build status for the related builds.
This method augments IBuildSet.getBuildStatusSummaryForBuilds() by
additionally checking to see if all the builds have been published
before returning the fully-built status.
:return: A dict consisting of the build status summary for the
related builds. For example:
{
'status': PackagePublishingStatus.PENDING,
'builds': [build1, build2]
}
"""
@export_read_operation()
def sourceFileUrls():
"""URLs for this source publication's uploaded source files.
:return: A collection of URLs for this source.
"""
@export_read_operation()
def binaryFileUrls():
"""URLs for this source publication's binary files.
:return: A collection of URLs for this source.
"""
@export_read_operation()
@operation_parameters(
to_version=TextLine(title=_("To Version"), required=True))
def packageDiffUrl(to_version):
"""URL of the debdiff file between this and the supplied version.
:param to_version: The version of the source package for which you
want to get the diff to.
:return: A URL to the librarian file containing the diff.
"""
class ISourcePackagePublishingHistory(ISourcePackagePublishingHistoryPublic,
IPublishingEdit):
"""A source package publishing history record."""
export_as_webservice_entry(publish_web_link=False)
#
# Binary package publishing
#
class IBinaryPackageFilePublishing(IFilePublishing):
"""Binary package files and their publishing status"""
# Note that it is really /source/ package name below, and not a
# thinko; at least, that's what Celso tells me the code uses
# -- kiko, 2006-03-22
sourcepackagename = TextLine(
title=_('Source package name'), required=True, readonly=True,
)
binarypackagepublishing = Int(
title=_('Binary Package publishing record id'), required=True,
readonly=True,
)
class IBinaryPackagePublishingHistoryPublic(IPublishingView):
"""A binary package publishing record."""
id = Int(title=_('ID'), required=True, readonly=True)
binarypackagenameID = Int(
title=_('The DB id for the binarypackagename.'),
required=False, readonly=False)
binarypackagename = Attribute('The binary package name being published')
binarypackagereleaseID = Int(
title=_('The DB id for the binarypackagerelease.'),
required=False, readonly=False)
binarypackagerelease = Attribute(
"The binary package release being published")
distroarchseries = exported(
Reference(
# Really IDistroArchSeries (fixed in
#_schema_circular_imports.py).
Interface,
title=_("Distro Arch Series"),
description=_('The distroarchseries being published into'),
required=False, readonly=False,
),
exported_as="distro_arch_series")
distroseries = Attribute("The distroseries being published into")
component = Int(
title=_('The component being published into'),
required=False, readonly=False,
)
section = Int(
title=_('The section being published into'),
required=False, readonly=False,
)
priority = Int(
title=_('The priority being published into'),
required=False, readonly=False,
)
datepublished = exported(
Datetime(
title=_("Date Published"),
description=_('The date on which this record was published'),
required=False, readonly=False,
),
exported_as="date_published")
scheduleddeletiondate = exported(
Datetime(
title=_("Scheduled Deletion Date"),
description=_('The date on which this record is scheduled for '
'deletion'),
required=False, readonly=False,
),
exported_as="scheduled_deletion_date")
status = exported(
Choice(
title=_('Status'),
description=_('The status of this publishing record'),
vocabulary=PackagePublishingStatus,
required=False, readonly=False,
))
pocket = exported(
Choice(
title=_('Pocket'),
description=_('The pocket into which this entry is published'),
vocabulary=PackagePublishingPocket,
required=True, readonly=True,
))
supersededby = Int(
title=_('The build which superseded this one'),
required=False, readonly=False,
)
datecreated = exported(
Datetime(
title=_('Date Created'),
description=_('The date on which this record was created'),
required=True, readonly=False,
),
exported_as="date_created")
datesuperseded = exported(
Datetime(
title=_("Date Superseded"),
description=_(
'The date on which this record was marked superseded'),
required=False, readonly=False,
),
exported_as="date_superseded")
datemadepending = exported(
Datetime(
title=_("Date Made Pending"),
description=_(
'The date on which this record was set as pending removal'),
required=False, readonly=False,
),
exported_as="date_made_pending")
dateremoved = exported(
Datetime(
title=_("Date Removed"),
description=_(
'The date on which this record was removed from the '
'published set'),
required=False, readonly=False,
),
exported_as="date_removed")
archive = exported(
Reference(
# Really IArchive (fixed in _schema_circular_imports.py).
Interface,
title=_('Archive'),
description=_("The context archive for this publication."),
required=True, readonly=True,
))
removed_by = exported(
Reference(
IPerson,
title=_("Removed By"),
description=_('The Person responsible for the removal'),
required=False, readonly=False,
))
removal_comment = exported(
Text(
title=_("Removal Comment"),
description=_(
'Reason why this publication is going to be removed.'),
required=False, readonly=False))
distroarchseriesbinarypackagerelease = Attribute("The object that "
"represents this binarypackagerelease in this distroarchseries.")
binary_package_name = exported(
TextLine(
title=_("Binary Package Name"),
required=False, readonly=True))
binary_package_version = exported(
TextLine(
title=_("Binary Package Version"),
required=False, readonly=True))
architecture_specific = exported(
Bool(
title=_("Architecture Specific"),
required=False, readonly=True))
priority_name = exported(
TextLine(
title=_("Priority Name"),
required=False, readonly=True))
def supersede(dominant=None, logger=None):
"""Supersede this publication.
:param dominant: optional `IBinaryPackagePublishingHistory` which is
triggering the domination.
:param logger: optional object to which debug information will be
logged.
"""
def changeOverride(new_component=None, new_section=None,
new_priority=None):
"""Change the component, section and/or priority of this publication.
It is changed only if the argument is not None.
Return the overridden publishing record, either a
`ISourcePackagePublishingHistory` or
`IBinaryPackagePublishingHistory`.
"""
def copyTo(distroseries, pocket, archive):
"""Copy this publication to another location.
Architecture independent binary publications are copied to all
supported architectures in the destination distroseries.
:return: a list of `IBinaryPackagePublishingHistory` records
representing the binaries copied to the destination location.
"""
@export_read_operation()
def getDownloadCount():
"""Get the download count of this binary package in this archive.
This is currently only meaningful for PPAs."""
@operation_parameters(
start_date=Date(title=_("Start date"), required=False),
end_date=Date(title=_("End date"), required=False))
@operation_returns_collection_of(IBinaryPackageReleaseDownloadCount)
@export_read_operation()
def getDownloadCounts(start_date=None, end_date=None):
"""Get detailed download counts for this binary.
:param start_date: The optional first date to return.
:param end_date: The optional last date to return.
"""
@operation_parameters(
start_date=Date(title=_("Start date"), required=False),
end_date=Date(title=_("End date"), required=False))
@export_read_operation()
def getDailyDownloadTotals(start_date=None, end_date=None):
"""Get the daily download counts for this binary.
:param start_date: The optional first date to return.
:param end_date: The optional last date to return.
"""
@export_read_operation()
@operation_for_version("devel")
def binaryFileUrls():
"""URLs for this binary publication's binary files.
:return: A collection of URLs for this binary.
"""
class IBinaryPackagePublishingHistory(IBinaryPackagePublishingHistoryPublic,
IPublishingEdit):
"""A binary package publishing record."""
export_as_webservice_entry(publish_web_link=False)
class IPublishingSet(Interface):
"""Auxiliary methods for dealing with sets of publications."""
def copyBinariesTo(binaries, distroseries, pocket, archive, policy=None):
"""Copy multiple binaries to a given destination.
Processing multiple binaries in a batch allows certain
performance optimisations such as looking up the main
component once only, and getting all the BPPH records
with one query.
:param binaries: A list of binaries to copy.
:param distroseries: The target distroseries.
:param pocket: The target pocket.
:param archive: The target archive.
:param policy: The `IOverridePolicy` to apply to the copy.
:return: A result set of the created binary package
publishing histories.
"""
def publishBinaries(archive, distroseries, pocket, binaries):
"""Efficiently publish multiple BinaryPackageReleases in an Archive.
Creates `IBinaryPackagePublishingHistory` records for each binary,
handling architecture-independent and debug packages, avoiding
creation of duplicate publications, and leaving disabled
architectures alone.
:param archive: The target `IArchive`.
:param distroseries: The target `IDistroSeries`.
:param pocket: The target `PackagePublishingPocket`.
:param binaries: A dict mapping `BinaryPackageReleases` to their
desired overrides as (`Component`, `Section`,
`PackagePublishingPriority`) tuples.
:return: A list of new `IBinaryPackagePublishingHistory` records.
"""
def publishBinary(archive, binarypackagerelease, distroseries,
component, section, priority, pocket):
"""Publish a `BinaryPackageRelease` in an archive.
Creates one or more `IBinaryPackagePublishingHistory` records,
handling architecture-independent and DDEB publications transparently.
Note that binaries will only be copied if they don't already exist in
the target; this method cannot be used to change overrides.
:param archive: The target `IArchive`.
:param binarypackagerelease: The `IBinaryPackageRelease` to copy.
:param distroseries: An `IDistroSeries`.
:param component: The target `IComponent`.
:param section: The target `ISection`.
:param priority: The target `PackagePublishingPriority`.
:param pocket: The target `PackagePublishingPocket`.
:return: A list of new `IBinaryPackagePublishingHistory` records.
"""
def newBinaryPublication(archive, binarypackagerelease, distroarchseries,
component, section, priority, pocket):
"""Create a new `BinaryPackagePublishingHistory`.
:param archive: An `IArchive`
:param binarypackagerelease: An `IBinaryPackageRelease`
:param distroarchseries: An `IDistroArchSeries`
:param component: An `IComponent`
:param section: An `ISection`
:param priority: A `PackagePublishingPriority`
:param pocket: A `PackagePublishingPocket`
datecreated will be UTC_NOW.
status will be PackagePublishingStatus.PENDING
"""
def newSourcePublication(archive, sourcepackagerelease, distroseries,
component, section, pocket, ancestor,
create_dsd_job=True):
"""Create a new `SourcePackagePublishingHistory`.
:param archive: An `IArchive`
:param sourcepackagerelease: An `ISourcePackageRelease`
:param distroseries: An `IDistroSeries`
:param component: An `IComponent`
:param section: An `ISection`
:param pocket: A `PackagePublishingPocket`
:param ancestor: A `ISourcePackagePublishingHistory` for the previous
version of this publishing record
:param create_dsd_job: A boolean indicating whether or not a dsd job
should be created for the new source publication.
:param creator: An optional `IPerson`. If this is None, the
sourcepackagerelease's creator will be used.
datecreated will be UTC_NOW.
status will be PackagePublishingStatus.PENDING
"""
def getByIdAndArchive(id, archive, source=True):
"""Return the publication matching id AND archive.
:param archive: The context `IArchive`.
:param source: If true look for source publications, otherwise
binary publications.
"""
def getBuildsForSourceIds(source_ids, archive=None, build_states=None,
need_build_farm_job=False):
"""Return all builds related with each given source publication.
The returned ResultSet contains entries with the wanted `Build`s
associated with the corresponding source publication and its
targeted `DistroArchSeries` in a 3-element tuple. This way the extra
information will be cached and the callsites can group builds in
any convenient form.
The optional archive parameter, if provided, will ensure that only
builds corresponding to the archive will be included in the results.
The result is ordered by:
1. Ascending `SourcePackagePublishingHistory.id`,
2. Ascending `DistroArchSeries.architecturetag`.
:param source_ids: list of or a single
`SourcePackagePublishingHistory` object.
:type source_ids: ``list`` or `SourcePackagePublishingHistory`
:param archive: An optional archive with which to filter the source
ids.
:type archive: `IArchive`
:param build_states: optional list of build states to which the
result will be limited. Defaults to all states if ommitted.
:type build_states: ``list`` or None
:param need_build_farm_job: whether to include the `PackageBuild`
and `BuildFarmJob` in the result.
:type need_build_farm_job: bool
:return: a storm ResultSet containing tuples as
(`SourcePackagePublishingHistory`, `Build`, `DistroArchSeries`,
[`PackageBuild`, `BuildFarmJob` if need_build_farm_job])
:rtype: `storm.store.ResultSet`.
"""
def getBuildsForSources(one_or_more_source_publications):
"""Return all builds related with each given source publication.
Extracts the source ids from one_or_more_source_publications and
calls getBuildsForSourceIds.
"""
def getUnpublishedBuildsForSources(one_or_more_source_publications,
build_states=None):
"""Return all the unpublished builds for each source.
:param one_or_more_source_publications: list of, or a single
`SourcePackagePublishingHistory` object.
:param build_states: list of build states to which the result should
be limited. Defaults to BuildStatus.FULLYBUILT if none are
specified.
:return: a storm ResultSet containing tuples of
(`SourcePackagePublishingHistory`, `Build`)
"""
def getBinaryFilesForSources(one_or_more_source_publication):
"""Return binary files related to each given source publication.
The returned ResultSet contains entries with the wanted
`LibraryFileAlias`s (binaries only) associated with the
corresponding source publication and its `LibraryFileContent`
in a 3-element tuple. This way the extra information will be
cached and the callsites can group files in any convenient form.
:param one_or_more_source_publication: list of or a single
`SourcePackagePublishingHistory` object.
:return: a storm ResultSet containing triples as follows:
(`SourcePackagePublishingHistory`, `LibraryFileAlias`,
`LibraryFileContent`)
"""
def getFilesForSources(one_or_more_source_publication):
"""Return all files related to each given source publication.
The returned ResultSet contains entries with the wanted
`LibraryFileAlias`s (source and binaries) associated with the
corresponding source publication and its `LibraryFileContent`
in a 3-element tuple. This way the extra information will be
cached and the callsites can group files in any convenient form.
Callsites should order this result after grouping by source,
because SQL UNION can't be correctly ordered in SQL level.
:param one_or_more_source_publication: list of or a single
`SourcePackagePublishingHistory` object.
:return: an *unordered* storm ResultSet containing tuples as
(`SourcePackagePublishingHistory`, `LibraryFileAlias`,
`LibraryFileContent`)
"""
def getBinaryPublicationsForSources(one_or_more_source_publications):
"""Return all binary publication for the given source publications.
The returned ResultSet contains entries with the wanted
`BinaryPackagePublishingHistory`s associated with the corresponding
source publication and its targeted `DistroArchSeries`,
`BinaryPackageRelease` and `BinaryPackageName` in a 5-element tuple.
This way the extra information will be cached and the callsites can
group binary publications in any convenient form.
The result is ordered by:
1. Ascending `SourcePackagePublishingHistory.id`,
2. Ascending `BinaryPackageName.name`,
3. Ascending `DistroArchSeries.architecturetag`.
4. Descending `BinaryPackagePublishingHistory.id`.
:param one_or_more_source_publication: list of or a single
`SourcePackagePublishingHistory` object.
:return: a storm ResultSet containing tuples as
(`SourcePackagePublishingHistory`,
`BinaryPackagePublishingHistory`,
`BinaryPackageRelease`, `BinaryPackageName`, `DistroArchSeries`)
"""
def getPackageDiffsForSources(one_or_more_source_publications):
"""Return all `PackageDiff`s for each given source publication.
The returned ResultSet contains entries with the wanted `PackageDiff`s
associated with the corresponding source publication and its resulting
`LibraryFileAlias` and `LibraryFileContent` in a 4-element tuple. This
way the extra information will be cached and the callsites can group
package-diffs in any convenient form.
`LibraryFileAlias` and `LibraryFileContent` elements might be None in
case the `PackageDiff` is not completed yet.
The result is ordered by:
1. Ascending `SourcePackagePublishingHistory.id`,
2. Descending `PackageDiff.date_requested`.
:param one_or_more_source_publication: list of or a single
`SourcePackagePublishingHistory` object.
:return: a storm ResultSet containing tuples as
(`SourcePackagePublishingHistory`, `PackageDiff`,
`LibraryFileAlias`, `LibraryFileContent`)
"""
def getChangesFilesForSources(one_or_more_source_publications):
"""Return all changesfiles for each given source publication.
The returned ResultSet contains entries with the wanted changesfiles
as `LibraryFileAlias`es associated with the corresponding source
publication and its corresponding `LibraryFileContent`,
`PackageUpload` and `SourcePackageRelease` in a 5-element tuple.
This way the extra information will be cached and the call sites can
group changesfiles in any convenient form.
The result is ordered by ascending `SourcePackagePublishingHistory.id`
:param one_or_more_source_publication: list of or a single
`SourcePackagePublishingHistory` object.
:return: a storm ResultSet containing tuples as
(`SourcePackagePublishingHistory`, `PackageUpload`,
`SourcePackageRelease`, `LibraryFileAlias`, `LibraryFileContent`)
"""
def getChangesFileLFA(spr):
"""The changes file for the given `SourcePackageRelease`.
:param spr: the `SourcePackageRelease` for which to return the
changes file `LibraryFileAlias`.
:return: a `LibraryFileAlias` instance or None
"""
def setMultipleDeleted(publication_class, ds, removed_by,
removal_comment=None):
"""Mark publications as deleted.
This is a supporting operation for a deletion request.
"""
def requestDeletion(sources, removed_by, removal_comment=None):
"""Delete the source and binary publications specified.
This method deletes the source publications passed via the first
parameter as well as their associated binary publications.
:param sources: list of `SourcePackagePublishingHistory` objects.
:param removed_by: `IPerson` responsible for the removal.
:param removal_comment: optional text describing the removal reason.
:return: The deleted publishing record, either:
`ISourcePackagePublishingHistory` or
`IBinaryPackagePublishingHistory`.
"""
def getBuildStatusSummariesForSourceIdsAndArchive(source_ids, archive):
"""Return a summary of the build statuses for source publishing ids.
This method collects all the builds for the provided source package
publishing history ids, and returns the build status summary for
the builds associated with each source package.
See the `getStatusSummaryForBuilds()` method of `IBuildSet`.for
details of the summary.
:param source_ids: A list of source publishing history record ids.
:type source_ids: ``list``
:param archive: The archive which will be used to filter the source
ids.
:type archive: `IArchive`
:return: A dict consisting of the overall status summaries for the
given ids that belong in the archive. For example:
{
18: {'status': 'succeeded'},
25: {'status': 'building', 'builds':[building_builds]},
35: {'status': 'failed', 'builds': [failed_builds]}
}
:rtype: ``dict``.
"""
def getBuildStatusSummaryForSourcePublication(source_publication):
"""Return a summary of the build statuses for this source
publication.
See `ISourcePackagePublishingHistory`.getStatusSummaryForBuilds()
for details. The call is just proxied here so that it can also be
used with an ArchiveSourcePublication passed in as
the source_package_pub, allowing the use of the cached results.
"""
def getNearestAncestor(
package_name, archive, distroseries, pocket=None, status=None,
binary=False):
"""Return the ancestor of the given parkage in a particular archive.
:param package_name: The package name for which we are checking for
an ancestor.
:type package_name: ``string``
:param archive: The archive in which we are looking for an ancestor.
:type archive: `IArchive`
:param distroseries: The particular series in which we are looking for
an ancestor.
:type distroseries: `IDistroSeries`
:param pocket: An optional pocket to restrict the search.
:type pocket: `PackagePublishingPocket`.
:param status: An optional status defaulting to PUBLISHED if not
provided.
:type status: `PackagePublishingStatus`
:param binary: An optional argument to look for a binary ancestor
instead of the default source.
:type binary: ``Boolean``
:return: The most recent publishing history for the given
arguments.
:rtype: `ISourcePackagePublishingHistory` or
`IBinaryPackagePublishingHistory` or None.
"""
active_publishing_status = (
PackagePublishingStatus.PENDING,
PackagePublishingStatus.PUBLISHED,
)
inactive_publishing_status = (
PackagePublishingStatus.SUPERSEDED,
PackagePublishingStatus.DELETED,
PackagePublishingStatus.OBSOLETE,
)
# Circular import problems fixed in _schema_circular_imports.py
|