From 6ce658fa0d52a5ed9d4bd78123522e69e9e5cf5e Mon Sep 17 00:00:00 2001 From: Corentin Chary Date: Sat, 28 Jul 2012 11:39:38 +0200 Subject: [PATCH] euscan: stuff (yeah, sorry ..) Signed-off-by: Corentin Chary --- euscanwww/djeuscan/models.py | 13 ++++++++----- .../processing/misc/update_counters.py | 15 +-------------- .../djeuscan/processing/scan/scan_portage.py | 19 +++++++++++++++++-- euscanwww/djeuscan/tasks.py | 2 +- euscanwww/djeuscan/views.py | 16 ++++++++++------ 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/euscanwww/djeuscan/models.py b/euscanwww/djeuscan/models.py index a277ebe..40daac5 100644 --- a/euscanwww/djeuscan/models.py +++ b/euscanwww/djeuscan/models.py @@ -143,15 +143,15 @@ class Version(models.Model): unique_together = ['package', 'slot', 'revision', 'version', 'overlay'] def cpv(self): - return '%s/%s-%s-%s' % ( + return '%s/%s-%s%s' % ( self.package.category, self.package.name, self.version, - self.revision if self.revision != 'r0' else '' + self.revision if self.revision != '-r0' else '' ) def __unicode__(self): - return '%s/%s-%s-%s:%s [%s]' % ( + return '%s/%s-%s%s:%s [%s]' % ( self.package.category, self.package.name, self.version, - self.revision if self.revision != 'r0' else '', + self.revision if self.revision != '-r0' else '', self.slot, self.overlay or "" ) @@ -219,7 +219,10 @@ class EuscanResult(models.Model): @property def messages(self): - result = json.loads(self.result) + try: + result = json.loads(self.result) + except ValueError: + return self.result if result and self.package.cp() in result: return result[self.package.cp()]['messages'] diff --git a/euscanwww/djeuscan/processing/misc/update_counters.py b/euscanwww/djeuscan/processing/misc/update_counters.py index 02d9b4b..fdbea9c 100644 --- a/euscanwww/djeuscan/processing/misc/update_counters.py +++ b/euscanwww/djeuscan/processing/misc/update_counters.py @@ -2,7 +2,7 @@ from django.db.transaction import commit_on_success from django.utils import timezone from djeuscan.models import Package, Herd, Maintainer, Version, HerdLog, \ - MaintainerLog, CategoryLog, WorldLog, Category, Overlay + MaintainerLog, CategoryLog, WorldLog from djeuscan import charts from djeuscan.processing import FakeLogger @@ -48,19 +48,6 @@ def update_counters(fast=False, nolog=False, logger=None): wlog = None - # Populate Category and Overlay - for cat in Package.objects.values('category').distinct(): - obj, created = Category.objects.get_or_create(name=cat["category"]) - if created: - logger.info("+ [c] %s", cat["category"]) - - for overlay in Version.objects.values('overlay').distinct(): - if not overlay["overlay"]: - continue - obj, created = Overlay.objects.get_or_create(name=overlay["overlay"]) - if created: - logger.info("+ [o] %s", overlay["overlay"]) - if not nolog: wlog = WorldLog() wlog.datetime = now diff --git a/euscanwww/djeuscan/processing/scan/scan_portage.py b/euscanwww/djeuscan/processing/scan/scan_portage.py index f4ca15d..25ca211 100644 --- a/euscanwww/djeuscan/processing/scan/scan_portage.py +++ b/euscanwww/djeuscan/processing/scan/scan_portage.py @@ -11,8 +11,7 @@ from django.core.management.color import color_style from euscan.version import get_version_type from djeuscan.processing import FakeLogger -from djeuscan.models import Package, Version, VersionLog - +from djeuscan.models import Package, Version, VersionLog, Category, Overlay class ScanPortage(object): def __init__(self, logger=None, no_log=False, purge_packages=False, @@ -359,4 +358,20 @@ def scan_portage(packages=None, category=None, no_log=False, else: scan_handler.scan(pkg) + # Populate Category and Overlay + # TODO: - use portage.settings.categories() + # - read metadata.xml to add description + for cat in Package.objects.values('category').distinct(): + obj, created = Category.objects.get_or_create(name=cat["category"]) + if created: + logger.info("+ [c] %s", cat["category"]) + + # TODO: - get informations from layman and portage (path, url) + for overlay in Version.objects.values('overlay').distinct(): + if not overlay["overlay"]: + continue + obj, created = Overlay.objects.get_or_create(name=overlay["overlay"]) + if created: + logger.info("+ [o] %s", overlay["overlay"]) + logger.info('Done.') diff --git a/euscanwww/djeuscan/tasks.py b/euscanwww/djeuscan/tasks.py index d0341fe..e3898cc 100644 --- a/euscanwww/djeuscan/tasks.py +++ b/euscanwww/djeuscan/tasks.py @@ -173,7 +173,7 @@ def update_portage(packages=None): @task def update_upstream(): if settings.TASKS_UPSTREAM_GROUPS >= 1: - packages = Package.objects.all().order_by("pk") + packages = Package.objects.all().order_by('pk') # .order_by('?') ? scan_upstream_sub = group_chunks(scan_upstream, packages, settings.TASKS_UPSTREAM_GROUPS, diff --git a/euscanwww/djeuscan/views.py b/euscanwww/djeuscan/views.py index 3a13b8e..6eded23 100644 --- a/euscanwww/djeuscan/views.py +++ b/euscanwww/djeuscan/views.py @@ -66,9 +66,11 @@ def category(request, category): favourited = False if request.user.is_authenticated(): - if Category.objects.get(name=category) in \ - get_profile(request.user).categories.all(): - favourited = True + try: + category = Category.objects.get(name=category) + favourited = category in get_profile(request.user).categories.all() + except Category.DoesNotExist: + pass return {'category': category, 'packages': packages, 'last_scan': last_scan, 'favourited': favourited} @@ -162,9 +164,11 @@ def overlay(request, overlay): favourited = False if request.user.is_authenticated(): - if Overlay.objects.get(name=overlay) in \ - get_profile(request.user).overlays.all(): - favourited = True + try: + overlay = Overlay.objects.get(name=overlay) + favourited = overlay in get_profile(request.user).overlays.all() + except Overlay.DoesNotExist: + pass return {'overlay': overlay, 'packages': packages, 'last_scan': last_scan, 'favourited': favourited}