~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py files.
2
#
13748.3.3 by Jeroen Vermeulen
Cosmetic.
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.22 by Karl Fogel
Add the copyright header block to the remaining .py files.
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5883.1.1 by Curtis Hovey
Added gina_target and buildsequence_job to lazr schema.
6
# This module uses relative imports.
5855.5.1 by Curtis Hovey
Migrate db configuration to lazr.config.
7
# pylint: disable-msg=W0403
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
8
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
9
"""
10
Gina launcher script. Handles commandline options and makes the proper
11
calls to the other classes and instances.
12
13
The callstack is essentially:
10303.1.1 by Gary Poster
use newest version of zc.buildout
14
    main -> run_gina
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
15
                -> import_sourcepackages -> do_one_sourcepackage
16
                -> import_binarypackages -> do_one_binarypackage
17
"""
18
5855.5.1 by Curtis Hovey
Migrate db configuration to lazr.config.
19
20
__metaclass__ = type
21
2670 by Canonical.com Patch Queue Manager
[trivial] Gina love
22
import os
23
import sys
1716.1.255 by Christian Reis
Cope with intermittent postgres isolation errors when importing packages (caused one package to fail in breezy, growl). Also stop lowercasing package and version numbers, since they should be compared case-sensitively (right?)
24
import time
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
25
13748.3.3 by Jeroen Vermeulen
Cosmetic.
26
import _pythonpath
27
import psycopg2
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
28
from zope.component import getUtility
29
6555.7.35 by Stuart Bishop
Fix gina tests
30
from canonical import lp
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
31
from canonical.config import config
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
32
from canonical.launchpad.scripts import log
33
from lp.services.scripts.base import LaunchpadCronScript
8294.6.8 by Julian Edwards
Section and component are now moved, and gina imports fixed.
34
from lp.soyuz.interfaces.component import IComponentSet
35
from lp.soyuz.scripts.gina import ExecutionError
13748.3.2 by Jeroen Vermeulen
Lint.
36
from lp.soyuz.scripts.gina.archive import (
37
    ArchiveComponentItems,
38
    MangledArchiveError,
39
    PackagesMap,
40
    )
41
from lp.soyuz.scripts.gina.handlers import (
42
    DataSetupError,
43
    ImporterHandler,
44
    MultiplePackageReleaseError,
45
    NoSourcePackageError,
46
    )
13748.3.3 by Jeroen Vermeulen
Cosmetic.
47
from lp.soyuz.scripts.gina.katie import Katie
13748.3.2 by Jeroen Vermeulen
Lint.
48
from lp.soyuz.scripts.gina.packages import (
49
    BinaryPackageData,
50
    DisplayNameDecodingError,
51
    InvalidVersionError,
52
    MissingRequiredArguments,
53
    PoolFileNotFound,
54
    SourcePackageData,
55
    )
56
57
# Set to non-zero if you'd like to be warned every so often
58
COUNTDOWN = 0
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
59
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
60
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
61
def _get_keyring(keyrings_root):
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
62
    # XXX kiko 2005-10-23: untested
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
63
    keyrings = ""
64
    for keyring in os.listdir(keyrings_root):
65
        path = os.path.join(keyrings_root, keyring)
66
        keyrings += " --keyring=%s" % path
67
    if not keyrings:
68
        raise AttributeError("Keyrings not found in ./keyrings/")
69
    return keyrings
70
71
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
72
def run_gina(options, ztm, target_section):
8294.6.8 by Julian Edwards
Section and component are now moved, and gina imports fixed.
73
    # Avoid circular imports.
9113.7.4 by Jonathan Lange
Update many imports of pocket.
74
    from lp.registry.interfaces.pocket import PackagePublishingPocket
8294.6.8 by Julian Edwards
Section and component are now moved, and gina imports fixed.
75
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
76
    package_root = target_section.root
77
    keyrings_root = target_section.keyrings
78
    distro = target_section.distro
5121.2.7 by Stuart Bishop
More required code changes
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
    pocket_distroseries = target_section.pocketrelease
