~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-19 04:01:37 UTC
  • mfrom: (13970.7.23 port-to-LaunchpadScript)
  • Revision ID: launchpad@pqm.canonical.com-20110919040137-sr8154o9tfptnqir
[r=sinzui][no-qa] Port a dozen scripts to LaunchpadScript,
        removing their direct initZopeless dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
A kind of archive garbage collector, supersede NBS binaries (not build
11
11
from source).
12
12
"""
 
13
 
13
14
import _pythonpath
14
 
import optparse
15
 
import sys
16
15
 
17
16
from canonical.config import config
18
 
from canonical.launchpad.scripts import (
19
 
    execute_zcml_for_scripts, logger, logger_options)
 
17
from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure
20
18
from lp.soyuz.scripts.ftpmaster import (
21
19
    ArchiveCruftChecker, ArchiveCruftCheckerError)
22
 
from canonical.lp import initZopeless
23
 
from contrib.glock import GlobalLock
24
 
 
25
 
 
26
 
def main():
27
 
    # Parse command-line arguments
28
 
    parser = optparse.OptionParser()
29
 
 
30
 
    logger_options(parser)
31
 
 
32
 
    parser.add_option(
33
 
        "-d", "--distro", dest="distro", help="remove from DISTRO")
34
 
    parser.add_option(
35
 
        "-n", "--no-action", dest="action", default=True,
36
 
        action="store_false", help="don't do anything")
37
 
    parser.add_option(
38
 
        "-s", "--suite", dest="suite", help="only act on SUITE")
39
 
 
40
 
    (options, args) = parser.parse_args()
41
 
 
42
 
    log = logger(options, "archive-cruft-check")
43
 
 
44
 
    log.debug("Acquiring lock")
45
 
    lock = GlobalLock('/var/lock/launchpad-archive-cruft-check.lock')
46
 
    lock.acquire(blocking=True)
47
 
 
48
 
    log.debug("Initializing connection.")
49
 
    execute_zcml_for_scripts()
50
 
    ztm = initZopeless(dbuser=config.archivepublisher.dbuser)
51
 
 
52
 
 
53
 
    if len(args) > 0:
54
 
        archive_path = args[0]
55
 
    else:
56
 
        log.error('ARCHIVEPATH is require')
57
 
        return 1
58
 
 
59
 
    checker = ArchiveCruftChecker(
60
 
        log, distribution_name=options.distro, suite=options.suite,
61
 
        archive_path=archive_path)
62
 
 
63
 
    try:
64
 
        checker.initialize()
65
 
    except ArchiveCruftCheckerError, info:
66
 
        log.error(info)
67
 
        return 1
68
 
 
69
 
# XXX cprov 2007-06-26 bug=121784: Disabling by distro-team request.
70
 
#    if checker.nbs_to_remove and options.action:
71
 
#        checker.doRemovals()
72
 
#        ztm.commit()
73
 
 
74
 
    lock.release()
75
 
    return 0
76
 
 
 
20
 
 
21
 
 
22
class ArchiveCruftCheckerScript(LaunchpadScript):
 
23
 
 
24
    usage = "Usage: archive-cruft-check.py [options] <ARCHIVE_PATH>"
 
25
 
 
26
    def add_my_options(self):
 
27
        self.parser.add_option(
 
28
            "-d", "--distro", dest="distro", help="remove from DISTRO")
 
29
        self.parser.add_option(
 
30
            "-n", "--no-action", dest="action", default=True,
 
31
            action="store_false", help="don't do anything")
 
32
        self.parser.add_option(
 
33
            "-s", "--suite", dest="suite", help="only act on SUITE")
 
34
 
 
35
    def main(self):
 
36
        if len(self.args) != 1:
 
37
            self.parser.error('ARCHIVEPATH is require')
 
38
        archive_path = self.args[0]
 
39
 
 
40
        checker = ArchiveCruftChecker(
 
41
            self.logger, distribution_name=self.options.distro,
 
42
            suite=self.options.suite, archive_path=archive_path)
 
43
 
 
44
        try:
 
45
            checker.initialize()
 
46
        except ArchiveCruftCheckerError, info:
 
47
            raise LaunchpadScriptFailure(info)
 
48
 
 
49
        # XXX cprov 2007-06-26 bug=121784: Disabling by distro-team request.
 
50
        #    if checker.nbs_to_remove and options.action:
 
51
        #        checker.doRemovals()
 
52
        #        ztm.commit()
77
53
 
78
54
if __name__ == '__main__':
79
 
    sys.exit(main())
 
55
    ArchiveCruftCheckerScript(
 
56
        'archive-cruft-check', config.archivepublisher.dbuser).lock_and_run()