2011-04-14 19:28:38 +02:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from optparse import make_option
|
|
|
|
|
|
|
|
from django.db.models import Count, Sum
|
|
|
|
from django.db.transaction import commit_on_success
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
2011-05-05 18:10:47 +02:00
|
|
|
from euscanwww.euscan.models import Package, Herd, Maintainer, Version
|
|
|
|
from euscanwww.euscan.models import HerdLog, MaintainerLog, CategoryLog, WorldLog
|
2011-05-03 08:19:01 +02:00
|
|
|
from euscanwww.euscan import charts
|
|
|
|
|
2011-04-14 19:28:38 +02:00
|
|
|
class Command(BaseCommand):
|
|
|
|
_overlays = {}
|
|
|
|
help = 'Update counters'
|
|
|
|
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('--quiet',
|
|
|
|
action='store_true',
|
|
|
|
dest='quiet',
|
|
|
|
default=False,
|
|
|
|
help='Be quiet'),
|
|
|
|
)
|
|
|
|
|
|
|
|
@commit_on_success
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
|
|
|
|
categories = {}
|
|
|
|
herds = {}
|
|
|
|
maintainers = {}
|
|
|
|
|
|
|
|
# Could be done using raw SQL queries, but I don't have time for that
|
|
|
|
# right now ...
|
|
|
|
|
2011-05-05 18:10:47 +02:00
|
|
|
wlog = WorldLog()
|
|
|
|
wlog.datetime = now
|
|
|
|
|
2011-04-14 19:28:38 +02:00
|
|
|
for cat in Package.objects.values('category').distinct():
|
|
|
|
clog = CategoryLog()
|
|
|
|
clog.datetime = now
|
|
|
|
clog.category = cat['category']
|
|
|
|
categories[clog.category] = clog
|
|
|
|
|
|
|
|
for herd in Herd.objects.all():
|
|
|
|
hlog = HerdLog()
|
|
|
|
hlog.datetime = now
|
|
|
|
hlog.herd = herd
|
|
|
|
herds[herd] = hlog
|
|
|
|
|
|
|
|
for maintainer in Maintainer.objects.all():
|
|
|
|
mlog = MaintainerLog()
|
|
|
|
mlog.datetime = now
|
|
|
|
mlog.maintainer = maintainer
|
|
|
|
maintainers[maintainer] = mlog
|
|
|
|
|
|
|
|
for package in Package.objects.all():
|
|
|
|
# Should not be needed, but can't hurt
|
|
|
|
package.n_versions = Version.objects.filter(package=package).count()
|
2011-04-25 22:27:32 +02:00
|
|
|
package.n_packaged = Version.objects.filter(package=package, packaged=True, overlay='gentoo').count()
|
|
|
|
package.n_overlay = Version.objects.filter(package=package, packaged=True).exclude(overlay='gentoo').count()
|
2011-04-14 19:28:38 +02:00
|
|
|
package.save()
|
|
|
|
|
2011-05-03 08:19:01 +02:00
|
|
|
n_packages_gentoo = int(package.n_packaged == package.n_versions)
|
|
|
|
n_packages_overlay = int(package.n_overlay and package.n_packaged + package.n_overlay == package.n_versions)
|
|
|
|
n_packages_outdated = int(package.n_packaged + package.n_overlay < package.n_versions)
|
|
|
|
|
2011-04-14 19:28:38 +02:00
|
|
|
for herd in package.herds.all():
|
2011-05-03 08:19:01 +02:00
|
|
|
herds[herd].n_packages_gentoo += n_packages_gentoo
|
|
|
|
herds[herd].n_packages_overlay += n_packages_overlay
|
|
|
|
herds[herd].n_packages_outdated += n_packages_outdated
|
|
|
|
|
|
|
|
herds[herd].n_versions_gentoo += package.n_packaged
|
|
|
|
herds[herd].n_versions_overlay += package.n_overlay
|
|
|
|
herds[herd].n_versions_upstream += package.n_versions - package.n_packaged - package.n_overlay
|
2011-04-14 19:28:38 +02:00
|
|
|
|
|
|
|
for maintainer in package.maintainers.all():
|
2011-05-03 08:19:01 +02:00
|
|
|
maintainers[maintainer].n_packages_gentoo += n_packages_gentoo
|
|
|
|
maintainers[maintainer].n_packages_overlay += n_packages_overlay
|
|
|
|
maintainers[maintainer].n_packages_outdated += n_packages_outdated
|
|
|
|
|
|
|
|
maintainers[maintainer].n_versions_gentoo += package.n_packaged
|
|
|
|
maintainers[maintainer].n_versions_overlay += package.n_overlay
|
|
|
|
maintainers[maintainer].n_versions_upstream += package.n_versions - package.n_packaged - package.n_overlay
|
2011-04-14 19:28:38 +02:00
|
|
|
|
2011-05-03 08:19:01 +02:00
|
|
|
categories[package.category].n_packages_gentoo += n_packages_gentoo
|
|
|
|
categories[package.category].n_packages_overlay += n_packages_overlay
|
|
|
|
categories[package.category].n_packages_outdated += n_packages_outdated
|
|
|
|
|
|
|
|
categories[package.category].n_versions_gentoo += package.n_packaged
|
|
|
|
categories[package.category].n_versions_overlay += package.n_overlay
|
|
|
|
categories[package.category].n_versions_upstream += package.n_versions - package.n_packaged - package.n_overlay
|
|
|
|
|
2011-05-05 18:10:47 +02:00
|
|
|
wlog.n_packages_gentoo += n_packages_gentoo
|
|
|
|
wlog.n_packages_overlay += n_packages_overlay
|
|
|
|
wlog.n_packages_outdated += n_packages_outdated
|
2011-05-03 08:19:01 +02:00
|
|
|
|
2011-05-05 18:10:47 +02:00
|
|
|
wlog.n_versions_gentoo += package.n_packaged
|
|
|
|
wlog.n_versions_overlay += package.n_overlay
|
|
|
|
wlog.n_versions_upstream += package.n_versions - package.n_packaged - package.n_overlay
|
2011-04-14 19:28:38 +02:00
|
|
|
|
|
|
|
for clog in categories.values():
|
|
|
|
if not options['quiet']:
|
2011-05-03 08:19:01 +02:00
|
|
|
self.stdout.write('[c] %s\n' % clog)
|
|
|
|
charts.rrd_update('category-%s' % clog.category, now, clog)
|
2011-04-14 19:28:38 +02:00
|
|
|
clog.save()
|
|
|
|
|
|
|
|
for hlog in herds.values():
|
|
|
|
if not options['quiet']:
|
2011-05-03 08:19:01 +02:00
|
|
|
self.stdout.write('[h] %s\n' % hlog)
|
|
|
|
charts.rrd_update('herd-%d' % hlog.herd.id, now, hlog)
|
2011-04-14 19:28:38 +02:00
|
|
|
hlog.save()
|
|
|
|
|
|
|
|
for mlog in maintainers.values():
|
|
|
|
if not options['quiet']:
|
2011-05-03 08:19:01 +02:00
|
|
|
self.stdout.write('[m] %s\n' % mlog)
|
|
|
|
charts.rrd_update('maintainer-%d' % mlog.maintainer.id, now, mlog)
|
2011-04-14 19:28:38 +02:00
|
|
|
mlog.save()
|
2011-05-03 08:19:01 +02:00
|
|
|
|
2011-05-05 18:10:47 +02:00
|
|
|
wlog.save()
|
|
|
|
|
|
|
|
charts.rrd_update('world', now, wlog)
|