~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-22 05:56:29 UTC
  • mfrom: (13492.1.1 revert-r13485)
  • Revision ID: launchpad@pqm.canonical.com-20110722055629-0y8ss6zvhjcoo12r
[r=wgrant][rollback=13485] Revert r13485. It prevents form pickers
 from being attached to their text widgets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
    'DistroSeriesDifferenceJob',
9
9
    ]
10
10
 
11
 
from storm.expr import And
12
11
from zope.component import getUtility
13
12
from zope.interface import (
14
13
    classProvides,
15
14
    implements,
16
15
    )
17
16
 
18
 
from canonical.database.sqlbase import sqlvalues
19
17
from canonical.launchpad.interfaces.lpstorm import (
20
18
    IMasterStore,
21
19
    IStore,
36
34
    IDistroSeriesDifferenceJobSource,
37
35
    )
38
36
from lp.soyuz.interfaces.packageset import IPackagesetSet
39
 
from lp.soyuz.interfaces.publishing import active_publishing_status
40
37
from lp.soyuz.model.distributionjob import (
41
38
    DistributionJob,
42
39
    DistributionJobDerived,
43
40
    )
44
 
from lp.soyuz.model.publishing import SourcePackagePublishingHistory
45
 
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
46
41
 
47
42
 
48
43
FEATURE_FLAG_ENABLE_MODULE = u"soyuz.derived_series_jobs.enabled"
83
78
    return DistroSeriesDifferenceJob(job)
84
79
 
85
80
 
86
 
def create_multiple_jobs(derived_series, parent_series):
87
 
    """Create a `DistroSeriesDifferenceJob` for all the source packages in
88
 
    archive (optionally limited to the sourcepackagenames passed).
89
 
 
90
 
    :param derived_series: A `DistroSeries` that is assumed to be derived
91
 
        from another one.
92
 
    :param parent_series: A `DistroSeries` that is a parent of
93
 
        `derived_series`.
94
 
    :param archive: A `IArchive` where to find the source packages.
95
 
    """
96
 
    store = IStore(SourcePackageRelease)
97
 
    source_package_releases = store.find(
98
 
        SourcePackageRelease,
99
 
        And(
100
 
            SourcePackagePublishingHistory.sourcepackagerelease ==
101
 
                SourcePackageRelease.id,
102
 
            SourcePackagePublishingHistory.distroseries == derived_series.id,
103
 
            SourcePackagePublishingHistory.status.is_in(
104
 
                active_publishing_status)))
105
 
    nb_jobs = source_package_releases.count()
106
 
    sourcepackagenames = source_package_releases.values(
107
 
        SourcePackageRelease.sourcepackagenameID)
108
 
    job_ids = Job.createMultiple(store, nb_jobs)
109
 
 
110
 
    def composeJobInsertionTuple(derived_series, parent_series,
111
 
                                 sourcepackagename, job_id):
112
 
        data = (
113
 
            derived_series.distribution.id, derived_series.id,
114
 
            DistributionJobType.DISTROSERIESDIFFERENCE, job_id,
115
 
            DistributionJob.serializeMetadata(
116
 
                {'sourcepackagename': sourcepackagename,
117
 
                 'parent_series': parent_series.id}))
118
 
        format_string = "(%s)" % ", ".join(["%s"] * len(data))
119
 
        return format_string % sqlvalues(*data)
120
 
 
121
 
    job_contents = [
122
 
        composeJobInsertionTuple(
123
 
            derived_series, parent_series, sourcepackagename, job_id)
124
 
        for job_id, sourcepackagename in
125
 
            zip(job_ids, sourcepackagenames)]
126
 
 
127
 
    store = IStore(DistributionJob)
128
 
    result = store.execute("""
129
 
        INSERT INTO DistributionJob (
130
 
            distribution, distroseries, job_type, job, json_data)
131
 
        VALUES %s
132
 
        RETURNING id
133
 
        """ % ", ".join(job_contents))
134
 
    return [job_id for job_id, in result]
135
 
 
136
 
 
137
81
def find_waiting_jobs(derived_series, sourcepackagename, parent_series=None):
138
82
    """Look for pending `DistroSeriesDifference` jobs on a package."""
139
83
    # Look for identical pending jobs.  This compares directly on
231
175
        return jobs
232
176
 
233
177
    @classmethod
234
 
    def massCreateForSeries(cls, derived_series, parent_series):
235
 
        """See `IDistroSeriesDifferenceJobSource`."""
236
 
        if not getFeatureFlag(FEATURE_FLAG_ENABLE_MODULE):
237
 
            return
238
 
        create_multiple_jobs(derived_series, parent_series)
239
 
 
240
 
    @classmethod
241
178
    def getPendingJobsForDifferences(cls, derived_series,
242
179
                                     distroseriesdifferences):
243
180
        """See `IDistroSeriesDifferenceJobSource`."""