28
28
from canonical.librarian.utils import copy_and_close
29
29
from lp.app.errors import NotFoundError
30
30
from lp.buildmaster.enums import BuildStatus
31
from lp.soyuz.adapters.notification import notify
31
32
from lp.soyuz.adapters.packagelocation import build_package_location
32
33
from lp.soyuz.enums import (
511
512
def do_copy(sources, archive, series, pocket, include_binaries=False,
512
allow_delayed_copies=True, person=None, check_permissions=True):
513
allow_delayed_copies=True, person=None, check_permissions=True,
514
overrides=None, send_email=False):
513
515
"""Perform the complete copy of the given sources incrementally.
515
517
Verifies if each copy can be performed using `CopyChecker` and
534
536
:param person: the requester `IPerson`.
535
537
:param check_permissions: boolean indicating whether or not the
536
538
requester's permissions to copy should be checked.
539
:param overrides: A list of `IOverride` as returned from one of the copy
540
policies which will be used as a manual override insyead of using the
541
default override returned by IArchive.getOverridePolicy(). There
542
must be the same number of overrides as there are sources and each
543
override must be for the corresponding source in the sources list.
544
Overrides will be ignored for delayed copies.
545
:param send_email: Should we notify for the copy performed?
538
547
:raise CannotCopy when one or more copies were not allowed. The error
539
548
will contain the reason why each copy was denied.
569
579
destination_series = series
570
580
if source.delayed:
571
581
delayed_copy = _do_delayed_copy(
572
source, archive, destination_series, pocket, include_binaries)
582
source, archive, destination_series, pocket,
573
584
sub_copies = [delayed_copy]
588
override = overrides[overrides_index]
575
589
sub_copies = _do_direct_copy(
576
source, archive, destination_series, pocket, include_binaries)
590
source, archive, destination_series, pocket,
591
include_binaries, override)
594
person, source.sourcepackagerelease, [], [], archive,
595
destination_series, pocket, changes=None,
578
599
copies.extend(sub_copies)
583
def _do_direct_copy(source, archive, series, pocket, include_binaries):
604
def _do_direct_copy(source, archive, series, pocket, include_binaries,
584
606
"""Copy publishing records to another location.
586
608
Copy each item of the given list of `SourcePackagePublishingHistory`
598
620
:param include_binaries: optional boolean, controls whether or
599
621
not the published binaries for each given source should be also
600
622
copied along with the source.
623
:param override: An `IOverride` as per do_copy().
602
625
:return: a list of `ISourcePackagePublishingHistory` and
603
626
`BinaryPackagePublishingHistory` corresponding to the copied
613
636
distroseries=series, pocket=pocket)
614
637
policy = archive.getOverridePolicy()
615
638
if source_in_destination.is_empty():
617
if policy is not None:
639
# If no manual overrides were specified and the archive has an
640
# override policy then use that policy to get overrides.
641
if override is None and policy is not None:
618
642
package_names = (source.sourcepackagerelease.sourcepackagename,)
643
# Only one override can be returned so take the first
644
# element of the returned list.
619
645
overrides = policy.calculateSourceOverrides(
620
646
archive, series, pocket, package_names)
621
647
# Only one override can be returned so take the first