44
43
MultiplePackageReleaseError,
45
44
NoSourcePackageError,
47
from lp.soyuz.scripts.gina.katie import Katie
48
46
from lp.soyuz.scripts.gina.packages import (
50
48
DisplayNameDecodingError,
61
def _get_keyring(keyrings_root):
62
# XXX kiko 2005-10-23: untested
64
for keyring in os.listdir(keyrings_root):
65
path = os.path.join(keyrings_root, keyring)
66
keyrings += " --keyring=%s" % path
68
raise AttributeError("Keyrings not found in ./keyrings/")
72
59
def run_gina(options, ztm, target_section):
73
60
# Avoid circular imports.
74
61
from lp.registry.interfaces.pocket import PackagePublishingPocket
76
63
package_root = target_section.root
77
keyrings_root = target_section.keyrings
78
64
distro = target_section.distro
79
# XXX kiko 2005-10-23: I honestly think having a separate distroseries
80
# bit silly. Can't we construct this based on `distroseries-pocket`?
81
65
pocket_distroseries = target_section.pocketrelease
82
66
distroseries = target_section.distroseries
83
67
components = [c.strip() for c in target_section.components.split(",")]
87
71
source_only = target_section.source_only
88
72
spnames_only = target_section.sourcepackagenames_only
90
KTDB = target_section.katie_dbname
92
74
LIBRHOST = config.librarian.upload_host
93
75
LIBRPORT = config.librarian.upload_port
96
78
log.info("=== Processing %s/%s/%s ===", distro, distroseries, pocket)
97
79
log.debug("Packages read from: %s", package_root)
98
log.debug("Keyrings read from: %s", keyrings_root)
99
80
log.info("Components to import: %s", ", ".join(components))
100
81
if component_override is not None:
101
82
log.info("Override components to: %s", component_override)
102
83
log.info("Architectures to import: %s", ", ".join(archs))
103
84
log.debug("Launchpad database: %s", config.database.rw_main_master)
104
log.info("Katie database: %s", KTDB)
105
85
log.info("SourcePackage Only: %s", source_only)
106
86
log.info("SourcePackageName Only: %s", spnames_only)
107
87
log.debug("Librarian: %s:%s", LIBRHOST, LIBRPORT)
120
100
log.error("Could not find component %s", component_override)
126
kdb = Katie(KTDB, distroseries)
127
keyrings = _get_keyring(keyrings_root)
130
104
arch_component_items = ArchiveComponentItems(
131
105
package_root, pocket_distroseries, components, archs,
138
112
packages_map = PackagesMap(arch_component_items)
139
113
importer_handler = ImporterHandler(
140
ztm, distro, distroseries, kdb, package_root, keyrings, pocket,
114
ztm, distro, distroseries, package_root, pocket, component_override)
143
import_sourcepackages(
144
packages_map, kdb, package_root, keyrings, importer_handler)
116
import_sourcepackages(packages_map, package_root, importer_handler)
145
117
importer_handler.commit()
147
119
# XXX JeroenVermeulen 2011-09-07 bug=843728: Dominate binaries as well.
160
132
log.exception("Database setup required for run on %s", archtag)
163
import_binarypackages(
164
packages_map, kdb, package_root, keyrings, importer_handler)
135
import_binarypackages(packages_map, package_root, importer_handler)
165
136
importer_handler.commit()
168
def attempt_source_package_import(source, kdb, package_root, keyrings,
139
def attempt_source_package_import(source, package_root, importer_handler):
170
140
"""Attempt to import a source package, and handle typical errors."""
171
141
package_name = source.get("Package", "unknown")
174
do_one_sourcepackage(
175
source, kdb, package_root, keyrings, importer_handler)
144
do_one_sourcepackage(source, package_root, importer_handler)
176
145
except psycopg2.Error:
178
147
"Database error: unable to create SourcePackage for %s. "
179
148
"Retrying once..", package_name)
180
149
importer_handler.abort()
182
do_one_sourcepackage(
183
source, kdb, package_root, keyrings, importer_handler)
151
do_one_sourcepackage(source, package_root, importer_handler)
185
153
InvalidVersionError, MissingRequiredArguments,
186
154
DisplayNameDecodingError):
199
167
"Database duplication processing %s", package_name)
202
def import_sourcepackages(packages_map, kdb, package_root,
203
keyrings, importer_handler):
170
def import_sourcepackages(packages_map, package_root, importer_handler):
204
171
# Goes over src_map importing the sourcepackages packages.
206
173
npacks = len(packages_map.src_map)
210
177
for source in packages_map.src_map[package]:
212
179
attempt_source_package_import(
213
source, kdb, package_root, keyrings, importer_handler)
180
source, package_root, importer_handler)
214
181
if COUNTDOWN and (count % COUNTDOWN == 0):
215
182
log.warn('%i/%i sourcepackages processed', count, npacks)
218
def do_one_sourcepackage(source, kdb, package_root, keyrings,
185
def do_one_sourcepackage(source, package_root, importer_handler):
220
186
source_data = SourcePackageData(**source)
221
187
if importer_handler.preimport_sourcecheck(source_data):
222
188
# Don't bother reading package information if the source package
223
189
# already exists in the database
224
190
log.info('%s already exists in the archive', source_data.package)
226
source_data.process_package(kdb, package_root, keyrings)
227
source_data.ensure_complete(kdb)
192
source_data.process_package(package_root)
193
source_data.ensure_complete()
228
194
importer_handler.import_sourcepackage(source_data)
229
195
importer_handler.commit()
232
def import_binarypackages(packages_map, kdb, package_root, keyrings,
198
def import_binarypackages(packages_map, package_root, importer_handler):
236
201
# Run over all the architectures we have
248
do_one_binarypackage(binary, archtag, kdb, package_root,
249
keyrings, importer_handler)
213
do_one_binarypackage(
214
binary, archtag, package_root, importer_handler)
250
215
except psycopg2.Error:
252
217
"Database errors when importing a BinaryPackage "
253
218
"for %s. Retrying once..", package_name)
254
219
importer_handler.abort()
256
do_one_binarypackage(binary, archtag, kdb, package_root,
257
keyrings, importer_handler)
221
do_one_binarypackage(
222
binary, archtag, package_root, importer_handler)
258
223
except (InvalidVersionError, MissingRequiredArguments):
260
225
"Unable to create BinaryPackageData for %s", package_name)
294
def do_one_binarypackage(binary, archtag, kdb, package_root, keyrings,
259
def do_one_binarypackage(binary, archtag, package_root, importer_handler):
296
260
binary_data = BinaryPackageData(**binary)
297
261
if importer_handler.preimport_binarycheck(archtag, binary_data):
298
262
log.info('%s already exists in the archive', binary_data.package)
300
binary_data.process_package(kdb, package_root, keyrings)
264
binary_data.process_package(package_root)
301
265
importer_handler.import_binarypackage(archtag, binary_data)
302
266
importer_handler.commit()