~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
14612.2.7 by William Grant
scripts
22
import _pythonpath
23
2670 by Canonical.com Patch Queue Manager
[trivial] Gina love
24
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?)
25
import time
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
26
13748.3.3 by Jeroen Vermeulen
Cosmetic.
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
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
30
from lp.services.config import config
14565.2.15 by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts.
31
from lp.services.scripts import log
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
32
from lp.services.scripts.base import LaunchpadCronScript
8294.6.8 by Julian Edwards
Section and component are now moved, and gina imports fixed.
33
from lp.soyuz.interfaces.component import IComponentSet
34
from lp.soyuz.scripts.gina import ExecutionError
13748.3.2 by Jeroen Vermeulen
Lint.
35
from lp.soyuz.scripts.gina.archive import (
36
    ArchiveComponentItems,
37
    MangledArchiveError,
38
    PackagesMap,
39
    )
13850.2.19 by Jeroen Vermeulen
Rename retire.py to dominate.py; more appropriate now.
40
from lp.soyuz.scripts.gina.dominate import dominate_imported_source_packages
13748.3.2 by Jeroen Vermeulen
Lint.
41
from lp.soyuz.scripts.gina.handlers import (
42
    DataSetupError,
43
    ImporterHandler,
44
    MultiplePackageReleaseError,
45
    NoSourcePackageError,
46
    )
47
from lp.soyuz.scripts.gina.packages import (
48
    BinaryPackageData,
49
    DisplayNameDecodingError,
50
    InvalidVersionError,
51
    MissingRequiredArguments,
52
    PoolFileNotFound,
53
    SourcePackageData,
54
    )
55
56
# Set to non-zero if you'd like to be warned every so often
57
COUNTDOWN = 0
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
58
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
59
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
60
def run_gina(options, ztm, target_section):
8294.6.8 by Julian Edwards
Section and component are now moved, and gina imports fixed.
61
    # Avoid circular imports.
9113.7.4 by Jonathan Lange
Update many imports of pocket.
62
    from lp.registry.interfaces.pocket import PackagePublishingPocket
8294.6.8 by Julian Edwards
Section and component are now moved, and gina imports fixed.
63
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
64
    package_root = target_section.root
65
    distro = target_section.distro
5121.2.7 by Stuart Bishop
More required code changes
66
    pocket_distroseries = target_section.pocketrelease
67
    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).
68
    components = [c.strip() for c in target_section.components.split(",")]
69
    archs = [a.strip() for a in target_section.architectures.split(",")]
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
70
    pocket = target_section.pocket
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
71
    component_override = target_section.componentoverride
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
72
    source_only = target_section.source_only
10512.5.4 by Steve Kowalik
And re-add parsing for sourcepackagenames_only.
73
    spnames_only = target_section.sourcepackagenames_only
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
74
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
75
    LIBRHOST = config.librarian.upload_host
76
    LIBRPORT = config.librarian.upload_port
1716.1.211 by Christian Reis
De-lintify and add better exceptions to gina.py
77
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
78
    log.info("")
13748.3.3 by Jeroen Vermeulen
Cosmetic.
79
    log.info("=== Processing %s/%s/%s ===", distro, distroseries, pocket)
80
    log.debug("Packages read from: %s", package_root)
81
    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
82
    if component_override is not None:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
83
        log.info("Override components to: %s", component_override)
84
    log.info("Architectures to import: %s", ", ".join(archs))
13879.1.8 by William Grant
Drop gina's canonical.lp usage.
85
    log.debug("Launchpad database: %s", config.database.rw_main_master)
13748.3.3 by Jeroen Vermeulen
Cosmetic.
86
    log.info("SourcePackage Only: %s", source_only)
87
    log.info("SourcePackageName Only: %s", spnames_only)
88
    log.debug("Librarian: %s:%s", LIBRHOST, LIBRPORT)
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 :-)
89
    log.info("")
1716.1.211 by Christian Reis
De-lintify and add better exceptions to gina.py
90
13748.3.7 by Jeroen Vermeulen
Cosmetic.
91
    if not hasattr(PackagePublishingPocket, pocket.upper()):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
