euscan: stuff

(yeah, sorry ..)

Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
Corentin Chary 2012-07-28 11:39:38 +02:00
parent 6ec059bdc2
commit 6ce658fa0d
5 changed files with 37 additions and 28 deletions

View File

@ -143,15 +143,15 @@ class Version(models.Model):
unique_together = ['package', 'slot', 'revision', 'version', 'overlay'] unique_together = ['package', 'slot', 'revision', 'version', 'overlay']
def cpv(self): def cpv(self):
return '%s/%s-%s-%s' % ( return '%s/%s-%s%s' % (
self.package.category, self.package.name, self.version, 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): 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.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 "<upstream>" self.slot, self.overlay or "<upstream>"
) )
@ -219,7 +219,10 @@ class EuscanResult(models.Model):
@property @property
def messages(self): def messages(self):
try:
result = json.loads(self.result) result = json.loads(self.result)
except ValueError:
return self.result
if result and self.package.cp() in result: if result and self.package.cp() in result:
return result[self.package.cp()]['messages'] return result[self.package.cp()]['messages']

View File

@ -2,7 +2,7 @@ from django.db.transaction import commit_on_success
from django.utils import timezone from django.utils import timezone
from djeuscan.models import Package, Herd, Maintainer, Version, HerdLog, \ from djeuscan.models import Package, Herd, Maintainer, Version, HerdLog, \
MaintainerLog, CategoryLog, WorldLog, Category, Overlay MaintainerLog, CategoryLog, WorldLog
from djeuscan import charts from djeuscan import charts
from djeuscan.processing import FakeLogger from djeuscan.processing import FakeLogger
@ -48,19 +48,6 @@ def update_counters(fast=False, nolog=False, logger=None):
wlog = 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: if not nolog:
wlog = WorldLog() wlog = WorldLog()
wlog.datetime = now wlog.datetime = now

View File

@ -11,8 +11,7 @@ from django.core.management.color import color_style
from euscan.version import get_version_type from euscan.version import get_version_type
from djeuscan.processing import FakeLogger from djeuscan.processing import FakeLogger
from djeuscan.models import Package, Version, VersionLog from djeuscan.models import Package, Version, VersionLog, Category, Overlay
class ScanPortage(object): class ScanPortage(object):
def __init__(self, logger=None, no_log=False, purge_packages=False, 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: else:
scan_handler.scan(pkg) 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.') logger.info('Done.')

View File

@ -173,7 +173,7 @@ def update_portage(packages=None):
@task @task
def update_upstream(): def update_upstream():
if settings.TASKS_UPSTREAM_GROUPS >= 1: 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, scan_upstream_sub = group_chunks(scan_upstream, packages,
settings.TASKS_UPSTREAM_GROUPS, settings.TASKS_UPSTREAM_GROUPS,

View File

@ -66,9 +66,11 @@ def category(request, category):
favourited = False favourited = False
if request.user.is_authenticated(): if request.user.is_authenticated():
if Category.objects.get(name=category) in \ try:
get_profile(request.user).categories.all(): category = Category.objects.get(name=category)
favourited = True favourited = category in get_profile(request.user).categories.all()
except Category.DoesNotExist:
pass
return {'category': category, 'packages': packages, 'last_scan': last_scan, return {'category': category, 'packages': packages, 'last_scan': last_scan,
'favourited': favourited} 'favourited': favourited}
@ -162,9 +164,11 @@ def overlay(request, overlay):
favourited = False favourited = False
if request.user.is_authenticated(): if request.user.is_authenticated():
if Overlay.objects.get(name=overlay) in \ try:
get_profile(request.user).overlays.all(): overlay = Overlay.objects.get(name=overlay)
favourited = True favourited = overlay in get_profile(request.user).overlays.all()
except Overlay.DoesNotExist:
pass
return {'overlay': overlay, 'packages': packages, 'last_scan': last_scan, return {'overlay': overlay, 'packages': packages, 'last_scan': last_scan,
'favourited': favourited} 'favourited': favourited}