~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/archivepublisher/scripts/generate_extra_overrides.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-03 17:08:40 UTC
  • mfrom: (14600.3.7 germinate-all-dev-series)
  • Revision ID: launchpad@pqm.canonical.com-20120103170840-qw8albc2cp5bk7ry
[r=wgrant][bug=904538] Let cron.germinate handle multiple dev series.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from germinate.archive import TagFile
18
18
from germinate.germinator import Germinator
19
19
from germinate.log import GerminateFormatter
20
 
from germinate.seeds import SeedStructure
 
20
from germinate.seeds import (
 
21
    SeedError,
 
22
    SeedStructure,
 
23
    )
21
24
from zope.component import getUtility
22
25
 
23
26
from lp.archivepublisher.config import getPubConfig
51
54
 
52
55
 
53
56
def find_operable_series(distribution):
54
 
    """Find a series we can operate on in this distribution.
 
57
    """Find all the series we can operate on in this distribution.
55
58
 
56
59
    We are allowed to modify DEVELOPMENT or FROZEN series, but should leave
57
60
    series with any other status alone.
58
61
    """
59
 
    series = distribution.currentseries
60
 
    if series.status in (SeriesStatus.DEVELOPMENT, SeriesStatus.FROZEN):
61
 
        return series
62
 
    else:
63
 
        return None
 
62
    return [
 
63
        series for series in distribution.series
 
64
        if series.status in (SeriesStatus.DEVELOPMENT, SeriesStatus.FROZEN)]
64
65
 
65
66
 
66
67
class GenerateExtraOverrides(LaunchpadScript):
96
97
                "Distribution '%s' not found." % self.options.distribution)
97
98
 
98
99
        self.series = find_operable_series(self.distribution)
99
 
        if self.series is None:
 
100
        if not self.series:
100
101
            raise LaunchpadScriptFailure(
101
 
                "There is no DEVELOPMENT distroseries for %s." %
 
102
                "There is no DEVELOPMENT or FROZEN distroseries for %s." %
102
103
                self.options.distribution)
103
104
 
104
 
        # Even if DistroSeries.component_names starts including partner, we
105
 
        # don't want it; this applies to the primary archive only.
106
 
        self.components = [component
107
 
                           for component in self.series.component_names
108
 
                           if component != "partner"]
109
 
 
110
105
    def getConfig(self):
111
106
        """Set up a configuration object for this archive."""
112
107
        archive = self.distribution.main_archive
148
143
        self.setUpDirs()
149
144
        self.addLogHandler()
150
145
 
 
146
    def getComponents(self, series):
 
147
        """Get the list of components to process for a given distroseries.
 
148
 
 
149
        Even if DistroSeries.component_names starts including partner,
 
150
        we don't want it; this applies to the primary archive only.
 
151
        """
 
152
        return [component
 
153
                for component in series.component_names
 
154
                if component != "partner"]
 
155
 
151
156
    def makeSeedStructures(self, series_name, flavours, seed_bases=None):
152
157
        structures = {}
153
158
        for flavour in flavours:
154
 
            structures[flavour] = SeedStructure(
155
 
                "%s.%s" % (flavour, series_name), seed_bases=seed_bases)
 
159
            try:
 
160
                structure = SeedStructure(
 
161
                    "%s.%s" % (flavour, series_name), seed_bases=seed_bases)
 
162
                if len(structure):
 
163
                    structures[flavour] = structure
 
164
                else:
 
165
                    self.logger.warning(
 
166
                        "Skipping empty seed structure for %s.%s",
 
167
                        flavour, series_name)
 
168
            except SeedError, e:
 
169
                self.logger.warning(
 
170
                    "Failed to fetch seeds for %s.%s: %s",
 
171
                    flavour, series_name, e)
156
172
        return structures
157
173
 
158
174
    def logGerminateProgress(self, *args):
278
294
        if "build-essential" in structure.names and primary_flavour:
279
295
            write_overrides("build-essential", "Build-Essential", "yes")
280
296
 
281
 
    def germinateArch(self, override_file, series_name, arch, flavours,
282
 
                      structures):
 
297
    def germinateArch(self, override_file, series_name, components, arch,
 
298
                      flavours, structures):
283
299
        """Germinate seeds on all flavours for a single architecture."""
284
300
        germinator = Germinator(arch)
285
301
 
286
302
        # Read archive metadata.
287
303
        archive = TagFile(
288
 
            series_name, self.components, arch,
 
304
            series_name, components, arch,
289
305
            "file://%s" % self.config.archiveroot, cleanup=True)
290
306
        germinator.parse_archive(archive)
291
307
 
302
318
                override_file, germinator, series_name, arch, flavour,
303
319
                structures[flavour], flavour == flavours[0])
304
320
 
305
 
    def generateExtraOverrides(self, series_name, series_architectures,
 
321
    def generateExtraOverrides(self, series_name, components, architectures,
306
322
                               flavours, seed_bases=None):
307
323
        structures = self.makeSeedStructures(
308
324
            series_name, flavours, seed_bases=seed_bases)
309
325
 
310
 
        override_path = os.path.join(
311
 
            self.config.miscroot,
312
 
            "more-extra.override.%s.main" % series_name)
313
 
        with AtomicFile(override_path) as override_file:
314
 
            for arch in series_architectures:
315
 
                self.germinateArch(
316
 
                    override_file, series_name, arch, flavours, structures)
 
326
        if structures:
 
327
            override_path = os.path.join(
 
328
                self.config.miscroot,
 
329
                "more-extra.override.%s.main" % series_name)
 
330
            with AtomicFile(override_path) as override_file:
 
331
                for arch in architectures:
 
332
                    self.germinateArch(
 
333
                        override_file, series_name, components, arch,
 
334
                        flavours, structures)
317
335
 
318
336
    def process(self, seed_bases=None):
319
337
        """Do the bulk of the work."""
320
338
        self.setUp()
321
339
 
322
 
        series_name = self.series.name
323
 
        series_architectures = sorted(
324
 
            [arch.architecturetag for arch in self.series.architectures])
 
340
        for series in self.series:
 
341
            series_name = series.name
 
342
            components = self.getComponents(series)
 
343
            architectures = sorted(
 
344
                [arch.architecturetag for arch in series.architectures])
325
345
 
326
 
        # This takes a while.  Ensure that we do it without keeping a
327
 
        # database transaction open.
328
 
        self.txn.commit()
329
 
        with DatabaseBlockedPolicy():
330
 
            self.generateExtraOverrides(
331
 
                series_name, series_architectures, self.args,
332
 
                seed_bases=seed_bases)
 
346
            # This takes a while.  Ensure that we do it without keeping a
 
347
            # database transaction open.
 
348
            self.txn.commit()
 
349
            with DatabaseBlockedPolicy():
 
350
                self.generateExtraOverrides(
 
351
                    series_name, components, architectures, self.args,
 
352
                    seed_bases=seed_bases)
333
353
 
334
354
    def main(self):
335
355
        """See `LaunchpadScript`."""