From 5970b4df3727e90053dfb9470570010e756ca069 Mon Sep 17 00:00:00 2001 From: volpino Date: Sun, 3 Jun 2012 09:43:49 +0200 Subject: [PATCH] euscanwww: Admin improved and simple task launcher added Signed-off-by: volpino --- .../management/commands/scan_metadata.py | 2 +- .../management/commands/scan_portage.py | 8 +- euscanwww/djeuscan/models.py | 5 ++ euscanwww/djeuscan/tasks.py | 16 +++- .../admin/djcelery/taskstate/change_list.html | 77 +++++++++++++++++++ euscanwww/djeuscan/urls.py | 17 ++++ euscanwww/djeuscan/views.py | 22 +++++- euscanwww/euscanwww/settings.py | 5 +- 8 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 euscanwww/djeuscan/templates/admin/djcelery/taskstate/change_list.html diff --git a/euscanwww/djeuscan/management/commands/scan_metadata.py b/euscanwww/djeuscan/management/commands/scan_metadata.py index d9c7e49..c3f4c4b 100644 --- a/euscanwww/djeuscan/management/commands/scan_metadata.py +++ b/euscanwww/djeuscan/management/commands/scan_metadata.py @@ -13,7 +13,7 @@ from djeuscan.models import Package, Herd, Maintainer class ScanMetadata(object): - def __init__(self, quiet): + def __init__(self, quiet=False): self.quiet = quiet self.style = color_style() diff --git a/euscanwww/djeuscan/management/commands/scan_portage.py b/euscanwww/djeuscan/management/commands/scan_portage.py index 9533730..4471fac 100644 --- a/euscanwww/djeuscan/management/commands/scan_portage.py +++ b/euscanwww/djeuscan/management/commands/scan_portage.py @@ -241,7 +241,7 @@ class ScanPortage(object): @commit_on_success -def purge_versions(options): +def purge_versions(quiet=False, nolog=False): # For each dead versions for version in Version.objects.filter(packaged=True, alive=False): if version.overlay == 'gentoo': @@ -251,10 +251,10 @@ def purge_versions(options): version.package.n_versions -= 1 version.package.save() - if not options['quiet']: + if not quiet: sys.stdout.write('- [v] %s\n' % (version)) - if options['no-log']: + if nolog: continue VersionLog.objects.create( @@ -335,7 +335,7 @@ class Command(BaseCommand): scan_portage.scan(package[:-1]) if options['purge-versions']: - purge_versions(options) + purge_versions(options["quiet"], options["no-log"]) if not options['quiet']: self.stdout.write('Done.\n') diff --git a/euscanwww/djeuscan/models.py b/euscanwww/djeuscan/models.py index 727deef..fee8dc4 100644 --- a/euscanwww/djeuscan/models.py +++ b/euscanwww/djeuscan/models.py @@ -190,6 +190,11 @@ class EuscanResult(models.Model): self.full_clean() super(EuscanResult, self).save(*args, **kwargs) + def __unicode__(self): + return '[%s] %s/%s' % ( + self.datetime, self.package.category, self.package.name + ) + class Log(models.Model): """ diff --git a/euscanwww/djeuscan/tasks.py b/euscanwww/djeuscan/tasks.py index e614a70..89a90dc 100644 --- a/euscanwww/djeuscan/tasks.py +++ b/euscanwww/djeuscan/tasks.py @@ -28,7 +28,7 @@ def scan_metadata_task(query, obj=None): logger.info("Starting metadata scanning for package %s ...", query) scan_metadata = ScanMetadata() - scan_metadata.scan(query) + scan_metadata.scan(query, obj) @task @@ -95,3 +95,17 @@ def scan_upstream_task(query): @task def scan_upstream_purge_task(): scan_upstream_purge() + + +launchable_tasks = [ + regen_rrds_task, + update_counters_task, + scan_metadata_task, + scan_metadata_all_task, + scan_portage_all_task, + scan_portage_task, + scan_portage_purge_task, + scan_upstream_all_task, + scan_upstream_task, + scan_upstream_purge_task, +] diff --git a/euscanwww/djeuscan/templates/admin/djcelery/taskstate/change_list.html b/euscanwww/djeuscan/templates/admin/djcelery/taskstate/change_list.html new file mode 100644 index 0000000..693214a --- /dev/null +++ b/euscanwww/djeuscan/templates/admin/djcelery/taskstate/change_list.html @@ -0,0 +1,77 @@ +{% extends "admin/change_list.html" %} + +{% load url from future %} + +{% block object-tools %} +
+ +
+ Launch task +
+ + +{% endblock %} diff --git a/euscanwww/djeuscan/urls.py b/euscanwww/djeuscan/urls.py index 019f99a..721fad5 100644 --- a/euscanwww/djeuscan/urls.py +++ b/euscanwww/djeuscan/urls.py @@ -1,7 +1,16 @@ from django.conf.urls.defaults import url, patterns, include +from django.contrib.auth.decorators import user_passes_test + +from djcelery.views import apply +from djeuscan.views import registered_tasks + from djeuscan.feeds import PackageFeed, CategoryFeed, HerdFeed, \ MaintainerFeed, GlobalFeed + +admin_required = user_passes_test(lambda u: u.is_superuser) + + package_patterns = patterns('djeuscan.views', url(r'^(?P[\w+][\w+.-]*)/(?P[\w+][\w+.-]*)/feed/$', PackageFeed(), name='package_feed'), @@ -41,6 +50,13 @@ overlays_patterns = patterns('djeuscan.views', url(r'^$', 'overlays', name="overlays"), ) +tasks_patterns = patterns('djcelery.views', + url(r'^registered_tasks/$', admin_required(registered_tasks), + name="registered_tasks"), + url(r'^apply/(?P.*)/$', admin_required(apply), + name="apply_task"), +) + urlpatterns = patterns('djeuscan.views', # Global stuff url(r'^api/', include('djeuscan.api.urls')), @@ -60,4 +76,5 @@ urlpatterns = patterns('djeuscan.views', url(r'^maintainers/', include(maintainers_patterns)), url(r'^overlays/', include(overlays_patterns)), url(r'^package/', include(package_patterns)), + url(r'^tasks/', include(tasks_patterns)), ) diff --git a/euscanwww/djeuscan/views.py b/euscanwww/djeuscan/views.py index 68836af..d84c39d 100644 --- a/euscanwww/djeuscan/views.py +++ b/euscanwww/djeuscan/views.py @@ -1,6 +1,8 @@ """ Views """ -from annoying.decorators import render_to +import inspect +from annoying.decorators import render_to, ajax_request + from django.http import Http404 from django.shortcuts import get_object_or_404 @@ -8,6 +10,7 @@ from djeuscan.helpers import version_key, packages_from_names from djeuscan.models import Version, Package, Herd, Maintainer, EuscanResult, \ VersionLog from djeuscan.forms import WorldForm, PackagesForm +from djeuscan.tasks import launchable_tasks from djeuscan import charts @@ -254,3 +257,20 @@ def chart_herd(request, **kwargs): def chart_category(request, **kwargs): return chart(request, **kwargs) + + +@ajax_request +def registered_tasks(request): + data = {} + for task in launchable_tasks: + argspec = inspect.getargspec(task.run) + data[task.name] = { + "args": argspec.args, + "defaults": argspec.defaults, + "default_types": None + } + if argspec.defaults is not None: + data[task.name].update({ + "defaults_types": [type(x).__name__ for x in argspec.defaults] + }) + return {"tasks": data} diff --git a/euscanwww/euscanwww/settings.py b/euscanwww/euscanwww/settings.py index 0f2b483..d84e340 100644 --- a/euscanwww/euscanwww/settings.py +++ b/euscanwww/euscanwww/settings.py @@ -157,6 +157,9 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ) INSTALLED_APPS = ( + 'euscanwww', + 'djeuscan', + 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', @@ -167,8 +170,6 @@ INSTALLED_APPS = ( # 'django.contrib.admindocs', 'south', 'djcelery', - 'euscanwww', - 'djeuscan', ) # A sample logging configuration. The only tangible logging