This commit is contained in:
volpino 2012-07-29 10:05:20 +02:00
commit a88824309d
6 changed files with 90 additions and 28 deletions

View File

@ -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 "<upstream>"
)
@ -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']

View File

@ -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

View File

@ -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.')

View File

@ -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,

View File

@ -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}

View File

@ -0,0 +1,53 @@
"""sendmail email backend class."""
import threading
from django.conf import settings
from django.core.mail.backends.base import BaseEmailBackend
from subprocess import Popen,PIPE
class EmailBackend(BaseEmailBackend):
def __init__(self, fail_silently=False, **kwargs):
super(EmailBackend, self).__init__(fail_silently=fail_silently)
self._lock = threading.RLock()
def open(self):
return True
def close(self):
pass
def send_messages(self, email_messages):
"""
Sends one or more EmailMessage objects and returns the number of email
messages sent.
"""
if not email_messages:
return
self._lock.acquire()
try:
num_sent = 0
for message in email_messages:
sent = self._send(message)
if sent:
num_sent += 1
finally:
self._lock.release()
return num_sent
def _send(self, email_message):
"""A helper method that does the actual sending."""
if not email_message.recipients():
return False
try:
ps = Popen(["sendmail"]+list(email_message.recipients()), \
stdin=PIPE)
ps.stdin.write(email_message.message().as_string())
ps.stdin.flush()
ps.stdin.close()
return not ps.wait()
except:
if not self.fail_silently:
raise
return False
return True