~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
8356.1.1 by Leonard Richardson
Partial move.
14
from lp.services.scripts.base import LaunchpadCronScript
2189 by Canonical.com Patch Queue Manager
properly stash launchpad statistics in the db [r=stevea]
15
from canonical.launchpad.interfaces import (
3617.1.2 by Steve Alexander
removed lib/canonical/rosetta, and changed _clearCache to the public API clear_current_connection_cache
16
    IDistributionSet, ILaunchpadStatisticSet, IPersonSet
3058.1.9 by Stuart Bishop
Make PersonSet.personCount and teamsCount use statistics, caculated by update-stats.py
17
    )
2189 by Canonical.com Patch Queue Manager
properly stash launchpad statistics in the db [r=stevea]
18
from canonical.config import config
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
19
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
20
4264.2.1 by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it
21
class StatUpdater(LaunchpadCronScript):
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
    def main(self):
5842.1.1 by James Henstridge
Rename the transaction isolation level constants to match the psycopg2
23
        self.txn.set_isolation_level(ISOLATION_LEVEL_READ_COMMITTED)
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
24
25
        self.logger.debug('Starting the stats update')
26
27
        # Note that we do not issue commits here in the script; content
28
        # objects are responsible for committing.
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
29
        distroset = getUtility(IDistributionSet)
30
        for distro in distroset:
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
31
            for distroseries in distro.series:
4285.2.3 by Mark Shuttleworth
Test fixes for renamed DistroSeries
32
                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...
33
3617.1.2 by Steve Alexander
removed lib/canonical/rosetta, and changed _clearCache to the public API clear_current_connection_cache
34
        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...
35
        launchpad_stats.updateStatistics(self.txn)
36
37
        getUtility(IPersonSet).updateStatistics(self.txn)
38
39
        self.logger.debug('Finished the stats update')
40
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
41
42
if __name__ == '__main__':
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
43
    script = StatUpdater('launchpad-stats',
44
                         dbuser=config.statistician.dbuser)
45
    script.lock_and_run()
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
46