~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/interfaces/packagecopyjob.py

  • Committer: Curtis Hovey
  • Date: 2011-05-27 21:53:34 UTC
  • mto: This revision was merged to the branch mainline in revision 13136.
  • Revision ID: curtis.hovey@canonical.com-20110527215334-jqlkmt52nnl4bpeh
Moved launchpad.event into registry interfaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
__metaclass__ = type
5
 
 
6
 
__all__ = [
7
 
    "IPackageCopyJob",
8
 
    "IPackageCopyJobEdit",
9
 
    "IPackageCopyJobSource",
10
 
    "IPlainPackageCopyJob",
11
 
    "IPlainPackageCopyJobSource",
12
 
    "PackageCopyJobType",
13
 
    ]
14
 
 
15
 
from lazr.enum import (
16
 
    DBEnumeratedType,
17
 
    DBItem,
18
 
    )
19
 
from lazr.restful.fields import Reference
20
 
from zope.interface import (
21
 
    Attribute,
22
 
    Interface,
23
 
    )
24
 
from zope.schema import (
25
 
    Bool,
26
 
    Choice,
27
 
    Int,
28
 
    TextLine,
29
 
    )
30
 
 
31
 
from canonical.launchpad import _
32
 
from lp.registry.interfaces.distroseries import IDistroSeries
33
 
from lp.services.job.interfaces.job import (
34
 
    IJob,
35
 
    IJobSource,
36
 
    IRunnableJob,
37
 
    )
38
 
from lp.soyuz.enums import PackageCopyPolicy
39
 
from lp.soyuz.interfaces.archive import IArchive
40
 
 
41
 
 
42
 
class IPackageCopyJobSource(Interface):
43
 
    """Utility for `IPackageCopyJob`-implementing types."""
44
 
 
45
 
    def wrap(package_copy_job):
46
 
        """Wrap a `PackageCopyJob` in its concrete implementation type.
47
 
 
48
 
        As a special case, `None` produces `None`.
49
 
 
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`).
54
 
        """
55
 
 
56
 
 
57
 
class IPackageCopyJobEdit(Interface):
58
 
    """Privileged access to an `IPackageCopyJob`."""
59
 
 
60
 
    def extendMetadata(metadata_dict):
61
 
        """Update the job's JSON metadata with items from `metadata_dict`."""
62
 
 
63
 
 
64
 
class IPackageCopyJobPublic(Interface):
65
 
    """The immutable data on an `IPackageCopyJob`, for normal use."""
66
 
 
67
 
    id = Int(
68
 
        title=_('DB ID'), required=True, readonly=True,
69
 
        description=_("The tracking number for this job."))
70
 
 
71
 
    source_archive_id = Int(
72
 
        title=_('Source Archive ID'),
73
 
        required=True, readonly=True)
74
 
 
75
 
    source_archive = Reference(
76
 
        schema=IArchive, title=_('Source Archive'),
77
 
        required=True, readonly=True)
78
 
 
79
 
    target_archive_id = Int(
80
 
        title=_('Target Archive ID'),
81
 
        required=True, readonly=True)
82
 
 
83
 
    target_archive = Reference(
84
 
        schema=IArchive, title=_('Target Archive'),
85
 
        required=True, readonly=True)
86
 
 
87
 
    target_distroseries = Reference(
88
 
        schema=IDistroSeries, title=_('Target DistroSeries.'),
89
 
        required=True, readonly=True)
90
 
 
91
 
    package_name = TextLine(
92
 
        title=_("Package name"), required=True, readonly=True)
93
 
 
94
 
    package_version = TextLine(
95
 
        title=_("Package version"), required=True, readonly=True)
96
 
 
97
 
    job = Reference(
98
 
        schema=IJob, title=_('The common Job attributes'),
99
 
        required=True, readonly=True)
100
 
 
101
 
    component_name = TextLine(
102
 
        title=_("Component override name"), required=False, readonly=True)
103
 
 
104
 
    section_name = TextLine(
105
 
        title=_("Section override name"), required=False, readonly=True)
106
 
 
107
 
    metadata = Attribute(_("A dict of data about the job."))
108
 
 
109
 
 
110
 
class IPackageCopyJob(IPackageCopyJobPublic, IPackageCopyJobEdit):
111
 
    """An `IJob` representing a copy of packages between places."""
112
 
 
113
 
 
114
 
class PackageCopyJobType(DBEnumeratedType):
115
 
 
116
 
    PLAIN = DBItem(1, """
117
 
        Copy packages between archives.
118
 
 
119
 
        This job copies one or more packages, optionally including binaries.
120
 
        """)
121
 
 
122
 
 
123
 
class IPlainPackageCopyJobSource(IJobSource):
124
 
    """An interface for acquiring `IPackageCopyJobs`."""
125
 
 
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`.
131
 
 
132
 
        :param package_name: The name of the source package to copy.
133
 
        :param source_archive: The `IArchive` in which `source_packages` are
134
 
            found.
135
 
        :param target_archive: The `IArchive` to which to copy the packages.
136
 
        :param target_distroseries: The `IDistroSeries` to which to copy the
137
 
            packages.
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.
145
 
        """
146
 
 
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.
151
 
 
152
 
        :param target_distroseries: The `IDistroSeries` to which to copy the
153
 
            packages.
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.
161
 
        """
162
 
 
163
 
    def getActiveJobs(target_archive):
164
 
        """Retrieve all active sync jobs for an archive."""
165
 
 
166
 
    def getPendingJobsPerPackage(target_series):
167
 
        """Find pending jobs for each package in `target_series`.
168
 
 
169
 
        This is meant for finding jobs that will resolve specific
170
 
        `DistroSeriesDifference`s.
171
 
 
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`.
179
 
        """
180
 
 
181
 
 
182
 
class IPlainPackageCopyJob(IRunnableJob):
183
 
    """A no-frills job to copy packages between `IArchive`s."""
184
 
 
185
 
    target_pocket = Int(
186
 
        title=_("Target package publishing pocket"), required=True,
187
 
        readonly=True)
188
 
 
189
 
    include_binaries = Bool(
190
 
        title=_("Copy binaries"),
191
 
        required=False, readonly=True)
192
 
 
193
 
    def addSourceOverride(override):
194
 
        """Add an `ISourceOverride` to the metadata."""
195
 
 
196
 
    def getSourceOverride():
197
 
        """Get an `ISourceOverride` from the metadata."""
198
 
 
199
 
    copy_policy = Choice(
200
 
        title=_("Applicable copy policy"),
201
 
        values=PackageCopyPolicy, required=True, readonly=True)