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