aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Bacherikov <slava@bacher09.org>2012-08-21 01:36:54 +0300
committerSlava Bacherikov <slava@bacher09.org>2012-08-21 01:36:54 +0300
commitd1862988afce875c02d691f0a6c8b2b010b8765c (patch)
treedb563bc8ec71648a30a88fafb2fb8b2354a1a02a
parentAdd herds_count field to RepositoryModel (diff)
downloadgentoo-packages-d1862988afce875c02d691f0a6c8b2b010b8765c.tar.gz
gentoo-packages-d1862988afce875c02d691f0a6c8b2b010b8765c.tar.bz2
gentoo-packages-d1862988afce875c02d691f0a6c8b2b010b8765c.zip
Update simplestats command, allow using precalculated values in it
-rw-r--r--gpackages/apps/packages/management/commands/simplestats.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/gpackages/apps/packages/management/commands/simplestats.py b/gpackages/apps/packages/management/commands/simplestats.py
index 2e07372..b312d45 100644
--- a/gpackages/apps/packages/management/commands/simplestats.py
+++ b/gpackages/apps/packages/management/commands/simplestats.py
@@ -3,25 +3,43 @@ from optparse import make_option
from packages import models
from django.db.models import Count
+def get_query(precalculated = False):
+ if precalculated == True:
+ return models.RepositoryModel.objects. \
+ values_list('name', 'packages_count', 'ebuilds_count',
+ 'maintainers_count', 'herds_count')
+
+ return models.RepositoryModel.objects.annotate(
+ packages_countr = Count('packagemodel', distinct = True),
+ ebuilds_countr = Count('packagemodel__ebuildmodel', distinct = True),
+ maintainers_countr = Count('packagemodel__maintainers', distinct = True),
+ herds_countr = Count('packagemodel__herds', distinct = True)). \
+ values_list('name', 'packages_countr', 'ebuilds_countr',
+ 'maintainers_countr', 'herds_countr')
class Command(BaseCommand):
+ option_list = BaseCommand.option_list + (
+ make_option('-p', '--precalculated',
+ action='store_true',
+ dest='precalculated',
+ default=False,
+ help='Use precalculated stats'),
+ )
args = ''
help = 'Will show some stats for repos'
+
def handle(self, *args, **options):
- query = models.RepositoryModel.objects.annotate(
- packages_countr = Count('packagemodel', distinct = True),
- ebuilds_countr = Count('packagemodel__ebuildmodel', distinct = True),
- maintainers_countr = Count('packagemodel__maintainers', distinct = True),
- herds_countr = Count('packagemodel__herds', distinct = True))
+ precalculated = options.get('precalculated', False)
+ query = get_query(precalculated)
self.stdout.write('"%s" "%s" "%s" "%s" "%s"\n' %
('Repo name', 'Packages', 'Ebuilds' , 'Maintainers', 'Herds'))
for repo_object in query:
self.stdout.write("%-25s %+9s %+9s %+9s %+9s\n" % (
- repo_object.name,
- repo_object.packages_countr,
- repo_object.ebuilds_countr,
- repo_object.maintainers_countr,
- repo_object.herds_countr))
+ repo_object[0],
+ repo_object[1],
+ repo_object[2],
+ repo_object[3],
+ repo_object[4]))