~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
#!/usr/bin/env python
# Copyright 2004 Canonical Ltd.  All rights reserved.
# Author: Daniel Silverstone <daniel.silverstone@canonical.com>
#         Celso Providelo <celso.providelo@canonical.com>
#
# Build Jobs initialization
# 
__metaclass__ = type

import sys
import logging
from optparse import OptionParser

from zope.component import getUtility

from canonical.lp import initZopeless
from canonical.launchpad.interfaces import IDistroArchReleaseSet

from canonical.launchpad.scripts.builddmaster import BuilddMaster
from canonical.launchpad.scripts.lockfile import LockFile
from canonical.launchpad.scripts import (
    execute_zcml_for_scripts, logger_options, logger
    )

_default_lockfile = '/var/lock/buildd-master.lock'


def rebuildQueue(log):
    """Look for and initialise new build jobs."""
    # XXX cprov 20051019
    # retrive the user infromation from the config file
    
    # setup a transaction manager
    tm = initZopeless(dbuser='fiera')
    
    buildMaster = BuilddMaster(log, tm)

    # Simple container
    distroreleases = set()
        
    # For every distroarchrelease we can find; put it into the build master
    for archrelease in getUtility(IDistroArchReleaseSet):
        distroreleases.add(archrelease.distrorelease)
        buildMaster.addDistroArchRelease(archrelease)
        
    # For each distrorelease we care about; scan for sourcepackagereleases
    # with no build associated with the distroarchreleases we're
    # interested in
    for distrorelease in distroreleases:
        buildMaster.createMissingBuilds(distrorelease)

    # For each build record in NEEDSBUILD, ensure it has a
    #buildqueue entry
    buildMaster.addMissingBuildQueueEntries()
                
    #Rescore the NEEDSBUILD properly
    buildMaster.sanitiseAndScoreCandidates()
 
if __name__ == '__main__':
    parser = OptionParser()
    logger_options(parser)
    (options, arguments) = parser.parse_args()

    if arguments:
        parser.error("Unhandled arguments %r" % arguments)

    execute_zcml_for_scripts()

    log = logger(options, 'queuebuilder')

    log.info("Rebuilding Build Queue.")

    locker = LockFile(_default_lockfile, logger=log)
    try:
        locker.acquire()
    except OSError:
        logger.info("Cannot Acquire Lock.")
        sys.exit(1)

    try:
        rebuildQueue(log)
    finally:
        locker.release()
    
    log.info("Buildd Queue Rebuilt.")