~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
__metaclass__ = type
6
6
__all__ = [
7
7
    "PackageCopyJob",
8
8
    "PlainPackageCopyJob",
 
9
    "specify_dsd_package",
9
10
]
10
11
 
11
12
from lazr.delegates import delegates
46
47
from lp.soyuz.scripts.packagecopier import do_copy
47
48
 
48
49
 
 
50
def specify_dsd_package(dsd):
 
51
    """Return (name, parent version) for `dsd`'s package.
 
52
 
 
53
    This describes the package that `dsd` is for in a format suitable for
 
54
    `PlainPackageCopyJobSource`.
 
55
 
 
56
    :param dsd: A `DistroSeriesDifference`.
 
57
    """
 
58
    return (dsd.source_package_name.name, dsd.parent_source_version)
 
59
 
 
60
 
49
61
class PackageCopyJob(StormBase):
50
62
    """Base class for package copying jobs."""
51
63
 
174
186
            PackageCopyJob.target_archive == target_archive)
175
187
        return DecoratedResultSet(jobs, cls)
176
188
 
 
189
    @classmethod
 
190
    def getPendingJobsForTargetSeries(cls, target_series):
 
191
        """Get upcoming jobs for `target_series`, ordered by age."""
 
192
        raw_jobs = IStore(PackageCopyJob).find(
 
193
            PackageCopyJob,
 
194
            Job.id == PackageCopyJob.job_id,
 
195
            PackageCopyJob.job_type == cls.class_job_type,
 
196
            PackageCopyJob.target_distroseries == target_series,
 
197
            Job._status.is_in(Job.PENDING_STATUSES))
 
198
        raw_jobs = raw_jobs.order_by(PackageCopyJob.id)
 
199
        return DecoratedResultSet(raw_jobs, cls)
 
200
 
 
201
    @classmethod
 
202
    def getPendingJobsPerPackage(cls, target_series):
 
203
        """See `IPlainPackageCopyJobSource`."""
 
204
        result = {}
 
205
        # Go through jobs in-order, picking the first matching job for
 
206
        # any (package, version) tuple.  Because of how
 
207
        # getPendingJobsForTargetSeries orders its results, the first
 
208
        # will be the oldest and thus presumably the first to finish.
 
209
        for job in cls.getPendingJobsForTargetSeries(target_series):
 
210
            for package in job.metadata["source_packages"]:
 
211
                result.setdefault(tuple(package), job)
 
212
        return result
 
213
 
177
214
    @property
178
215
    def source_packages(self):
179
216
        getPublishedSources = self.source_archive.getPublishedSources