82
    distroseries = target_section.distroseries
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
83
    components = [c.strip() for c in target_section.components.split(",")]
84
    archs = [a.strip() for a in target_section.architectures.split(",")]
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
85
    pocket = target_section.pocket
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
86
    component_override = target_section.componentoverride
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
87
    source_only = target_section.source_only
10512.5.4 by Steve Kowalik
And re-add parsing for sourcepackagenames_only.
88
    spnames_only = target_section.sourcepackagenames_only
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
89
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
90
    dry_run = options.dry_run
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
91
11737.2.20 by William Grant
Fix two missed canonical.lp.dbname references.
92
    LPDB = lp.get_dbname()
6555.7.35 by Stuart Bishop
Fix gina tests
93
    LPDB_HOST = lp.dbhost
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
94
    LPDB_USER = config.gina.dbuser
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
95
    KTDB = target_section.katie_dbname
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
96
97
    LIBRHOST = config.librarian.upload_host
98
    LIBRPORT = config.librarian.upload_port
1716.1.211 by Christian Reis
De-lintify and add better exceptions to gina.py
99
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
100
    log.info("")
13748.3.3 by Jeroen Vermeulen
Cosmetic.
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))
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
105
    if component_override is not None:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
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)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
116
    log.info("")
1716.1.211 by Christian Reis
De-lintify and add better exceptions to gina.py
117
13748.3.7 by Jeroen Vermeulen
Cosmetic.
118
    if not hasattr(PackagePublishingPocket, pocket.upper()):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
119
        log.error("Could not find a pocket schema for %s", pocket)
