~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.7 by Karl Fogel
Add the copyright header block to more files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
4935.3.7 by Curtis Hovey
Added bad name suppression to cronscripts.
6
# pylint: disable-msg=C0103,W0403
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
7
8
# This script updates the cached stats in the system
9
2125 by Canonical.com Patch Queue Manager
[r=bjornt] Cronscript refactorings
10
import _pythonpath
11
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
12
from zope.component import getUtility
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
13
from canonical.database.sqlbase import ISOLATION_LEVEL_READ_COMMITTED
11882.2.2 by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces.
14
from canonical.launchpad.interfaces.launchpadstatistic import (
15
    ILaunchpadStatisticSet,
16
    )
8356.1.1 by Leonard Richardson
Partial move.
17
from lp.services.scripts.base import LaunchpadCronScript
11882.2.2 by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces.
18
from lp.registry.interfaces.distribution import IDistributionSet
19
from lp.registry.interfaces.person import IPersonSet
2189 by Canonical.com Patch Queue Manager
properly stash launchpad statistics in the db [r=stevea]
20
from canonical.config import config
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
21
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
22
4264.2.1 by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it
23
class StatUpdater(LaunchpadCronScript):
12415.1.1 by William Grant
Stop using txn.set_isolation_level in scripts... run() has an argument for that purpose.
24
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
25
    def main(self):
26
        self.logger.debug('Starting the stats update')
27
28
        # Note that we do not issue commits here in the script; content
29
        # objects are responsible for committing.
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
30
        distroset = getUtility(IDistributionSet)
31
        for distro in distroset:
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
32
            for distroseries in distro.series:
4285.2.3 by Mark Shuttleworth
Test fixes for renamed DistroSeries
33
                distroseries.updateStatistics(self.txn)
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
34
3617.1.2 by Steve Alexander
removed lib/canonical/rosetta, and changed _clearCache to the public API clear_current_connection_cache
35
        launchpad_stats = getUtility(ILaunchpadStatisticSet)
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
36
        launchpad_stats.updateStatistics(self.txn)
37
38
        getUtility(IPersonSet).updateStatistics(self.txn)
39
40
        self.logger.debug('Finished the stats update')
41
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
42
43
if __name__ == '__main__':
12415.1.1 by William Grant
Stop using txn.set_isolation_level in scripts... run() has an argument for that purpose.
44
    script = StatUpdater('launchpad-stats', dbuser=config.statistician.dbuser)
45
    script.lock_and_run(isolation=ISOLATION_LEVEL_READ_COMMITTED)