~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/scripts/packagecopier.py

  • Committer: Raphael Badin
  • Date: 2011-05-05 13:01:50 UTC
  • mto: This revision was merged to the branch mainline in revision 12988.
  • Revision ID: raphael.badin@canonical.com-20110505130150-ktehsl7twlm10j4f
Roll back 12977.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from lp.app.errors import NotFoundError
29
29
from lp.buildmaster.enums import BuildStatus
30
30
from lp.soyuz.adapters.packagelocation import build_package_location
31
 
from lp.soyuz.enums import ArchivePurpose
32
 
from lp.soyuz.interfaces.archive import (
33
 
    CannotCopy,
 
31
from lp.soyuz.enums import (
 
32
    ArchivePurpose,
 
33
    SourcePackageFormat,
34
34
    )
 
35
from lp.soyuz.interfaces.archive import CannotCopy
35
36
from lp.soyuz.interfaces.binarypackagebuild import BuildSetStatus
36
37
from lp.soyuz.interfaces.publishing import (
37
38
    active_publishing_status,
44
45
    IPackageUploadCustom,
45
46
    IPackageUploadSet,
46
47
    )
47
 
from lp.soyuz.enums import SourcePackageFormat
48
48
from lp.soyuz.scripts.ftpmasterbase import (
49
49
    SoyuzScript,
50
50
    SoyuzScriptError,
374
374
                        "%s already exists in destination archive with "
375
375
                        "different contents." % lf.libraryfile.filename)
376
376
 
377
 
    def checkCopy(self, source, series, pocket):
 
377
    def checkCopy(self, source, series, pocket, person=None,
 
378
                  check_permissions=True):
378
379
        """Check if the source can be copied to the given location.
379
380
 
380
381
        Check possible conflicting publications in the destination archive.
384
385
        higher than any version of the same source present in the
385
386
        destination suite (series + pocket).
386
387
 
 
388
        If person is not None, check that this person has upload rights to
 
389
        the destination (archive, component, pocket).
 
390
 
387
391
        :param source: copy candidate, `ISourcePackagePublishingHistory`.
388
392
        :param series: destination `IDistroSeries`.
389
393
        :param pocket: destination `PackagePublishingPocket`.
 
394
        :param person: requester `IPerson`.
 
395
        :param check_permissions: boolean indicating whether or not the
 
396
            requester's permissions to copy should be checked.
390
397
 
391
398
        :raise CannotCopy when a copy is not allowed to be performed
392
399
            containing the reason of the error.
393
400
        """
 
401
        # If there is a requester, check that he has upload permission
 
402
        # into the destination (archive, component, pocket). This check
 
403
        # is done here rather than in the security adapter because it
 
404
        # requires more info than is available in the security adapter.
 
405
        if check_permissions:
 
406
            if person is None:
 
407
                raise CannotCopy(
 
408
                    'Cannot check copy permissions (no requester).')
 
409
            else:
 
410
                sourcepackagerelease = source.sourcepackagerelease
 
411
                sourcepackagename = sourcepackagerelease.sourcepackagename
 
412
                destination_component = series.getSourcePackage(
 
413
                    sourcepackagename).latest_published_component
 
414
                # If destination_component is not None, make sure the person
 
415
                # has upload permission for this component. Otherwise, any
 
416
                # upload permission on this archive will do.
 
417
                strict_component = destination_component is not None
 
418
                reason = self.archive.checkUpload(
 
419
                    person, series, sourcepackagename, destination_component,
 
420
                    pocket, strict_component=strict_component)
 
421
                if reason is not None:
 
422
                    raise CannotCopy(reason)
 
423
 
394
424
        if series not in self.archive.distribution.series:
395
425
            raise CannotCopy(
396
426
                "No such distro series %s in distribution %s." %
459
489
 
460
490
 
461
491
def do_copy(sources, archive, series, pocket, include_binaries=False,
462
 
            allow_delayed_copies=True):
 
492
            allow_delayed_copies=True, person=None, check_permissions=True):
463
493
    """Perform the complete copy of the given sources incrementally.
464
494
 
465
495
    Verifies if each copy can be performed using `CopyChecker` and
470
500
 
471
501
    Wrapper for `do_direct_copy`.
472
502
 
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
 
503
    :param sources: a list of `ISourcePackagePublishingHistory`.
 
504
    :param archive: the target `IArchive`.
 
505
    :param series: the target `IDistroSeries`, if None is given the same
476
506
        current source distroseries will be used as destination.
477
 
    :param: pocket: the target `PackagePublishingPocket`.
478
 
    :param: include_binaries: optional boolean, controls whether or
 
507
    :param pocket: the target `PackagePublishingPocket`.
 
508
    :param include_binaries: optional boolean, controls whether or
479
509
        not the published binaries for each given source should be also
480
510
        copied along with the source.
481
511
    :param allow_delayed_copies: boolean indicating whether or not private
482
512
        sources can be copied to public archives using delayed_copies.
483
513
        Defaults to True, only set as False in the UnembargoPackage context.
 
514
    :param person: the requester `IPerson`.
 
515
    :param check_permissions: boolean indicating whether or not the
 
516
        requester's permissions to copy should be checked.
484
517
 
485
518
    :raise CannotCopy when one or more copies were not allowed. The error
486
519
        will contain the reason why each copy was denied.
500
533
        else:
501
534
            destination_series = series
502
535
        try:
503
 
            copy_checker.checkCopy(source, destination_series, pocket)
 
536
            copy_checker.checkCopy(
 
537
                source, destination_series, pocket, person, check_permissions)
504
538
        except CannotCopy, reason:
505
539
            errors.append("%s (%s)" % (source.displayname, reason))
506
540
            continue
536
570
    Also copy published binaries for each source if requested to. Again,
537
571
    only copy binaries that were not yet copied before.
538
572
 
539
 
    :param: source: an `ISourcePackagePublishingHistory`.
540
 
    :param: archive: the target `IArchive`.
541
 
    :param: series: the target `IDistroSeries`, if None is given the same
 
573
    :param source: an `ISourcePackagePublishingHistory`.
 
574
    :param archive: the target `IArchive`.
 
575
    :param series: the target `IDistroSeries`, if None is given the same
542
576
        current source distroseries will be used as destination.
543
 
    :param: pocket: the target `PackagePublishingPocket`.
544
 
    :param: include_binaries: optional boolean, controls whether or
 
577
    :param pocket: the target `PackagePublishingPocket`.
 
578
    :param include_binaries: optional boolean, controls whether or
545
579
        not the published binaries for each given source should be also
546
580
        copied along with the source.
547
581
 
608
642
 
609
643
    Also include published builds for each source if requested to.
610
644
 
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
 
645
    :param source: an `ISourcePackagePublishingHistory`.
 
646
    :param archive: the target `IArchive`.
 
647
    :param series: the target `IDistroSeries`.
 
648
    :param pocket: the target `PackagePublishingPocket`.
 
649
    :param include_binaries: optional boolean, controls whether or
616
650
        not the published binaries for each given source should be also
617
651
        copied along with the source.
618
652
 
778
812
            copies = do_copy(
779
813
                sources, self.destination.archive,
780
814
                self.destination.distroseries, self.destination.pocket,
781
 
                self.options.include_binaries, self.allow_delayed_copies)
 
815
                self.options.include_binaries, self.allow_delayed_copies,
 
816
                check_permissions=False)
782
817
        except CannotCopy, error:
783
818
            self.logger.error(str(error))
784
819
            return []