2011-04-13 08:50:24 +02:00
|
|
|
from annoying.decorators import render_to
|
2012-04-28 18:16:05 +02:00
|
|
|
from django.http import Http404
|
2011-04-15 00:24:45 +02:00
|
|
|
from django.shortcuts import get_object_or_404
|
2011-04-14 19:28:38 +02:00
|
|
|
from django.db.models import Sum, Max
|
|
|
|
|
2012-04-04 14:33:40 +02:00
|
|
|
from models import Version, Package, Herd, Maintainer, EuscanResult, VersionLog
|
|
|
|
from forms import WorldForm, PackagesForm
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
import charts
|
|
|
|
|
|
|
|
""" Views """
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
@render_to('euscan/index.html')
|
|
|
|
def index(request):
|
2011-04-14 19:28:38 +02:00
|
|
|
ctx = {}
|
2012-04-28 18:16:05 +02:00
|
|
|
ctx['n_packaged'] = charts.xint(
|
|
|
|
Package.objects.aggregate(Sum('n_packaged'))['n_packaged__sum']
|
|
|
|
)
|
|
|
|
ctx['n_overlay'] = charts.xint(
|
|
|
|
Package.objects.aggregate(Sum('n_overlay'))['n_overlay__sum']
|
|
|
|
)
|
|
|
|
ctx['n_versions'] = charts.xint(
|
|
|
|
Package.objects.aggregate(Sum('n_versions'))['n_versions__sum']
|
|
|
|
)
|
|
|
|
ctx['n_upstream'] = ctx['n_versions'] - ctx['n_packaged'] - \
|
|
|
|
ctx['n_overlay']
|
2011-04-14 19:28:38 +02:00
|
|
|
ctx['n_packages'] = Package.objects.count()
|
|
|
|
ctx['n_herds'] = Herd.objects.count()
|
|
|
|
ctx['n_maintainers'] = Maintainer.objects.count()
|
2012-03-05 14:46:34 +01:00
|
|
|
|
|
|
|
try:
|
2012-04-28 18:16:05 +02:00
|
|
|
ctx['last_scan'] = EuscanResult.objects.get(
|
|
|
|
id=EuscanResult.objects.aggregate(Max('id'))['id__max']
|
|
|
|
).datetime
|
2012-03-05 14:46:34 +01:00
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
ctx['last_scan'] = None
|
|
|
|
|
2011-04-14 19:28:38 +02:00
|
|
|
return ctx
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
@render_to('euscan/logs.html')
|
|
|
|
def logs(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
@render_to('euscan/categories.html')
|
|
|
|
def categories(request):
|
2012-04-28 18:16:05 +02:00
|
|
|
categories = Package.objects.values('category').annotate(
|
|
|
|
n_packaged=Sum('n_packaged'),
|
|
|
|
n_overlay=Sum('n_overlay'),
|
|
|
|
n_versions=Sum('n_versions')
|
|
|
|
)
|
|
|
|
|
|
|
|
return {'categories': categories}
|
2011-04-25 22:27:32 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/category.html')
|
|
|
|
def category(request, category):
|
2012-03-05 14:46:34 +01:00
|
|
|
packages = Package.objects.filter(category=category)
|
2012-04-28 18:16:05 +02:00
|
|
|
packages = packages.select_related(
|
|
|
|
'last_version_gentoo', 'last_version_overlay', 'last_version_upstream'
|
|
|
|
)
|
2012-03-02 18:01:46 +01:00
|
|
|
print dir(packages[0])
|
2011-04-15 00:24:45 +02:00
|
|
|
if not packages:
|
|
|
|
raise Http404
|
2012-04-28 18:16:05 +02:00
|
|
|
return {'category': category, 'packages': packages}
|
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/herds.html')
|
|
|
|
def herds(request):
|
2012-04-28 18:16:05 +02:00
|
|
|
# FIXME: optimize the query, it uses 'LEFT OUTER JOIN' instead of
|
|
|
|
# 'INNER JOIN'
|
2011-04-25 22:27:32 +02:00
|
|
|
herds = Package.objects.filter(herds__isnull=False)
|
2012-04-28 18:16:05 +02:00
|
|
|
herds = herds.values('herds__herd').annotate(
|
|
|
|
n_packaged=Sum('n_packaged'),
|
|
|
|
n_overlay=Sum('n_overlay'),
|
|
|
|
n_versions=Sum('n_versions'))
|
|
|
|
return {'herds': herds}
|
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/herd.html')
|
|
|
|
def herd(request, herd):
|
2011-04-15 19:28:37 +02:00
|
|
|
herd = get_object_or_404(Herd, herd=herd)
|
|
|
|
packages = Package.objects.filter(herds__id=herd.id)
|
2012-04-28 18:16:05 +02:00
|
|
|
packages = packages.select_related(
|
|
|
|
'last_version_gentoo', 'last_version_overlay', 'last_version_upstream'
|
|
|
|
)
|
|
|
|
return {'herd': herd, 'packages': packages}
|
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/maintainers.html')
|
|
|
|
def maintainers(request):
|
2011-04-25 22:27:32 +02:00
|
|
|
maintainers = Package.objects.filter(maintainers__isnull=False)
|
2012-04-28 18:16:05 +02:00
|
|
|
maintainers = maintainers.values(
|
|
|
|
'maintainers__id', 'maintainers__name', 'maintainers__email'
|
|
|
|
)
|
|
|
|
maintainers = maintainers.annotate(
|
|
|
|
n_packaged=Sum('n_packaged'),
|
|
|
|
n_overlay=Sum('n_overlay'),
|
|
|
|
n_versions=Sum('n_versions')
|
|
|
|
)
|
|
|
|
|
|
|
|
return {'maintainers': maintainers}
|
2011-04-25 22:27:32 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/maintainer.html')
|
|
|
|
def maintainer(request, maintainer_id):
|
2011-04-15 19:28:37 +02:00
|
|
|
maintainer = get_object_or_404(Maintainer, id=maintainer_id)
|
|
|
|
packages = Package.objects.filter(maintainers__id=maintainer.id)
|
2012-04-28 18:16:05 +02:00
|
|
|
packages = packages.select_related(
|
|
|
|
'last_version_gentoo', 'last_version_overlay', 'last_version_upstream'
|
|
|
|
)
|
|
|
|
return {'maintainer': maintainer, 'packages': packages}
|
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-23 18:03:07 +01:00
|
|
|
@render_to('euscan/overlays.html')
|
|
|
|
def overlays(request):
|
|
|
|
overlays = Package.objects.values('version__overlay')
|
|
|
|
overlays = overlays.exclude(version__overlay='')
|
|
|
|
overlays = overlays.distinct()
|
2012-04-28 18:16:05 +02:00
|
|
|
return {'overlays': overlays}
|
|
|
|
|
2011-11-23 18:03:07 +01:00
|
|
|
|
|
|
|
@render_to('euscan/overlay.html')
|
|
|
|
def overlay(request, overlay):
|
|
|
|
packages = Package.objects.values('id', 'name', 'category',
|
|
|
|
'n_versions', 'n_packaged',
|
|
|
|
'n_overlay')
|
|
|
|
packages = packages.filter(version__overlay=overlay).distinct()
|
|
|
|
if not packages:
|
|
|
|
raise Http404
|
2012-04-28 18:16:05 +02:00
|
|
|
return {'overlay': overlay, 'packages': packages}
|
|
|
|
|
2011-11-23 18:03:07 +01:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/package.html')
|
|
|
|
def package(request, category, package):
|
2012-03-14 14:07:28 +01:00
|
|
|
|
|
|
|
def version_key(version):
|
|
|
|
from distutils.version import StrictVersion, LooseVersion
|
|
|
|
|
|
|
|
version = version.version
|
|
|
|
try:
|
|
|
|
return StrictVersion(version)
|
|
|
|
# in case of abnormal version number, fall back to LooseVersion
|
|
|
|
except ValueError:
|
|
|
|
return LooseVersion(version)
|
|
|
|
|
2011-04-15 00:24:45 +02:00
|
|
|
package = get_object_or_404(Package, category=category, name=package)
|
2011-04-25 22:27:32 +02:00
|
|
|
package.homepages = package.homepage.split(' ')
|
2012-03-14 14:07:28 +01:00
|
|
|
packaged = Version.objects.filter(package=package, packaged=True)
|
|
|
|
upstream = Version.objects.filter(package=package, packaged=False)
|
|
|
|
|
|
|
|
packaged = sorted(packaged, key=version_key)
|
|
|
|
upstream = sorted(upstream, key=version_key)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
log = EuscanResult.objects.filter(package=package).\
|
|
|
|
order_by('-datetime')[:1]
|
2011-04-18 21:49:27 +02:00
|
|
|
log = log[0] if log else None
|
2011-08-25 15:39:54 +02:00
|
|
|
vlog = VersionLog.objects.filter(package=package).order_by('-id')
|
2012-04-28 18:16:05 +02:00
|
|
|
|
|
|
|
return {'package': package, 'packaged': packaged,
|
|
|
|
'upstream': upstream, 'log': log, 'vlog': vlog}
|
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
@render_to('euscan/world.html')
|
|
|
|
def world(request):
|
2011-04-16 11:44:57 +02:00
|
|
|
world_form = WorldForm()
|
|
|
|
packages_form = PackagesForm()
|
2011-04-15 19:28:37 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
return {'world_form': world_form,
|
|
|
|
'packages_form': packages_form}
|
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
@render_to('euscan/world_scan.html')
|
|
|
|
def world_scan(request):
|
|
|
|
packages = []
|
|
|
|
|
2011-04-16 11:44:57 +02:00
|
|
|
if 'world' in request.FILES:
|
|
|
|
data = request.FILES['world'].read()
|
|
|
|
elif 'packages' in request.POST:
|
|
|
|
data = request.POST['packages']
|
2011-04-15 19:28:37 +02:00
|
|
|
else:
|
|
|
|
data = ""
|
|
|
|
|
2011-04-18 21:49:27 +02:00
|
|
|
data = data.replace("\r", "")
|
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
for pkg in data.split('\n'):
|
|
|
|
try:
|
2011-04-18 21:49:27 +02:00
|
|
|
if '/' in pkg:
|
|
|
|
cat, pkg = pkg.split('/')
|
|
|
|
packages.extend(Package.objects.filter(category=cat, name=pkg))
|
|
|
|
else:
|
|
|
|
packages.extend(Package.objects.filter(name=pkg))
|
2011-04-15 19:28:37 +02:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
return {'packages': packages}
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
@render_to("euscan/about.html")
|
|
|
|
def about(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-11-17 14:37:59 +01:00
|
|
|
@render_to("euscan/api.html")
|
|
|
|
def api(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
@render_to("euscan/statistics.html")
|
|
|
|
def statistics(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart(request, **kwargs):
|
|
|
|
from django.views.static import serve
|
|
|
|
|
|
|
|
chart = kwargs['chart'] if 'chart' in kwargs else None
|
|
|
|
|
|
|
|
if 'maintainer_id' in kwargs:
|
2012-04-28 18:16:05 +02:00
|
|
|
kwargs['maintainer'] = get_object_or_404(
|
|
|
|
Maintainer,
|
|
|
|
id=kwargs['maintainer_id']
|
|
|
|
)
|
2011-04-25 22:27:32 +02:00
|
|
|
if 'herd' in kwargs:
|
|
|
|
kwargs['herd'] = get_object_or_404(Herd, herd=kwargs['herd'])
|
|
|
|
|
2011-05-03 08:19:01 +02:00
|
|
|
for kw in ('-small', '-weekly', '-monthly', '-yearly'):
|
|
|
|
if chart.endswith(kw):
|
|
|
|
if kw in ('-weekly', '-monthly', '-yearly'):
|
|
|
|
kwargs['period'] = kw
|
|
|
|
kwargs[kw] = True
|
|
|
|
chart = chart[:-len(kw)]
|
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
if chart == 'pie-packages':
|
|
|
|
path = charts.pie_packages(**kwargs)
|
|
|
|
elif chart == 'pie-versions':
|
|
|
|
path = charts.pie_versions(**kwargs)
|
2011-05-03 08:19:01 +02:00
|
|
|
elif chart == 'packages':
|
|
|
|
path = charts.packages(**kwargs)
|
|
|
|
elif chart == 'versions':
|
|
|
|
path = charts.versions(**kwargs)
|
2011-04-25 22:27:32 +02:00
|
|
|
else:
|
|
|
|
raise Http404()
|
|
|
|
|
|
|
|
return serve(request, path, document_root=charts.CHARTS_ROOT)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart_maintainer(request, **kwargs):
|
|
|
|
return chart(request, **kwargs)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart_herd(request, **kwargs):
|
|
|
|
return chart(request, **kwargs)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart_category(request, **kwargs):
|
|
|
|
return chart(request, **kwargs)
|