~launchpad-pqm/launchpad/devel

10637.3.15 by Guilherme Salgado
update the shebang lines of a few scripts that still had python2.5 hard-coded
1
#!/usr/bin/python -S
7675.686.4 by Stuart Bishop
Add script to populate DatabaseTableStats
2
# Copyright 2010 Canonical Ltd.  This software is licensed under the
3
# GNU Affero General Public License version 3 (see the file LICENSE).
4
7675.686.10 by Stuart Bishop
Tidy and database table comments
5
"""Populate the DatabaseTableStats and DatabaseCpuStats tables."""
7675.686.4 by Stuart Bishop
Add script to populate DatabaseTableStats
6
7
__metaclass__ = type
8
9
import _pythonpath
10
11
from zope.component import getUtility
12
13
from canonical.launchpad.scripts import db_options
14
from canonical.launchpad.webapp.interfaces import (
15
    IStoreSelector, MAIN_STORE, MASTER_FLAVOR)
16
from lp.services.scripts.base import LaunchpadCronScript
17
7675.686.10 by Stuart Bishop
Tidy and database table comments
18
7675.686.8 by Stuart Bishop
Add database user cpu utilization stats too
19
class UpdateDatabaseStats(LaunchpadCronScript):
7675.686.10 by Stuart Bishop
Tidy and database table comments
20
    """Populate the DatabaseTableStats and DatabaseCpuStats tables."""
7675.686.4 by Stuart Bishop
Add script to populate DatabaseTableStats
21
22
    def main(self):
23
        "Run UpdateDatabaseTableStats."""
24
        store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
7675.686.8 by Stuart Bishop
Add database user cpu utilization stats too
25
26
        # The logic is in a stored procedure because we want to run
27
        # ps(1) on the database server rather than the host this script
28
        # is running on.
29
        self.logger.debug("Invoking update_database_stats()")
30
        store.execute("SELECT update_database_stats()", noresult=True)
31
32
        self.logger.debug("Committing")
7675.686.4 by Stuart Bishop
Add script to populate DatabaseTableStats
33
        store.commit()
34
35
    def add_my_options(self):
36
        """Add standard database command line options."""
37
        db_options(self.parser)
38
39
if __name__ == '__main__':
7675.686.8 by Stuart Bishop
Add database user cpu utilization stats too
40
    script = UpdateDatabaseStats(
41
        'update-database-stats', dbuser='database_stats_update')
7675.686.4 by Stuart Bishop
Add script to populate DatabaseTableStats
42
    script.lock_and_run()
43