~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python -S
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Archive Override Check

Given a distribution to run on, report any override inconsistence found.
It basically check if all published source and binaries are coherent.
"""

import _pythonpath

import transaction
from zope.component import getUtility

from lp.app.errors import NotFoundError
from lp.registry.interfaces.distribution import IDistributionSet
from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.services.config import config
from lp.services.scripts.base import LaunchpadScript
from lp.soyuz.enums import PackagePublishingStatus
from lp.soyuz.scripts.ftpmaster import PubSourceChecker


class ArchiveOverrideCheckScript(LaunchpadScript):

    def add_my_options(self):
        self.parser.add_option(
            "-d", "--distribution", action="store",
            dest="distribution", metavar="DISTRO", default="ubuntu",
            help="Distribution to consider")
        self.parser.add_option(
            "-s", "--suite", action="store",
            dest="suite", metavar="SUITE", default=None,
            help=("Suite to consider, if not passed consider the "
                  "currentseries and the RELEASE pocket"))

    def main(self):
        try:
            try:
                distribution = getUtility(IDistributionSet)[
                    self.options.distribution]
                if self.options.suite is None:
                    distroseries = distribution.currentseries
                    pocket = PackagePublishingPocket.RELEASE
                else:
                    distroseries, pocket = (
                        distribution.getDistroSeriesAndPocket(
                            self.options.suite))

                self.logger.debug(
                    "Considering: %s/%s/%s/%s."
                    % (distribution.name, distroseries.name, pocket.name,
                       distroseries.status.name))

                checkOverrides(distroseries, pocket, self.logger)
            except NotFoundError, info:
                self.logger.error('Not found: %s' % info)
        finally:
            self.logger.debug("Rolling back any remaining transactions.")
            transaction.abort()


def checkOverrides(distroseries, pocket, log):
    """Initialize and handle PubSourceChecker.

    Iterate over PUBLISHED sources and perform PubSourceChecker.check()
    on each published Source/Binaries couple.
    """
    spps = distroseries.getSourcePackagePublishing(
        status=PackagePublishingStatus.PUBLISHED,
        pocket=pocket)

    log.debug('%s published sources' % spps.count())

    for spp in spps:
        spr = spp.sourcepackagerelease
        checker = PubSourceChecker(
            spr.name, spr.version, spp.component.name, spp.section.name,
            spr.urgency.name)

        for bpp in spp.getPublishedBinaries():
            bpr = bpp.binarypackagerelease
            checker.addBinary(
                bpr.name, bpr.version, bpp.distroarchseries.architecturetag,
                bpp.component.name, bpp.section.name, bpr.priority.name)

        checker.check()

        report = checker.renderReport()

        if report:
            print report

if __name__ == '__main__':
    script = ArchiveOverrideCheckScript(
        'archive-override-check', config.archivepublisher.dbuser)
    script.lock_and_run()