~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
#
14027.3.2 by Jeroen Vermeulen
Merge devel, resolve conflicts.
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
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
14612.2.8 by William Grant
cronscripts
11
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
12
from zope.component import getUtility
14027.3.2 by Jeroen Vermeulen
Merge devel, resolve conflicts.
13
11882.2.2 by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces.
14
from lp.registry.interfaces.distribution import IDistributionSet
15
from lp.registry.interfaces.person import IPersonSet
14612.2.8 by William Grant
cronscripts
16
from lp.services.config import config
14027.3.2 by Jeroen Vermeulen
Merge devel, resolve conflicts.
17
from lp.services.scripts.base import LaunchpadCronScript
14612.2.8 by William Grant
cronscripts
18
from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet
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):
12415.1.1 by William Grant
Stop using txn.set_isolation_level in scripts... run() has an argument for that purpose.
22
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
23
    def main(self):
24
        self.logger.debug('Starting the stats update')
25
26
        # Note that we do not issue commits here in the script; content
27
        # objects are responsible for committing.
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
28
        distroset = getUtility(IDistributionSet)
29
        for distro in distroset:
9760.8.1 by Brad Crittenden
Change the non-English 'serieses' to 'series' throughout our codebase.
30
            for distroseries in distro.series:
4285.2.3 by Mark Shuttleworth
Test fixes for renamed DistroSeries
31
                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...
32
3617.1.2 by Steve Alexander
removed lib/canonical/rosetta, and changed _clearCache to the public API clear_current_connection_cache
33
        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...
34
        launchpad_stats.updateStatistics(self.txn)
35
36
        getUtility(IPersonSet).updateStatistics(self.txn)
37
38
        self.logger.debug('Finished the stats update')
39
2075 by Canonical.com Patch Queue Manager
add better distrorelease translation pages, r=salgado
40
41
if __name__ == '__main__':
12415.1.1 by William Grant
Stop using txn.set_isolation_level in scripts... run() has an argument for that purpose.
42
    script = StatUpdater('launchpad-stats', dbuser=config.statistician.dbuser)
14022.3.2 by William Grant
LaunchpadScript no longer uses initZopeless.
43
    script.lock_and_run()