20
20
__metaclass__ = type
29
28
from zope.component import getUtility
31
30
from canonical import lp
32
31
from canonical.config import config
33
32
from canonical.launchpad.scripts import log
35
33
from lp.services.scripts.base import LaunchpadCronScript
36
34
from lp.soyuz.interfaces.component import IComponentSet
37
35
from lp.soyuz.scripts.gina import ExecutionError
38
from lp.soyuz.scripts.gina.katie import Katie
39
36
from lp.soyuz.scripts.gina.archive import (
40
37
ArchiveComponentItems,
41
38
MangledArchiveError,
101
98
LIBRPORT = config.librarian.upload_port
104
log.info("=== Processing %s/%s/%s ===" % (distro, distroseries, pocket))
105
log.debug("Packages read from: %s" % package_root)
106
log.debug("Keyrings read from: %s" % keyrings_root)
107
log.info("Components to import: %s" % ", ".join(components))
101
log.info("=== Processing %s/%s/%s ===", distro, distroseries, pocket)
102
log.debug("Packages read from: %s", package_root)
103
log.debug("Keyrings read from: %s", keyrings_root)
104
log.info("Components to import: %s", ", ".join(components))
108
105
if component_override is not None:
109
log.info("Override components to: %s" % component_override)
110
log.info("Architectures to import: %s" % ", ".join(archs))
111
log.debug("Launchpad database: %s" % LPDB)
112
log.debug("Launchpad database host: %s" % LPDB_HOST)
113
log.debug("Launchpad database user: %s" % LPDB_USER)
114
log.info("Katie database: %s" % KTDB)
115
log.info("SourcePackage Only: %s" % source_only)
116
log.info("SourcePackageName Only: %s" % spnames_only)
117
log.debug("Librarian: %s:%s" % (LIBRHOST, LIBRPORT))
118
log.info("Dry run: %s" % (dry_run))
106
log.info("Override components to: %s", component_override)
107
log.info("Architectures to import: %s", ", ".join(archs))
108
log.debug("Launchpad database: %s", LPDB)
109
log.debug("Launchpad database host: %s", LPDB_HOST)
110
log.debug("Launchpad database user: %s", LPDB_USER)
111
log.info("Katie database: %s", KTDB)
112
log.info("SourcePackage Only: %s", source_only)
113
log.info("SourcePackageName Only: %s", spnames_only)
114
log.debug("Librarian: %s:%s", LIBRHOST, LIBRPORT)
115
log.info("Dry run: %s", dry_run)
121
118
if hasattr(PackagePublishingPocket, pocket.upper()):
122
119
pocket = getattr(PackagePublishingPocket, pocket.upper())
124
log.error("Could not find a pocket schema for %s" % pocket)
121
log.error("Could not find a pocket schema for %s", pocket)
127
124
if component_override:
128
125
valid_components = [
129
126
component.name for component in getUtility(IComponentSet)]
130
127
if component_override not in valid_components:
131
log.error("Could not find component %s" % component_override)
128
log.error("Could not find component %s", component_override)
176
173
# Goes over src_map importing the sourcepackages packages.
178
175
npacks = len(packages_map.src_map)
179
log.info('%i Source Packages to be imported' % npacks)
176
log.info('%i Source Packages to be imported', npacks)
181
178
for list_source in sorted(
182
179
packages_map.src_map.values(), key=lambda x: x[0].get("Package")):
199
196
InvalidVersionError, MissingRequiredArguments,
200
197
DisplayNameDecodingError):
202
"Unable to create SourcePackageData for %s" %
199
"Unable to create SourcePackageData for %s",
205
202
except (PoolFileNotFound, ExecutionError):
206
203
# Problems with katie db stuff of opening files
208
"Error processing package files for %s" % package_name)
205
"Error processing package files for %s", package_name)
210
207
except psycopg2.Error:
212
209
"Database errors made me give up: unable to create "
213
"SourcePackage for %s" % package_name)
210
"SourcePackage for %s", package_name)
214
211
importer_handler.abort()
216
213
except MultiplePackageReleaseError:
218
"Database duplication processing %s" % package_name)
215
"Database duplication processing %s", package_name)
221
218
if COUNTDOWN and count % COUNTDOWN == 0:
222
log.warn('%i/%i sourcepackages processed' % (count, npacks))
219
log.warn('%i/%i sourcepackages processed', count, npacks)
225
222
def do_one_sourcepackage(source, kdb, package_root, keyrings,
228
225
if importer_handler.preimport_sourcecheck(source_data):
229
226
# Don't bother reading package information if the source package
230
227
# already exists in the database
231
log.info('%s already exists in the archive' % source_data.package)
228
log.info('%s already exists in the archive', source_data.package)
233
230
source_data.process_package(kdb, package_root, keyrings)
234
231
source_data.ensure_complete(kdb)
244
241
for archtag in packages_map.bin_map.keys():
246
243
npacks = len(packages_map.bin_map[archtag])
247
log.info('%i Binary Packages to be imported for %s' %
245
'%i Binary Packages to be imported for %s', npacks, archtag)
249
246
# Go over binarypackages importing them for this architecture
250
247
for binary in sorted(packages_map.bin_map[archtag].values(),
251
248
key=lambda x: x.get("Package")):
256
253
do_one_binarypackage(binary, archtag, kdb, package_root,
257
254
keyrings, importer_handler)
258
255
except psycopg2.Error:
259
log.exception("Database errors when importing a "
260
"BinaryPackage for %s. Retrying once.."
257
"Database errors when importing a BinaryPackage "
258
"for %s. Retrying once..", package_name)
262
259
importer_handler.abort()
264
261
do_one_binarypackage(binary, archtag, kdb, package_root,
265
262
keyrings, importer_handler)
266
263
except (InvalidVersionError, MissingRequiredArguments):
267
log.exception("Unable to create BinaryPackageData for %s" %
265
"Unable to create BinaryPackageData for %s", package_name)
270
267
except (PoolFileNotFound, ExecutionError):
271
268
# Problems with katie db stuff of opening files
272
log.exception("Error processing package files for %s" %
270
"Error processing package files for %s", package_name)
275
272
except MultiplePackageReleaseError:
276
log.exception("Database duplication processing %s" %
274
"Database duplication processing %s", package_name)
279
276
except psycopg2.Error:
280
log.exception("Database errors made me give up: unable to "
281
"create BinaryPackage for %s" % package_name)
278
"Database errors made me give up: unable to create "
279
"BinaryPackage for %s", package_name)
282
280
importer_handler.abort()
284
282
except NoSourcePackageError:
285
log.exception("Failed to create Binary Package for %s" %
284
"Failed to create Binary Package for %s", package_name)
287
285
nosource.append(binary)
290
288
if COUNTDOWN and count % COUNTDOWN == 0:
291
289
# XXX kiko 2005-10-23: untested
292
log.warn('%i/%i binary packages processed' % (count, npacks))
290
log.warn('%i/%i binary packages processed', count, npacks)
295
293
# XXX kiko 2005-10-23: untested
296
log.warn('%i source packages not found' % len(nosource))
294
log.warn('%i source packages not found', len(nosource))
297
295
for pkg in nosource:
302
300
importer_handler):
303
301
binary_data = BinaryPackageData(**binary)
304
302
if importer_handler.preimport_binarycheck(archtag, binary_data):
305
log.info('%s already exists in the archive' % binary_data.package)
303
log.info('%s already exists in the archive', binary_data.package)
307
305
binary_data.process_package(kdb, package_root, keyrings)
308
306
importer_handler.import_binarypackage(archtag, binary_data)