24
24
from zope.component import getUtility
26
26
from canonical.launchpad.interfaces.librarian import ILibraryFileAliasSet
27
from canonical.launchpad.webapp.authorization import check_permission
27
28
from canonical.librarian.utils import copy_and_close
28
29
from lp.app.errors import NotFoundError
29
30
from lp.buildmaster.enums import BuildStatus
30
31
from lp.soyuz.adapters.packagelocation import build_package_location
31
from lp.soyuz.enums import ArchivePurpose
32
from lp.soyuz.interfaces.archive import (
32
from lp.soyuz.enums import (
36
from lp.soyuz.interfaces.archive import CannotCopy
35
37
from lp.soyuz.interfaces.binarypackagebuild import BuildSetStatus
36
38
from lp.soyuz.interfaces.publishing import (
37
39
active_publishing_status,
374
375
"%s already exists in destination archive with "
375
376
"different contents." % lf.libraryfile.filename)
377
def checkCopy(self, source, series, pocket):
378
def checkCopy(self, source, series, pocket, person=None,
379
check_permissions=True):
378
380
"""Check if the source can be copied to the given location.
380
382
Check possible conflicting publications in the destination archive.
384
386
higher than any version of the same source present in the
385
387
destination suite (series + pocket).
389
If person is not None, check that this person has upload rights to
390
the destination (archive, component, pocket).
387
392
:param source: copy candidate, `ISourcePackagePublishingHistory`.
388
393
:param series: destination `IDistroSeries`.
389
394
:param pocket: destination `PackagePublishingPocket`.
395
:param person: requester `IPerson`.
396
:param check_permissions: boolean indicating whether or not the
397
requester's permissions to copy should be checked.
391
399
:raise CannotCopy when a copy is not allowed to be performed
392
400
containing the reason of the error.
402
# If there is a requester, check that he has upload permission
403
# into the destination (archive, component, pocket). This check
404
# is done here rather than in the security adapter because it
405
# requires more info than is available in the security adapter.
406
if check_permissions:
409
'Cannot check copy permissions (no requester).')
411
sourcepackagerelease = source.sourcepackagerelease
412
sourcepackagename = sourcepackagerelease.sourcepackagename
413
destination_component = series.getSourcePackage(
414
sourcepackagename).latest_published_component
415
# If destination_component is not None, make sure the person
416
# has upload permission for this component. Otherwise, any
417
# upload permission on this archive will do.
418
strict_component = destination_component is not None
419
reason = self.archive.checkUpload(
420
person, series, sourcepackagename, destination_component,
421
pocket, strict_component=strict_component)
422
if reason is not None:
423
# launchpad.Append on the main archive is sufficient
424
# to copy arbitrary packages. This allows for
425
# ubuntu's security team to sync sources into the
426
# primary archive (bypassing the queue and
428
if not check_permission(
429
'launchpad.Append', series.main_archive):
430
raise CannotCopy(reason)
394
432
if series not in self.archive.distribution.series:
395
433
raise CannotCopy(
396
434
"No such distro series %s in distribution %s." %
461
499
def do_copy(sources, archive, series, pocket, include_binaries=False,
462
allow_delayed_copies=True):
500
allow_delayed_copies=True, person=None, check_permissions=True):
463
501
"""Perform the complete copy of the given sources incrementally.
465
503
Verifies if each copy can be performed using `CopyChecker` and
471
509
Wrapper for `do_direct_copy`.
473
:param: sources: a list of `ISourcePackagePublishingHistory`.
474
:param: archive: the target `IArchive`.
475
:param: series: the target `IDistroSeries`, if None is given the same
511
:param sources: a list of `ISourcePackagePublishingHistory`.
512
:param archive: the target `IArchive`.
513
:param series: the target `IDistroSeries`, if None is given the same
476
514
current source distroseries will be used as destination.
477
:param: pocket: the target `PackagePublishingPocket`.
478
:param: include_binaries: optional boolean, controls whether or
515
:param pocket: the target `PackagePublishingPocket`.
516
:param include_binaries: optional boolean, controls whether or
479
517
not the published binaries for each given source should be also
480
518
copied along with the source.
481
519
:param allow_delayed_copies: boolean indicating whether or not private
482
520
sources can be copied to public archives using delayed_copies.
483
521
Defaults to True, only set as False in the UnembargoPackage context.
522
:param person: the requester `IPerson`.
523
:param check_permissions: boolean indicating whether or not the
524
requester's permissions to copy should be checked.
485
526
:raise CannotCopy when one or more copies were not allowed. The error
486
527
will contain the reason why each copy was denied.
501
542
destination_series = series
503
copy_checker.checkCopy(source, destination_series, pocket)
544
copy_checker.checkCopy(
545
source, destination_series, pocket, person, check_permissions)
504
546
except CannotCopy, reason:
505
547
errors.append("%s (%s)" % (source.displayname, reason))
536
578
Also copy published binaries for each source if requested to. Again,
537
579
only copy binaries that were not yet copied before.
539
:param: source: an `ISourcePackagePublishingHistory`.
540
:param: archive: the target `IArchive`.
541
:param: series: the target `IDistroSeries`, if None is given the same
581
:param source: an `ISourcePackagePublishingHistory`.
582
:param archive: the target `IArchive`.
583
:param series: the target `IDistroSeries`, if None is given the same
542
584
current source distroseries will be used as destination.
543
:param: pocket: the target `PackagePublishingPocket`.
544
:param: include_binaries: optional boolean, controls whether or
585
:param pocket: the target `PackagePublishingPocket`.
586
:param include_binaries: optional boolean, controls whether or
545
587
not the published binaries for each given source should be also
546
588
copied along with the source.
609
651
Also include published builds for each source if requested to.
611
:param: source: an `ISourcePackagePublishingHistory`.
612
:param: archive: the target `IArchive`.
613
:param: series: the target `IDistroSeries`.
614
:param: pocket: the target `PackagePublishingPocket`.
615
:param: include_binaries: optional boolean, controls whether or
653
:param source: an `ISourcePackagePublishingHistory`.
654
:param archive: the target `IArchive`.
655
:param series: the target `IDistroSeries`.
656
:param pocket: the target `PackagePublishingPocket`.
657
:param include_binaries: optional boolean, controls whether or
616
658
not the published binaries for each given source should be also
617
659
copied along with the source.
778
820
copies = do_copy(
779
821
sources, self.destination.archive,
780
822
self.destination.distroseries, self.destination.pocket,
781
self.options.include_binaries, self.allow_delayed_copies)
823
self.options.include_binaries, self.allow_delayed_copies,
824
check_permissions=False)
782
825
except CannotCopy, error:
783
826
self.logger.error(str(error))