From 5062f29e3c49b08eeaacb32a04372eee53b2b88d Mon Sep 17 00:00:00 2001 From: Corentin Chary Date: Wed, 14 Mar 2012 14:07:28 +0100 Subject: [PATCH] euscanwww: don't delete packages when deleting related versions Signed-off-by: Corentin Chary --- TODO | 4 ++++ euscanwww/api/handlers.py | 12 ++++++++---- euscanwww/euscan/models.py | 9 ++++++--- euscanwww/euscan/views.py | 19 +++++++++++++++++-- pym/euscan/scan.py | 1 - 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 763c90f..393dc79 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,9 @@ euscan - http://my.soft/tar-(\d+).ball - cleaner code to separate gentoo mangled version and upstream unmangled versions - try to import $PV -> $MY_PV transformations from ebuilds ? +- Add a way to how we failled to find a new version - add a HTTP cache (1day, configurable) +- add a way to enable/disable methods: other_distributions,remote_euscan,handlers, etc.... Site Handlers ------------- @@ -37,6 +39,8 @@ euscanwww - add an /about/config page that describe the current config (overlays, stuff in make.conf, euscan default settings, etc..) [0.2.0] - add a table for overlays, change euscan_versions [0.2.0] - rss scan world + post ? +- always keep in db the last upstream version (could be marked as packaged without overlay ?) +- store euscan status (and used methods ?) ### Commands [0.2.0] diff --git a/euscanwww/api/handlers.py b/euscanwww/api/handlers.py index 711d416..5e073a5 100644 --- a/euscanwww/api/handlers.py +++ b/euscanwww/api/handlers.py @@ -7,6 +7,11 @@ from django.forms.models import model_to_dict from euscan.models import Version, Package, Herd, Maintainer, EuscanResult, VersionLog from euscan.forms import WorldForm, PackagesForm +from api.emitters import EuscanXMLEmitter + +# replace default XMLEmitter with ours +from piston.emitters import Emitter +Emitter.register('xml', EuscanXMLEmitter, 'text/xml; charset=utf-8') def xint(i): try: @@ -75,7 +80,7 @@ class MaintainersHandler(AnonymousBaseHandler): maintainers = renameFields(maintainers, [('maintainers__id', 'id'), ('maintainers__name', 'name'), ('maintainers__email', 'email')]) - return maintainers + return { 'maintainers' : maintainers } # /api/1.0/herds class HerdsHandler(AnonymousBaseHandler): @@ -89,7 +94,7 @@ class HerdsHandler(AnonymousBaseHandler): n_versions=Sum('n_versions')) herds = renameFields(herds, [('herds__herd', 'herd')]) - return herds + return { 'herds' : herds } # /api/1.0/categories class CategoriesHandler(AnonymousBaseHandler): @@ -101,7 +106,7 @@ class CategoriesHandler(AnonymousBaseHandler): n_overlay=Sum('n_overlay'), n_versions=Sum('n_versions')) - return categories + return { 'categories' : categories } # /api/1.0/packages/by-maintainer/ # /api/1.0/packages/by-category/ @@ -189,4 +194,3 @@ class PackageHandler(AnonymousBaseHandler): package['log'] = model_to_dict(log, ['result', 'datetime']) return package - diff --git a/euscanwww/euscan/models.py b/euscanwww/euscan/models.py index 753ce31..cf6e1ec 100644 --- a/euscanwww/euscan/models.py +++ b/euscanwww/euscan/models.py @@ -32,11 +32,14 @@ class Package(models.Model): ' And we also pre-compute last versions ' last_version_gentoo = models.ForeignKey('Version', blank=True, null=True, - related_name="last_version_gentoo") + related_name="last_version_gentoo", + on_delete=models.SET_NULL) last_version_overlay = models.ForeignKey('Version', blank=True, null=True, - related_name="last_version_overlay") + related_name="last_version_overlay", + on_delete=models.SET_NULL) last_version_upstream = models.ForeignKey('Version', blank=True, null=True, - related_name="last_version_upstream") + related_name="last_version_upstream", + on_delete=models.SET_NULL) def __unicode__(self): return '%s/%s' % (self.category, self.name) diff --git a/euscanwww/euscan/views.py b/euscanwww/euscan/views.py index c96ce20..6c0d920 100644 --- a/euscanwww/euscan/views.py +++ b/euscanwww/euscan/views.py @@ -101,10 +101,25 @@ def overlay(request, overlay): @render_to('euscan/package.html') def package(request, category, package): + + 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) + package = get_object_or_404(Package, category=category, name=package) package.homepages = package.homepage.split(' ') - packaged = Version.objects.filter(package=package, packaged=True).order_by('version', 'revision') - upstream = Version.objects.filter(package=package, packaged=False).order_by('version', 'revision') + 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) + log = EuscanResult.objects.filter(package=package).order_by('-datetime')[:1] log = log[0] if log else None vlog = VersionLog.objects.filter(package=package).order_by('-id') diff --git a/pym/euscan/scan.py b/pym/euscan/scan.py index aae180d..fddb4fc 100644 --- a/pym/euscan/scan.py +++ b/pym/euscan/scan.py @@ -22,7 +22,6 @@ def filter_versions(cp, versions): for url, version in versions: - ''' Try to keep the most specific urls (determinted by the length) ''' if version in filtered and len(url) < len(filtered[version]): continue