92
        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 :-(
93
        sys.exit(1)
94
13748.3.7 by Jeroen Vermeulen
Cosmetic.
95
    pocket = getattr(PackagePublishingPocket, pocket.upper())
96
4753.4.1 by Julian Edwards
Allow gina to override the component (and thus the archive) when importing
97
    if component_override:
4753.4.2 by Julian Edwards
PEP-8 drives me NUTS.
98
        valid_components = [
99
            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
100
        if component_override not in valid_components:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
101
            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
102
            sys.exit(1)
103
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
104
    try:
6527.11.1 by Celso Providelo
go, gina, go ...
105
        arch_component_items = ArchiveComponentItems(
106
            package_root, pocket_distroseries, components, archs,
107
            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
108
    except MangledArchiveError:
5855.5.1 by Curtis Hovey
Migrate db configuration to lazr.config.
109
        log.exception(
13748.3.3 by Jeroen Vermeulen
Cosmetic.
110
            "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
111
        sys.exit(1)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
112
113
    packages_map = PackagesMap(arch_component_items)
13748.3.7 by Jeroen Vermeulen
Cosmetic.
114
    importer_handler = ImporterHandler(
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
115
        ztm, distro, distroseries, package_root, pocket, component_override)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
116
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
117
    import_sourcepackages(packages_map, package_root, importer_handler)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
118
    importer_handler.commit()
119
13850.2.15 by Jeroen Vermeulen
XXX
120
    # XXX JeroenVermeulen 2011-09-07 bug=843728: Dominate binaries as well.
13850.2.11 by Jeroen Vermeulen
Dominate source packages in gina.
121
    dominate_imported_source_packages(
13969.1.1 by Jeroen Vermeulen
Commit regularly during Gina domination.
122
        ztm, log, distro, distroseries, pocket, packages_map)
13912.3.1 by Jeroen Vermeulen
Forgot to commit.
123
    ztm.commit()
13850.2.11 by Jeroen Vermeulen
Dominate source packages in gina.
124
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
125
    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
126
        log.info('Source only mode... done')
7224.3.1 by Celso Providelo
fixing gina batching mode.
127
        return
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
128
6527.11.1 by Celso Providelo
go, gina, go ...
129
    for archtag in archs:
130
        try:
131
            importer_handler.ensure_archinfo(archtag)
132
        except DataSetupError:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
133
            log.exception("Database setup required for run on %s", archtag)
6527.11.1 by Celso Providelo
go, gina, go ...
134
            sys.exit(1)
135
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
136
    import_binarypackages(packages_map, package_root, 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 :-)
137
    importer_handler.commit()
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
138
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
139
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
140
def attempt_source_package_import(source, package_root, importer_handler):
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
141
    """Attempt to import a source package, and handle typical errors."""
142
    package_name = source.get("Package", "unknown")
143
    try:
144
        try:
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
145
            do_one_sourcepackage(source, package_root, importer_handler)
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
146
        except psycopg2.Error:
147
            log.exception(
148
                "Database error: unable to create SourcePackage for %s. "
149
                "Retrying once..", package_name)
150
            importer_handler.abort()
151
            time.sleep(15)
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
152
            do_one_sourcepackage(source, package_root, importer_handler)
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
153
    except (
154
        InvalidVersionError, MissingRequiredArguments,
155
        DisplayNameDecodingError):
156
        log.exception(
157
            "Unable to create SourcePackageData for %s", package_name)
158
    except (PoolFileNotFound, ExecutionError):
159
        # Problems with katie db stuff of opening files
160
        log.exception("Error processing package files for %s", package_name)
161
    except psycopg2.Error:
162
        log.exception(
163
            "Database errors made me give up: unable to create "
164
            "SourcePackage for %s", package_name)
165
        importer_handler.abort()
166
    except MultiplePackageReleaseError:
167
        log.exception(
168
            "Database duplication processing %s", package_name)
169
170
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
171
def import_sourcepackages(packages_map, package_root, importer_handler):
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
172
    # Goes over src_map importing the sourcepackages packages.
173
    count = 0
174
    npacks = len(packages_map.src_map)
13748.3.3 by Jeroen Vermeulen
Cosmetic.
175
    log.info('%i Source Packages to be imported', npacks)
1716.1.211 by Christian Reis
De-lintify and add better exceptions to gina.py
176
13850.2.1 by Jeroen Vermeulen
Bit of cleanup.
177
    for package in sorted(packages_map.src_map.iterkeys()):
178
        for source in packages_map.src_map[package]:
10512.5.1 by Steve Kowalik
Brutally hack gina to process multiple sources of the same name.
179
            count += 1
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
180
            attempt_source_package_import(
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
181
                source, package_root, importer_handler)
13748.3.4 by Jeroen Vermeulen
Cleanup (and don't skip countdown output when just the right package fails).
182
            if COUNTDOWN and (count % COUNTDOWN == 0):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
183
                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
184
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
185
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
186
def do_one_sourcepackage(source, package_root, 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
187
    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 :-)
188
    if importer_handler.preimport_sourcecheck(source_data):
189
        # Don't bother reading package information if the source package
190
        # already exists in the database
13748.3.3 by Jeroen Vermeulen
Cosmetic.
191
        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
192
        return
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
193
    source_data.process_package(package_root)
194
    source_data.ensure_complete()
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 :-)
195
    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
196
    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 :-)
197
198
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
199
def import_binarypackages(packages_map, package_root, 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 :-)
200
    nosource = []
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
201
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
202
    # 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
203
    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 :-)
204
        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
205
        npacks = len(packages_map.bin_map[archtag])
13748.3.3 by Jeroen Vermeulen
Cosmetic.
206
        log.info(
207
            '%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
208
        # Go over binarypackages importing them for this architecture
13850.2.1 by Jeroen Vermeulen
Bit of cleanup.
209
        for package_name in sorted(packages_map.bin_map[archtag].iterkeys()):
210
            binary = packages_map.bin_map[archtag][package_name]
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
211
            count += 1
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
212
            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?)
213
                try:
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
214
                    do_one_binarypackage(
215
                        binary, archtag, package_root, importer_handler)
5821.10.4 by Celso Providelo
fixing gina tests.
216
                except psycopg2.Error:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
217
                    log.exception(
218
                        "Database errors when importing a BinaryPackage "
219
                        "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?)
220
                    importer_handler.abort()
221
                    time.sleep(15)
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
222
                    do_one_binarypackage(
223
                        binary, archtag, package_root, 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).
224
            except (InvalidVersionError, MissingRequiredArguments):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
225
                log.exception(
226
                    "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).
227
                continue
1716.2.14 by Christian Reis
Cope better with source packages whose DSC refers to files not in the pool
228
            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).
229
                # Problems with katie db stuff of opening files
13748.3.3 by Jeroen Vermeulen
Cosmetic.
230
                log.exception(
231
                    "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
232
                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
233
            except MultiplePackageReleaseError:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
234
                log.exception(
235
                    "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
236
                continue
5821.10.4 by Celso Providelo
fixing gina tests.
237
            except psycopg2.Error:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
238
                log.exception(
239
                    "Database errors made me give up: unable to create "
240
                    "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).
241
                importer_handler.abort()
242
                continue
243
            except NoSourcePackageError:
13748.3.3 by Jeroen Vermeulen
Cosmetic.
244
                log.exception(
245
                    "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).
246
                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
247
                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 :-)
248
249
            if COUNTDOWN and count % COUNTDOWN == 0:
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
250
                # XXX kiko 2005-10-23: untested
13748.3.3 by Jeroen Vermeulen
Cosmetic.
251
                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 :-)
252
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
253
        if nosource:
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
254
            # XXX kiko 2005-10-23: untested
13748.3.3 by Jeroen Vermeulen
Cosmetic.
255
            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 :-)
256
            for pkg in nosource:
2168 by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements.
257
                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 :-)
258
259
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
260
def do_one_binarypackage(binary, archtag, package_root, 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
261
    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
262
    if importer_handler.preimport_binarycheck(archtag, binary_data):
13748.3.3 by Jeroen Vermeulen
Cosmetic.
263
        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.
264
        return
13951.1.1 by Jeroen Vermeulen
First round of Katie/Gina cleanups. Turns out we don't even need Katie.
265
    binary_data.process_package(package_root)
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
266
    importer_handler.import_binarypackage(archtag, binary_data)
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
267
    importer_handler.commit()
268
269
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
270
class Gina(LaunchpadCronScript):
271
272
    def __init__(self):
273
        super(Gina, self).__init__(name='gina', dbuser=config.gina.dbuser)
274
13912.2.1 by Jeroen Vermeulen
Make gina slightly more helpful.
275
    @property
276
    def usage(self):
277
        return "%s [options] (targets|--all)" % sys.argv[0]
278
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
279
    def add_my_options(self):
13912.2.1 by Jeroen Vermeulen
Make gina slightly more helpful.
280
        self.parser.add_option("-a", "--all", action="store_true",
281
            help="Run all sections defined in launchpad.conf (in order)",
282
            dest="all", default=False)
283
        self.parser.add_option("-l", "--list-targets", action="store_true",
284
            help="List configured import targets", dest="list_targets",
285
            default=False)
286
287
    def getConfiguredTargets(self):
288
        """Get the configured import targets.
289
290
        Gina's targets are configured as "[gina_target.*]" sections in the
291
        LAZR config.
292
        """
293
        sections = config.getByCategory('gina_target', [])
294
        targets = [
295
            target.category_and_section_names[1] for target in sections]
296
        if len(targets) == 0:
297
            self.logger.warn("No gina_target entries configured.")
298
        return targets
299
300
    def listTargets(self, targets):
301
        """Print out the given targets list."""
302
        for target in targets:
303
            self.logger.info("Target: %s", target)
304
305
    def getTargets(self, possible_targets):
306
        """Get targets to process."""
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
307
        targets = self.args
308
        if self.options.all:
13912.2.1 by Jeroen Vermeulen
Make gina slightly more helpful.
309
            return list(possible_targets)
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
310
        else:
311
            if not targets:
312
                self.parser.error(
313
                    "Must specify at least one target to run, or --all")
314
            for target in targets:
315
                if target not in possible_targets:
316
                    self.parser.error(
317
                        "No Gina target %s in config file" % target)
13912.2.1 by Jeroen Vermeulen
Make gina slightly more helpful.
318
            return targets
319
320
    def main(self):
321
        possible_targets = self.getConfiguredTargets()
322
323
        if self.options.list_targets:
324
            self.listTargets(possible_targets)
325
            return
326
327
        for target in self.getTargets(possible_targets):
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
328
            target_section = config['gina_target.%s' % target]
329
            run_gina(self.options, self.txn, target_section)
330
331
1964 by Canonical.com Patch Queue Manager
[r=spiv] full gina refactor
332
if __name__ == "__main__":
11416.2.1 by Steve Kowalik
* Brutally hack at gina again, this time making it use LaunchpadCronScript.
333
    gina = Gina()
334
    gina.lock_and_run()