~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to scripts/ftpmaster-tools/archive-override-check.py

  • Committer: William Grant
  • Date: 2011-09-18 05:53:11 UTC
  • mto: (13970.10.9 ztm-murder)
  • mto: This revision was merged to the branch mainline in revision 13982.
  • Revision ID: william.grant@canonical.com-20110918055311-bsdlbbfay36lb8zc
archive-override-check.py too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
import _pythonpath
13
13
 
14
 
from optparse import OptionParser
15
 
import sys
16
 
 
 
14
import transaction
17
15
from zope.component import getUtility
18
 
# Still needed fake import to stop circular imports.
19
 
import canonical.launchpad.interfaces
20
16
 
21
17
from canonical.config import config
22
 
from canonical.launchpad.scripts import (
23
 
    execute_zcml_for_scripts, logger, logger_options)
24
18
from lp.app.errors import NotFoundError
25
 
from canonical.lp import initZopeless
26
19
from lp.registry.interfaces.distribution import IDistributionSet
27
20
from lp.registry.interfaces.pocket import PackagePublishingPocket
 
21
from lp.services.scripts.base import LaunchpadScript
28
22
from lp.soyuz.scripts.ftpmaster import PubSourceChecker
29
23
from lp.soyuz.enums import PackagePublishingStatus
30
24
 
31
 
from contrib.glock import GlobalLock
32
 
 
33
 
def main():
34
 
    # Parse command-line arguments
35
 
    parser = OptionParser()
36
 
    logger_options(parser)
37
 
 
38
 
    parser.add_option("-d", "--distribution", action="store",
39
 
                      dest="distribution", metavar="DISTRO", default="ubuntu",
40
 
                      help="Distribution to consider")
41
 
 
42
 
    parser.add_option("-s", "--suite", action="store",
43
 
                      dest="suite", metavar="SUITE", default=None,
44
 
                      help=("Suite to consider, if not passed consider the "
45
 
                            "currentseries and the RELEASE pocket"))
46
 
 
47
 
    (options, args) = parser.parse_args()
48
 
 
49
 
    log = logger(options, "archive-override-check")
50
 
 
51
 
    log.debug("Acquiring lock")
52
 
    lock = GlobalLock('/var/lock/archive-override-check.lock')
53
 
    lock.acquire(blocking=True)
54
 
 
55
 
    log.debug("Initializing connection.")
56
 
    execute_zcml_for_scripts()
57
 
    ztm = initZopeless(dbuser=config.archivepublisher.dbuser)
58
 
 
59
 
    try:
 
25
 
 
26
class ArchiveOverrideCheckScript(LaunchpadScript):
 
27
 
 
28
    def add_my_options(self):
 
29
        self.parser.add_option(
 
30
            "-d", "--distribution", action="store",
 
31
            dest="distribution", metavar="DISTRO", default="ubuntu",
 
32
            help="Distribution to consider")
 
33
        self.parser.add_option(
 
34
            "-s", "--suite", action="store",
 
35
            dest="suite", metavar="SUITE", default=None,
 
36
            help=("Suite to consider, if not passed consider the "
 
37
                  "currentseries and the RELEASE pocket"))
 
38
 
 
39
    def main(self):
60
40
        try:
61
 
            distribution = getUtility(IDistributionSet)[options.distribution]
62
 
            if options.suite is None:
63
 
                distroseries = distribution.currentseries
64
 
                pocket = PackagePublishingPocket.RELEASE
65
 
            else:
66
 
                distroseries, pocket = distribution.getDistroSeriesAndPocket(
67
 
                    options.suite)
68
 
 
69
 
            log.debug("Considering: %s/%s/%s/%s."
70
 
                      % (distribution.name, distroseries.name, pocket.name,
71
 
                         distroseries.status.name))
72
 
 
73
 
            checkOverrides(distroseries, pocket, log)
74
 
 
75
 
        except NotFoundError, info:
76
 
            log.error('Not found: %s' % info)
77
 
 
78
 
    finally:
79
 
        log.debug("Rolling back any remaining transactions.")
80
 
        ztm.abort()
81
 
        log.debug("Releasing lock")
82
 
        lock.release()
83
 
 
84
 
    return 0
 
41
            try:
 
42
                distribution = getUtility(IDistributionSet)[
 
43
                    self.options.distribution]
 
44
                if self.options.suite is None:
 
45
                    distroseries = distribution.currentseries
 
46
                    pocket = PackagePublishingPocket.RELEASE
 
47
                else:
 
48
                    distroseries, pocket = (
 
49
                        distribution.getDistroSeriesAndPocket(
 
50
                            self.options.suite))
 
51
 
 
52
                self.logger.debug(
 
53
                    "Considering: %s/%s/%s/%s."
 
54
                    % (distribution.name, distroseries.name, pocket.name,
 
55
                       distroseries.status.name))
 
56
 
 
57
                checkOverrides(distroseries, pocket, self.logger)
 
58
            except NotFoundError, info:
 
59
                self.logger.error('Not found: %s' % info)
 
60
        finally:
 
61
            self.logger.debug("Rolling back any remaining transactions.")
 
62
            transaction.abort()
85
63
 
86
64
 
87
65
def checkOverrides(distroseries, pocket, log):
116
94
            print report
117
95
 
118
96
if __name__ == '__main__':
119
 
    sys.exit(main())
120
 
 
 
97
    script = ArchiveOverrideCheckScript(
 
98
        'archive-override-check', config.archivepublisher.dbuser)
 
99
    script.lock_and_run()