From df48243970fac633586eb99c9baf3090123c681c Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Tue, 16 Jun 2015 16:00:26 +0100 Subject: bitbake: toaster: split orm app into it's own module and app The orm application was also the django application to collect the build information. Splitting this module up into it's functional parts. orm for the data module and bldcollector for build collection data. (Bitbake rev: 8ca10764ffd6cfec12cbfeabf240d81213a07845) Signed-off-by: Michael Wood Signed-off-by: Richard Purdie --- bitbake/lib/toaster/bldcollector/__init__.py | 0 bitbake/lib/toaster/bldcollector/admin.py | 33 +++++++++++++++ bitbake/lib/toaster/bldcollector/urls.py | 26 ++++++++++++ bitbake/lib/toaster/bldcollector/views.py | 62 ++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 bitbake/lib/toaster/bldcollector/__init__.py create mode 100644 bitbake/lib/toaster/bldcollector/admin.py create mode 100644 bitbake/lib/toaster/bldcollector/urls.py create mode 100644 bitbake/lib/toaster/bldcollector/views.py (limited to 'bitbake/lib/toaster/bldcollector') diff --git a/bitbake/lib/toaster/bldcollector/__init__.py b/bitbake/lib/toaster/bldcollector/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bitbake/lib/toaster/bldcollector/admin.py b/bitbake/lib/toaster/bldcollector/admin.py new file mode 100644 index 0000000000..c1f85d73d5 --- /dev/null +++ b/bitbake/lib/toaster/bldcollector/admin.py @@ -0,0 +1,33 @@ +from django.contrib import admin +from django.contrib.admin.filters import RelatedFieldListFilter +from orm.models import BitbakeVersion, Release, LayerSource, ToasterSetting +from django.forms.widgets import Textarea +from django import forms +import django.db.models as models + +from django.contrib.admin import widgets, helpers + +class LayerSourceAdmin(admin.ModelAdmin): + pass + +class BitbakeVersionAdmin(admin.ModelAdmin): + + # we override the formfield for db URLField because of broken URL validation + + def formfield_for_dbfield(self, db_field, **kwargs): + if isinstance(db_field, models.fields.URLField): + return forms.fields.CharField() + return super(BitbakeVersionAdmin, self).formfield_for_dbfield(db_field, **kwargs) + + + +class ReleaseAdmin(admin.ModelAdmin): + pass + +class ToasterSettingAdmin(admin.ModelAdmin): + pass + +admin.site.register(LayerSource, LayerSourceAdmin) +admin.site.register(BitbakeVersion, BitbakeVersionAdmin) +admin.site.register(Release, ReleaseAdmin) +admin.site.register(ToasterSetting, ToasterSettingAdmin) diff --git a/bitbake/lib/toaster/bldcollector/urls.py b/bitbake/lib/toaster/bldcollector/urls.py new file mode 100644 index 0000000000..144387b56a --- /dev/null +++ b/bitbake/lib/toaster/bldcollector/urls.py @@ -0,0 +1,26 @@ +# +# BitBake Toaster Implementation +# +# Copyright (C) 2014 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +from django.conf.urls import patterns, include, url +from django.views.generic import RedirectView + +urlpatterns = patterns('bldcollector.views', + # landing point for pushing a bitbake_eventlog.json file to this toaster instace + url(r'^eventfile$', 'eventfile', name='eventfile'), + ) diff --git a/bitbake/lib/toaster/bldcollector/views.py b/bitbake/lib/toaster/bldcollector/views.py new file mode 100644 index 0000000000..f32fa4d225 --- /dev/null +++ b/bitbake/lib/toaster/bldcollector/views.py @@ -0,0 +1,62 @@ +# +# BitBake Toaster Implementation +# +# Copyright (C) 2014 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django.views.decorators.cache import cache_control +from django.core.urlresolvers import reverse +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.http import HttpResponseBadRequest, HttpResponse +from django.utils import timezone +from django.utils.html import escape +from datetime import timedelta +from django.utils import formats +from toastergui.templatetags.projecttags import json as jsonfilter +import json +import os +import tempfile +import subprocess +import toastermain +from django.views.decorators.csrf import csrf_exempt + + +@csrf_exempt +def eventfile(request): + """ Receives a file by POST, and runs toaster-eventreply on this file """ + if request.method != "POST": + return HttpResponseBadRequest("This API only accepts POST requests. Post a file with:\n\ncurl -F eventlog=@bitbake_eventlog.json %s\n" % request.build_absolute_uri(reverse('eventfile')), content_type="text/plain;utf8") + + # write temporary file + (handle, abstemppath) = tempfile.mkstemp(dir="/tmp/") + with os.fdopen(handle, "w") as tmpfile: + for chunk in request.FILES['eventlog'].chunks(): + tmpfile.write(chunk) + tmpfile.close() + + # compute the path to "bitbake/bin/toaster-eventreplay" + from os.path import dirname as DN + import_script = os.path.join(DN(DN(DN(DN(os.path.abspath(__file__))))), "bin/toaster-eventreplay") + if not os.path.exists(import_script): + raise Exception("script missing %s" % import_script) + scriptenv = os.environ.copy() + scriptenv["DATABASE_URL"] = toastermain.settings.getDATABASE_URL() + + # run the data loading process and return the results + importer = subprocess.Popen([import_script, abstemppath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=scriptenv) + (out, err) = importer.communicate() + if importer.returncode == 0: + os.remove(abstemppath) + return HttpResponse("== Retval %d\n== STDOUT\n%s\n\n== STDERR\n%s" % (importer.returncode, out, err), content_type="text/plain;utf8") -- cgit v1.2.3-54-g00ecf