euscanwww: Admin improved and simple task launcher added
Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
47ec539e1d
commit
5970b4df37
@ -13,7 +13,7 @@ from djeuscan.models import Package, Herd, Maintainer
|
|||||||
|
|
||||||
|
|
||||||
class ScanMetadata(object):
|
class ScanMetadata(object):
|
||||||
def __init__(self, quiet):
|
def __init__(self, quiet=False):
|
||||||
self.quiet = quiet
|
self.quiet = quiet
|
||||||
self.style = color_style()
|
self.style = color_style()
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ class ScanPortage(object):
|
|||||||
|
|
||||||
|
|
||||||
@commit_on_success
|
@commit_on_success
|
||||||
def purge_versions(options):
|
def purge_versions(quiet=False, nolog=False):
|
||||||
# For each dead versions
|
# For each dead versions
|
||||||
for version in Version.objects.filter(packaged=True, alive=False):
|
for version in Version.objects.filter(packaged=True, alive=False):
|
||||||
if version.overlay == 'gentoo':
|
if version.overlay == 'gentoo':
|
||||||
@ -251,10 +251,10 @@ def purge_versions(options):
|
|||||||
version.package.n_versions -= 1
|
version.package.n_versions -= 1
|
||||||
version.package.save()
|
version.package.save()
|
||||||
|
|
||||||
if not options['quiet']:
|
if not quiet:
|
||||||
sys.stdout.write('- [v] %s\n' % (version))
|
sys.stdout.write('- [v] %s\n' % (version))
|
||||||
|
|
||||||
if options['no-log']:
|
if nolog:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
VersionLog.objects.create(
|
VersionLog.objects.create(
|
||||||
@ -335,7 +335,7 @@ class Command(BaseCommand):
|
|||||||
scan_portage.scan(package[:-1])
|
scan_portage.scan(package[:-1])
|
||||||
|
|
||||||
if options['purge-versions']:
|
if options['purge-versions']:
|
||||||
purge_versions(options)
|
purge_versions(options["quiet"], options["no-log"])
|
||||||
|
|
||||||
if not options['quiet']:
|
if not options['quiet']:
|
||||||
self.stdout.write('Done.\n')
|
self.stdout.write('Done.\n')
|
||||||
|
@ -190,6 +190,11 @@ class EuscanResult(models.Model):
|
|||||||
self.full_clean()
|
self.full_clean()
|
||||||
super(EuscanResult, self).save(*args, **kwargs)
|
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):
|
class Log(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -28,7 +28,7 @@ def scan_metadata_task(query, obj=None):
|
|||||||
logger.info("Starting metadata scanning for package %s ...", query)
|
logger.info("Starting metadata scanning for package %s ...", query)
|
||||||
|
|
||||||
scan_metadata = ScanMetadata()
|
scan_metadata = ScanMetadata()
|
||||||
scan_metadata.scan(query)
|
scan_metadata.scan(query, obj)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
@ -95,3 +95,17 @@ def scan_upstream_task(query):
|
|||||||
@task
|
@task
|
||||||
def scan_upstream_purge_task():
|
def scan_upstream_purge_task():
|
||||||
scan_upstream_purge()
|
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,
|
||||||
|
]
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
{% extends "admin/change_list.html" %}
|
||||||
|
|
||||||
|
{% load url from future %}
|
||||||
|
|
||||||
|
{% block object-tools %}
|
||||||
|
<div>
|
||||||
|
<span id="task_selector"></span>
|
||||||
|
<form id="task_data"></form>
|
||||||
|
<a href="#" id="task_launch">Launch task</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function($){
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
$.get("{% url "registered_tasks" %}", function (data) {
|
||||||
|
var selector = $("<select/>");
|
||||||
|
selector.append(
|
||||||
|
$("<option/>").text("-------------").attr("selected", "selected")
|
||||||
|
);
|
||||||
|
for (task in data["tasks"]) {
|
||||||
|
var t = data["tasks"][task];
|
||||||
|
selector.append(
|
||||||
|
$("<option/>").val(task).text(task)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
selector.change(function() {
|
||||||
|
$("#task_data").empty();
|
||||||
|
var task = data["tasks"][$(this).val()];
|
||||||
|
if (task.args) {
|
||||||
|
for (var i = 0; i < task.args.length; i++) {
|
||||||
|
var arg = task.args[i];
|
||||||
|
var arg_input = $("<input/>").attr("name", arg);
|
||||||
|
var default_arg;
|
||||||
|
|
||||||
|
if (task.defaults) {
|
||||||
|
var default_arg_i = task.args.length - 1 - i;
|
||||||
|
if (task.defaults[default_arg_i] !== undefined) {
|
||||||
|
default_arg = task.defaults[default_arg_i];
|
||||||
|
if (task.defaults_types && task.defaults_types[default_arg_i] === "bool") {
|
||||||
|
arg_input.attr("type", "checkbox");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arg_input.val(default_arg);
|
||||||
|
|
||||||
|
$("#task_data").append(
|
||||||
|
$("<label/>").text(arg + ": ").attr("for", arg)
|
||||||
|
).append(
|
||||||
|
arg_input
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$("#task_selector").append(selector);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#task_launch").click(function() {
|
||||||
|
var task_name = $("#task_selector").find("select").val();
|
||||||
|
var data = $("#task_data").serialize();
|
||||||
|
var url = "{% url "apply_task" "task_name" %}";
|
||||||
|
|
||||||
|
$.post(url.replace("task_name", task_name), data, function() {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
})(django.jQuery);
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
@ -1,7 +1,16 @@
|
|||||||
from django.conf.urls.defaults import url, patterns, include
|
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, \
|
from djeuscan.feeds import PackageFeed, CategoryFeed, HerdFeed, \
|
||||||
MaintainerFeed, GlobalFeed
|
MaintainerFeed, GlobalFeed
|
||||||
|
|
||||||
|
|
||||||
|
admin_required = user_passes_test(lambda u: u.is_superuser)
|
||||||
|
|
||||||
|
|
||||||
package_patterns = patterns('djeuscan.views',
|
package_patterns = patterns('djeuscan.views',
|
||||||
url(r'^(?P<category>[\w+][\w+.-]*)/(?P<package>[\w+][\w+.-]*)/feed/$',
|
url(r'^(?P<category>[\w+][\w+.-]*)/(?P<package>[\w+][\w+.-]*)/feed/$',
|
||||||
PackageFeed(), name='package_feed'),
|
PackageFeed(), name='package_feed'),
|
||||||
@ -41,6 +50,13 @@ overlays_patterns = patterns('djeuscan.views',
|
|||||||
url(r'^$', 'overlays', name="overlays"),
|
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<task_name>.*)/$', admin_required(apply),
|
||||||
|
name="apply_task"),
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = patterns('djeuscan.views',
|
urlpatterns = patterns('djeuscan.views',
|
||||||
# Global stuff
|
# Global stuff
|
||||||
url(r'^api/', include('djeuscan.api.urls')),
|
url(r'^api/', include('djeuscan.api.urls')),
|
||||||
@ -60,4 +76,5 @@ urlpatterns = patterns('djeuscan.views',
|
|||||||
url(r'^maintainers/', include(maintainers_patterns)),
|
url(r'^maintainers/', include(maintainers_patterns)),
|
||||||
url(r'^overlays/', include(overlays_patterns)),
|
url(r'^overlays/', include(overlays_patterns)),
|
||||||
url(r'^package/', include(package_patterns)),
|
url(r'^package/', include(package_patterns)),
|
||||||
|
url(r'^tasks/', include(tasks_patterns)),
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
""" Views """
|
""" Views """
|
||||||
|
|
||||||
from annoying.decorators import render_to
|
import inspect
|
||||||
|
from annoying.decorators import render_to, ajax_request
|
||||||
|
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.shortcuts import get_object_or_404
|
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, \
|
from djeuscan.models import Version, Package, Herd, Maintainer, EuscanResult, \
|
||||||
VersionLog
|
VersionLog
|
||||||
from djeuscan.forms import WorldForm, PackagesForm
|
from djeuscan.forms import WorldForm, PackagesForm
|
||||||
|
from djeuscan.tasks import launchable_tasks
|
||||||
from djeuscan import charts
|
from djeuscan import charts
|
||||||
|
|
||||||
|
|
||||||
@ -254,3 +257,20 @@ def chart_herd(request, **kwargs):
|
|||||||
|
|
||||||
def chart_category(request, **kwargs):
|
def chart_category(request, **kwargs):
|
||||||
return chart(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}
|
||||||
|
@ -157,6 +157,9 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
|
'euscanwww',
|
||||||
|
'djeuscan',
|
||||||
|
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
@ -167,8 +170,6 @@ INSTALLED_APPS = (
|
|||||||
# 'django.contrib.admindocs',
|
# 'django.contrib.admindocs',
|
||||||
'south',
|
'south',
|
||||||
'djcelery',
|
'djcelery',
|
||||||
'euscanwww',
|
|
||||||
'djeuscan',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# A sample logging configuration. The only tangible logging
|
# A sample logging configuration. The only tangible logging
|
||||||
|
Loading…
Reference in New Issue
Block a user