10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
1 |
#
|
2 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
3 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
4 |
||
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
5 |
import sys |
6 |
||
12506.2.3
by William Grant
Add P-a-s support. |
7 |
from canonical.config import config |
11270.1.3
by Tim Penhey
Changed NotFoundError imports - gee there were a lot of them. |
8 |
from lp.app.errors import NotFoundError |
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
9 |
from lp.services.scripts.base import LaunchpadScriptFailure |
12506.2.3
by William Grant
Add P-a-s support. |
10 |
from lp.soyuz.pas import BuildDaemonPackagesArchSpecific |
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
11 |
from lp.soyuz.scripts.ftpmasterbase import ( |
12 |
SoyuzScript, |
|
13 |
SoyuzScriptError, |
|
14 |
)
|
|
11411.6.12
by Julian Edwards
Move PackagePublishingStatus/Priority |
15 |
from lp.soyuz.enums import PackagePublishingStatus |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
16 |
|
17 |
||
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
18 |
class AddMissingBuilds(SoyuzScript): |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
19 |
"""Helper class to create builds in PPAs for requested architectures."""
|
20 |
||
12506.2.3
by William Grant
Add P-a-s support. |
21 |
def add_missing_builds(self, archive, required_arches, pas_verify, |
22 |
distroseries, pocket): |
|
12506.2.1
by William Grant
Rename ppa-add-missing-builds to add-missing-builds. It will soon work for any archive. |
23 |
"""Create builds in an archive as necessary.
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
24 |
|
12506.2.1
by William Grant
Rename ppa-add-missing-builds to add-missing-builds. It will soon work for any archive. |
25 |
:param archive: The `Archive`.
|
26 |
:param required_arches: A list of `DistroArchSeries`.
|
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
27 |
:param distroseries: The context `DistroSeries` in which to create
|
28 |
builds.
|
|
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
29 |
:param pocket: The context `PackagePublishingPocket`.
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
30 |
"""
|
31 |
# Listify the architectures to avoid hitting this MultipleJoin
|
|
32 |
# multiple times.
|
|
33 |
distroseries_architectures = list(distroseries.architectures) |
|
34 |
if not distroseries_architectures: |
|
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
35 |
self.logger.error( |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
36 |
"No architectures defined for %s, skipping" |
37 |
% distroseries.name) |
|
38 |
return
|
|
39 |
||
7675.884.3
by William Grant
Rename (I)DistroSeries.enabled_architectures to the more accurate (I)DistroSeries.buildable_architectures. |
40 |
architectures_available = set(distroseries.buildable_architectures) |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
41 |
if not architectures_available: |
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
42 |
self.logger.error( |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
43 |
"Chroots missing for %s" % distroseries.name) |
44 |
return
|
|
45 |
||
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
46 |
self.logger.info( |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
47 |
"Supported architectures in %s: %s" % ( |
48 |
distroseries.name, |
|
10147.5.12
by Julian Edwards
Remove an un-necesary listification |
49 |
", ".join(arch_series.architecturetag |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
50 |
for arch_series in architectures_available))) |
51 |
||
52 |
required_arch_set = set(required_arches) |
|
10147.5.11
by Julian Edwards
Remove an un-necesary listification |
53 |
doable_arch_set = architectures_available.intersection( |
54 |
required_arch_set) |
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
55 |
if len(doable_arch_set) == 0: |
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
56 |
self.logger.error("Requested architectures not available") |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
57 |
return
|
58 |
||
12506.2.1
by William Grant
Rename ppa-add-missing-builds to add-missing-builds. It will soon work for any archive. |
59 |
sources = archive.getPublishedSources( |
10147.5.8
by Julian Edwards
Fix tests up a bit |
60 |
distroseries=distroseries, |
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
61 |
pocket=pocket, |
10147.5.8
by Julian Edwards
Fix tests up a bit |
62 |
status=PackagePublishingStatus.PUBLISHED) |
12505.4.1
by Robert Collins
Hopefully fix bug 727560 by permitting a much better query plan for folk querying the primary archive. |
63 |
sources = list(sources) |
12505.4.6
by Robert Collins
Fix add_missing_builds. |
64 |
if not sources: |
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
65 |
self.logger.info("No sources published, nothing to do.") |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
66 |
return
|
67 |
||
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
68 |
self.logger.info("Creating builds in %s" % |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
69 |
" ".join(arch_series.architecturetag |
70 |
for arch_series in doable_arch_set)) |
|
71 |
for pubrec in sources: |
|
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
72 |
self.logger.info("Considering %s" % pubrec.displayname) |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
73 |
builds = pubrec.createMissingBuilds( |
12506.2.3
by William Grant
Add P-a-s support. |
74 |
architectures_available=doable_arch_set, |
75 |
pas_verify=pas_verify, logger=self.logger) |
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
76 |
if len(builds) > 0: |
10147.5.12
by Julian Edwards
Remove an un-necesary listification |
77 |
self.logger.info("Created %s build(s)" % len(builds)) |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
78 |
|
79 |
def add_my_options(self): |
|
80 |
"""Command line options for this script."""
|
|
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
81 |
self.add_archive_options() |
82 |
self.add_distro_options() |
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
83 |
self.parser.add_option( |
84 |
"-a", action="append", dest='arch_tags', default=[]) |
|
85 |
||
86 |
def main(self): |
|
10147.5.10
by Julian Edwards
fix lint |
87 |
"""Entry point for `LaunchpadScript`s."""
|
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
88 |
try: |
89 |
self.setupLocation() |
|
90 |
except SoyuzScriptError, err: |
|
91 |
raise LaunchpadScriptFailure(err) |
|
92 |
||
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
93 |
if not self.options.arch_tags: |
10147.5.9
by Julian Edwards
Fix broken error reporting |
94 |
self.parser.error("Specify at least one architecture.") |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
95 |
|
96 |
arches = [] |
|
97 |
for arch_tag in self.options.arch_tags: |
|
98 |
try: |
|
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
99 |
das = self.location.distroseries.getDistroArchSeries(arch_tag) |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
100 |
arches.append(das) |
101 |
except NotFoundError: |
|
10147.5.9
by Julian Edwards
Fix broken error reporting |
102 |
self.parser.error( |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
103 |
"%s not a valid architecture for %s" % ( |
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
104 |
arch_tag, self.location.distroseries.name)) |
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
105 |
|
12506.2.3
by William Grant
Add P-a-s support. |
106 |
pas_verify = BuildDaemonPackagesArchSpecific( |
107 |
config.builddmaster.root, self.location.distroseries) |
|
108 |
||
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
109 |
# I'm tired of parsing options. Let's do it.
|
110 |
try: |
|
12506.2.2
by William Grant
Turn add-missing-builds.py into a SoyuzScript, allowing most of its code to be deleted. Also now probably works on primary, but as yet untested. |
111 |
self.add_missing_builds( |
12506.2.3
by William Grant
Add P-a-s support. |
112 |
self.location.archive, arches, pas_verify, |
113 |
self.location.distroseries, self.location.pocket) |
|
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
114 |
self.txn.commit() |
115 |
self.logger.info("Finished adding builds.") |
|
10147.5.5
by Julian Edwards
half way through converting to proper LPscript |
116 |
except Exception, err: |
10147.5.6
by Julian Edwards
Re-factor code to look like a normal LP script. |
117 |
self.logger.error(err) |
118 |
self.txn.abort() |
|
119 |
self.logger.info("Errors, aborted transaction.") |
|
120 |
sys.exit(1) |
|
121 |