1
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
9
"IPackageCopyJobSource",
10
"IPlainPackageCopyJob",
11
"IPlainPackageCopyJobSource",
15
from lazr.enum import (
19
from lazr.restful.fields import Reference
20
from zope.interface import (
24
from zope.schema import (
31
from canonical.launchpad import _
32
from lp.registry.interfaces.distroseries import IDistroSeries
33
from lp.services.job.interfaces.job import (
38
from lp.soyuz.enums import PackageCopyPolicy
39
from lp.soyuz.interfaces.archive import IArchive
42
class IPackageCopyJobSource(Interface):
43
"""Utility for `IPackageCopyJob`-implementing types."""
45
def wrap(package_copy_job):
46
"""Wrap a `PackageCopyJob` in its concrete implementation type.
48
As a special case, `None` produces `None`.
50
:param package_copy_job: A `PackageCopyJob`.
51
:return: An `IPackageCopyJob` implementation based on
52
`package_copy_job`, but of the job's specific concrete type
53
(such as `PlainPackageCopyJob`).
57
class IPackageCopyJobEdit(Interface):
58
"""Privileged access to an `IPackageCopyJob`."""
60
def extendMetadata(metadata_dict):
61
"""Update the job's JSON metadata with items from `metadata_dict`."""
64
class IPackageCopyJobPublic(Interface):
65
"""The immutable data on an `IPackageCopyJob`, for normal use."""
68
title=_('DB ID'), required=True, readonly=True,
69
description=_("The tracking number for this job."))
71
source_archive_id = Int(
72
title=_('Source Archive ID'),
73
required=True, readonly=True)
75
source_archive = Reference(
76
schema=IArchive, title=_('Source Archive'),
77
required=True, readonly=True)
79
target_archive_id = Int(
80
title=_('Target Archive ID'),
81
required=True, readonly=True)
83
target_archive = Reference(
84
schema=IArchive, title=_('Target Archive'),
85
required=True, readonly=True)
87
target_distroseries = Reference(
88
schema=IDistroSeries, title=_('Target DistroSeries.'),
89
required=True, readonly=True)
91
package_name = TextLine(
92
title=_("Package name"), required=True, readonly=True)
94
package_version = TextLine(
95
title=_("Package version"), required=True, readonly=True)
98
schema=IJob, title=_('The common Job attributes'),
99
required=True, readonly=True)
101
component_name = TextLine(
102
title=_("Component override name"), required=False, readonly=True)
104
section_name = TextLine(
105
title=_("Section override name"), required=False, readonly=True)
107
metadata = Attribute(_("A dict of data about the job."))
110
class IPackageCopyJob(IPackageCopyJobPublic, IPackageCopyJobEdit):
111
"""An `IJob` representing a copy of packages between places."""
114
class PackageCopyJobType(DBEnumeratedType):
116
PLAIN = DBItem(1, """
117
Copy packages between archives.
119
This job copies one or more packages, optionally including binaries.
123
class IPlainPackageCopyJobSource(IJobSource):
124
"""An interface for acquiring `IPackageCopyJobs`."""
126
def create(package_name, source_archive,
127
target_archive, target_distroseries, target_pocket,
128
include_binaries=False, package_version=None,
129
copy_policy=PackageCopyPolicy.INSECURE, requester=None):
130
"""Create a new `IPlainPackageCopyJob`.
132
:param package_name: The name of the source package to copy.
133
:param source_archive: The `IArchive` in which `source_packages` are
135
:param target_archive: The `IArchive` to which to copy the packages.
136
:param target_distroseries: The `IDistroSeries` to which to copy the
138
:param target_pocket: The pocket into which to copy the packages. Must
139
be a member of `PackagePublishingPocket`.
140
:param include_binaries: See `do_copy`.
141
:param package_version: The version string for the package version
142
that is to be copied.
143
:param copy_policy: Applicable `PackageCopyPolicy`.
144
:param requester: The user requesting the copy.
147
def createMultiple(target_distroseries, copy_tasks, requester,
148
copy_policy=PackageCopyPolicy.INSECURE,
149
include_binaries=False):
150
"""Create multiple new `IPlainPackageCopyJob`s at once.
152
:param target_distroseries: The `IDistroSeries` to which to copy the
154
:param copy_tasks: A list of tuples describing the copies to be
155
performed: (package name, package version, source archive,
156
target archive, target pocket).
157
:param requester: The user requesting the copy.
158
:param copy_policy: Applicable `PackageCopyPolicy`.
159
:param include_binaries: As in `do_copy`.
160
:return: An iterable of `PackageCopyJob` ids.
163
def getActiveJobs(target_archive):
164
"""Retrieve all active sync jobs for an archive."""
166
def getPendingJobsPerPackage(target_series):
167
"""Find pending jobs for each package in `target_series`.
169
This is meant for finding jobs that will resolve specific
170
`DistroSeriesDifference`s.
172
:param target_series: Target `DistroSeries`; this corresponds to
173
`DistroSeriesDifference.derived_series`.
174
:return: A dict containing as keys the (name, version) tuples for
175
each `DistroSeriesDifference` that has a resolving
176
`PlainPackageCopyJob` pending. Each of these DSDs maps to its
177
oldest pending job. The `version` corresponds to
178
`DistroSeriesDifference.parent_source_version`.
182
class IPlainPackageCopyJob(IRunnableJob):
183
"""A no-frills job to copy packages between `IArchive`s."""
186
title=_("Target package publishing pocket"), required=True,
189
include_binaries = Bool(
190
title=_("Copy binaries"),
191
required=False, readonly=True)
193
def addSourceOverride(override):
194
"""Add an `ISourceOverride` to the metadata."""
196
def getSourceOverride():
197
"""Get an `ISourceOverride` from the metadata."""
199
copy_policy = Choice(
200
title=_("Applicable copy policy"),
201
values=PackageCopyPolicy, required=True, readonly=True)