1716.1.232 by Christian Reis
Set up an initial (empty) multiple-arch-component-pocket run, with a basic test. Also fix up my librarian query to not use selectOneBy. But I had to comment out the check, because staging and production are already polluted :-(
120
        sys.exit(1)
121
13748.3.7 by Jeroen Vermeulen
Cosmetic.
122
    pocket = getattr(PackagePublishingPocket, pocket.upper())
123
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
124
    if component_override:
4753.4.2 by Julian Edwards
PEP-8 drives me NUTS.
125
        valid_components = [
126
            component.name for component in getUtility(IComponentSet)]
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
127
        if component_override not in valid_components:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
128
            log.error("Could not find component %s", component_override)
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
129
            sys.exit(1)
130
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
131
    kdb = None
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
132
    keyrings = None
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
133
    if KTDB:
5121.2.7 by Stuart Bishop
More required code changes
134
        kdb = Katie(KTDB, distroseries, dry_run)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
135
        keyrings = _get_keyring(keyrings_root)
136
137
    try:
6527.11.1 by Celso Providelo
go, gina, go ...
138
        arch_component_items = ArchiveComponentItems(
139
            package_root, pocket_distroseries, components, archs,
140
            source_only)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
141
    except MangledArchiveError:
5855.5.1 by Curtis Hovey
Migrate db configuration to lazr.config.
142
        log.exception(
13748.3.3 by Jeroen Vermeulen
Cosmetic.
143
            "Failed to analyze archive for %s", pocket_distroseries)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
144
        sys.exit(1)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
145
146
    packages_map = PackagesMap(arch_component_items)
13748.3.7 by Jeroen Vermeulen
Cosmetic.
147
    importer_handler = ImporterHandler(
148
        ztm, distro, distroseries, dry_run, kdb, package_root, keyrings,
149
        pocket, component_override)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
150
13748.3.7 by Jeroen Vermeulen
Cosmetic.
151
    import_sourcepackages(
152
        packages_map, kdb, package_root, keyrings, importer_handler)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
153
    importer_handler.commit()
154
155
    if source_only:
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
156
        log.info('Source only mode... done')
7224.3.1 by Celso Providelo
fixing gina batching mode.
157
        return
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
158
6527.11.1 by Celso Providelo
go, gina, go ...
159
    for archtag in archs:
160
        try:
161
            importer_handler.ensure_archinfo(archtag)
162
        except DataSetupError:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
163
            log.exception("Database setup required for run on %s", archtag)
6527.11.1 by Celso Providelo
go, gina, go ...
164
            sys.exit(1)
165
13748.3.7 by Jeroen Vermeulen
Cosmetic.
166
    import_binarypackages(
167
        packages_map, kdb, package_root, keyrings, importer_handler)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
168
    importer_handler.commit()
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
169
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
170
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
171
def attempt_source_package_import(source, kdb, package_root, keyrings,
172
                                  importer_handler):
173
    """Attempt to import a source package, and handle typical errors."""
174
    package_name = source.get("Package", "unknown")
175
    try:
176
        try:
177
            do_one_sourcepackage(
178
                source, kdb, package_root, keyrings, importer_handler)
179
        except psycopg2.Error:
180
            log.exception(
181
                "Database error: unable to create SourcePackage for %s. "
182
                "Retrying once..", package_name)
183
            importer_handler.abort()
184
            time.sleep(15)
185
            do_one_sourcepackage(
186
                source, kdb, package_root, keyrings, importer_handler)
187
    except (
188
        InvalidVersionError, MissingRequiredArguments,
189
        DisplayNameDecodingError):
190
        log.exception(
191
            "Unable to create SourcePackageData for %s", package_name)
192
    except (PoolFileNotFound, ExecutionError):
193
        # Problems with katie db stuff of opening files
194
        log.exception("Error processing package files for %s", package_name)
195
    except psycopg2.Error:
196
        log.exception(
197
            "Database errors made me give up: unable to create "
198
            "SourcePackage for %s", package_name)
199
        importer_handler.abort()
200
    except MultiplePackageReleaseError:
201
        log.exception(
202
            "Database duplication processing %s", package_name)
203
204
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
205
def import_sourcepackages(packages_map, kdb, package_root,
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
206
                          keyrings, importer_handler):
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
207
    # Goes over src_map importing the sourcepackages packages.
208
    count = 0
209
    npacks = len(packages_map.src_map)
13748.3.3 by Jeroen Vermeulen
Cosmetic.
210
    log.info('%i Source Packages to be imported', npacks)
1716.1.211 by Christian Reis
De-lintify and add better exceptions to gina.py
211
10512.5.2 by Steve Kowalik
Slightly refactor to use defaultdict.
212
    for list_source in sorted(
213
        packages_map.src_map.values(), key=lambda x: x[0].get("Package")):
10512.5.1 by Steve Kowalik
Brutally hack gina to process multiple sources of the same name.
214
        for source in list_source:
215
            count += 1
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
216
            attempt_source_package_import(
217
                source, kdb, package_root, keyrings, importer_handler)
218
            if COUNTDOWN and (count % COUNTDOWN == 0):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
219
                log.warn('%i/%i sourcepackages processed', count, npacks)
1716.1.217 by Christian Reis
Fix up remaining SQL issues (manually tested by hacking up gina.py, improve gina.py logging and error output, some added language consistency
220
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
221
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
222
def do_one_sourcepackage(source, kdb, package_root, keyrings,
223
                         importer_handler):
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
224
    source_data = SourcePackageData(**source)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
225
    if importer_handler.preimport_sourcecheck(source_data):
226
        # Don't bother reading package information if the source package
227
        # already exists in the database
13748.3.3 by Jeroen Vermeulen
Cosmetic.
228
        log.info('%s already exists in the archive', source_data.package)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
229
        return
230
    source_data.process_package(kdb, package_root, keyrings)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
231
    source_data.ensure_complete(kdb)
232
    importer_handler.import_sourcepackage(source_data)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
233
    importer_handler.commit()
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
234
235
1716.1.223 by Christian Reis
Checkpoint gina: the sourcepackage side is implemented and well-tested, over two releases, and over two runs of gina
236
def import_binarypackages(packages_map, kdb, package_root, keyrings,
237
                          importer_handler):
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
238
    nosource = []
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
239
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
240
    # Run over all the architectures we have
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
241
    for archtag in packages_map.bin_map.keys():
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
242
        count = 0
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
243
        npacks = len(packages_map.bin_map[archtag])
13748.3.3 by Jeroen Vermeulen
Cosmetic.
244
        log.info(
245
            '%i Binary Packages to be imported for %s', npacks, archtag)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
246
        # Go over binarypackages importing them for this architecture
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
247
        for binary in sorted(packages_map.bin_map[archtag].values(),
1716.1.227 by Christian Reis
Order packages by name when processing them, to obtain stable test output. Add a host of binary packages to hoary to ensure I have enough to test with. Check before importing binary packages that they already exist (as we do for source packages) to optimize processing time and output. Reorganize tests to be a bit more self-contained.
248
                             key=lambda x: x.get("Package")):
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
249
            count += 1
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
250
            package_name = binary.get("Package", "unknown")
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
251
            try:
1716.1.255 by Christian Reis
Cope with intermittent postgres isolation errors when importing packages (caused one package to fail in breezy, growl). Also stop lowercasing package and version numbers, since they should be compared case-sensitively (right?)
252
                try:
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
253
                    do_one_binarypackage(binary, archtag, kdb, package_root,
1716.1.255 by Christian Reis
Cope with intermittent postgres isolation errors when importing packages (caused one package to fail in breezy, growl). Also stop lowercasing package and version numbers, since they should be compared case-sensitively (right?)
254
                                         keyrings, importer_handler)
5821.10.4 by Celso Providelo
fixing gina tests.
255
                except psycopg2.Error:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
256
                    log.exception(
257
                        "Database errors when importing a BinaryPackage "
258
                        "for %s. Retrying once..", package_name)
1716.1.255 by Christian Reis
Cope with intermittent postgres isolation errors when importing packages (caused one package to fail in breezy, growl). Also stop lowercasing package and version numbers, since they should be compared case-sensitively (right?)
259
                    importer_handler.abort()
260
                    time.sleep(15)
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
261
                    do_one_binarypackage(binary, archtag, kdb, package_root,
1716.1.255 by Christian Reis
Cope with intermittent postgres isolation errors when importing packages (caused one package to fail in breezy, growl). Also stop lowercasing package and version numbers, since they should be compared case-sensitively (right?)
262
                                         keyrings, importer_handler)
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
263
            except (InvalidVersionError, MissingRequiredArguments):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
264
                log.exception(
265
                    "Unable to create BinaryPackageData for %s", package_name)
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
266
                continue
1716.2.14 by Christian Reis
Cope better with source packages whose DSC refers to files not in the pool
267
            except (PoolFileNotFound, ExecutionError):
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
268
                # Problems with katie db stuff of opening files
13748.3.3 by Jeroen Vermeulen
Cosmetic.
269
                log.exception(
270
                    "Error processing package files for %s", package_name)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
271
                continue
1716.1.226 by Christian Reis
Moving verification and parsing code over to packages.py, simplifying handlers.py. Also improved the way check_not_in_librarian communicates failures. Added some important XXXs that are a consequence of the use of Teri on the archive. All tests still pass
272
            except MultiplePackageReleaseError:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
273
                log.exception(
274
                    "Database duplication processing %s", package_name)
1716.1.226 by Christian Reis
Moving verification and parsing code over to packages.py, simplifying handlers.py. Also improved the way check_not_in_librarian communicates failures. Added some important XXXs that are a consequence of the use of Teri on the archive. All tests still pass
275
                continue
5821.10.4 by Celso Providelo
fixing gina tests.
276
            except psycopg2.Error:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
277
                log.exception(
278
                    "Database errors made me give up: unable to create "
279
                    "BinaryPackage for %s", package_name)
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
280
                importer_handler.abort()
281
                continue
282
            except NoSourcePackageError:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
283
                log.exception(
284
                    "Failed to create Binary Package for %s", package_name)
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
285
                nosource.append(binary)
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
286
                continue
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
287
288
            if COUNTDOWN and count % COUNTDOWN == 0:
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
289
                # XXX kiko 2005-10-23: untested
13748.3.3 by Jeroen Vermeulen
Cosmetic.
290
                log.warn('%i/%i binary packages processed', count, npacks)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
291
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
292
        if nosource:
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
293
            # XXX kiko 2005-10-23: untested
13748.3.3 by Jeroen Vermeulen
Cosmetic.
294
            log.warn('%i source packages not found', len(nosource))
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
295
            for pkg in nosource:
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
296
                log.warn(pkg)
1716.1.218 by Christian Reis
Add more package data and update the gina doctest. Seriously whack packages.py and gina.py, with some trickle into handlers.py. The creation of source packages for Hoary is now minimally tested, with most important codepaths and error conditions being checked. Did work on validation and ensuring the source and binary package data we have is consistent. Added a ton of packages to the gina test archive so we can use them in our tests -- welcome them into rocketfuel :-)
297
298
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
299
def do_one_binarypackage(binary, archtag, kdb, package_root, keyrings,
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
300
                         importer_handler):
1716.1.219 by Christian Reis
One more step in the direction of gina testing: test the processing of a second distro release. Verify that no duplicate source packages are added. Check for mangled tagfile stanzas. Reorder classes in handlers.py to be more naturally sequenced. Centralize error checking in gina.py so that do_one_*package is what's tested for error raising. Add support files for testing Breezy. More test clauses. I'd estimate I'm 30% done
301
    binary_data = BinaryPackageData(**binary)
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
302
    if importer_handler.preimport_binarycheck(archtag, binary_data):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
303
        log.info('%s already exists in the archive', binary_data.package)
1716.1.227 by Christian Reis
Order packages by name when processing them, to obtain stable test output. Add a host of binary packages to hoary to ensure I have enough to test with. Check before importing binary packages that they already exist (as we do for source packages) to optimize processing time and output. Reorganize tests to be a bit more self-contained.
304
        return
1716.1.225 by Christian Reis
First part of really testing binary packages. Add 14 binary package entries for hoary main. Change the librarian check to be a function so it can be unified between sources and binaries. Bulletproof the test to run under weird filesystem conditions. Make the config a bit less daft. Deal better with corrupt packages files (and entries). Fetch the licence for binary packages properly (the hard way). Clean up the creation of BinaryPackageData. Removed the catch-all except:s which only make my life harder (for now, at least).
305
    binary_data.process_package(kdb, package_root, keyrings)
1716.2.6 by Christian Reis
Move the check for processor to the start of run_gina so we ensure that all processors required are already preseeded in the database before doing /anything/. Clarifies issue in production where a processor for ia64 was missing
306
    importer_handler.import_binarypackage(archtag, binary_data)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
307
    importer_handler.commit()
308
309
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
310
class Gina(LaunchpadCronScript):
311
312
    def __init__(self):
313
        super(Gina, self).__init__(name='gina', dbuser=config.gina.dbuser)
314
315
    def add_my_options(self):
316
        self.parser.add_option("-n", "--dry-run", action="store_true",
317
            help="Don't commit changes to the database",
318
            dest="dry_run", default=False)
319
        self.parser.add_option("-a", "--all", action="store_true",
320
            help="Run all sections defined in launchpad.conf (in order)",
321
            dest="all", default=False)
322
323
    def main(self):
324
        possible_targets = [target.category_and_section_names[1]
325
            for target in config.getByCategory('gina_target')]
326
        targets = self.args
327
        if self.options.all:
328
            targets = possible_targets[:]
329
        else:
330
            if not targets:
331
                self.parser.error(
332
                    "Must specify at least one target to run, or --all")
333
            for target in targets:
334
                if target not in possible_targets:
335
                    self.parser.error(
336
                        "No Gina target %s in config file" % target)
337
338
        for target in targets:
339
            target_section = config['gina_target.%s' % target]
340
            run_gina(self.options, self.txn, target_section)
341
342
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
343
if __name__ == "__main__":
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
344
    gina = Gina()
345
    gina.lock_and_run()