| 1 |
# Copyright 2005 Gentoo Foundation
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
#
|
| 4 |
|
| 5 |
"""Methods for obtaining repo statistics."""
|
| 6 |
|
| 7 |
__revision__ = "$Id$"
|
| 8 |
__authors__ = ["Scott Hadfield <hadfield@gentoo.org>",
|
| 9 |
"Ian Leitch <port001@gentoo.org>"]
|
| 10 |
__modulename__ = "stat"
|
| 11 |
|
| 12 |
from glsr.setup import config
|
| 13 |
from glsr.core.db.mysql import SQLdb
|
| 14 |
|
| 15 |
def dbsize():
|
| 16 |
"""Returns the size of the database in bytes."""
|
| 17 |
|
| 18 |
result = SQLdb(config.db).query("SHOW TABLE STATUS", fetch = "all")
|
| 19 |
|
| 20 |
dbsize = 0
|
| 21 |
for row in result:
|
| 22 |
dbsize += row["Data_length"] + row["Index_length"]
|
| 23 |
|
| 24 |
return str(dbsize)
|
| 25 |
|
| 26 |
def count(table):
|
| 27 |
"""Returns the total number of rows in the specified table."""
|
| 28 |
|
| 29 |
result = SQLdb(config.db).query(
|
| 30 |
"SELECT count(*) FROM %s%s" % (config.db["prefix"], table),
|
| 31 |
fetch = "one")
|
| 32 |
|
| 33 |
return str(result["count(*)"])
|