summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-12-09 14:19:23 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-18 10:24:06 +0000
commit4061fcdeeb54f08f97089b58ab99160c2fe10604 (patch)
treeecffb9bc681191c2a19f53a4ae3646edf000414f /bitbake
parentaa9816ad79ca34000c1cb0cdc4d35b5fc09a9ba3 (diff)
downloadpoky-4061fcdeeb54f08f97089b58ab99160c2fe10604.tar.gz
bitbake: add POST endpoint for uploading eventlog files
This patch adds a simple UI-less POST endpoint, where bitbake_eventlog.json files generated by a bitbake run can be uploaded to the running toaster instance for insertion into the database. (Bitbake rev: cf98a8cbc5dd7a41bbe5fdebcd81e29b1621ff35) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/toaster/orm/urls.py27
-rw-r--r--bitbake/lib/toaster/orm/views.py60
2 files changed, 87 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/orm/urls.py b/bitbake/lib/toaster/orm/urls.py
new file mode 100644
index 0000000000..961bc19070
--- /dev/null
+++ b/bitbake/lib/toaster/orm/urls.py
@@ -0,0 +1,27 @@
1#
2# BitBake Toaster Implementation
3#
4# Copyright (C) 2014 Intel Corporation
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
20from django.conf.urls import patterns, include, url
21from django.views.generic import RedirectView
22
23urlpatterns = patterns('orm.views',
24 # landing point for pushing a bitbake_eventlog.json file to this toaster instace
25 url(r'^eventfile$', 'eventfile', name='eventfile'),
26 )
27
diff --git a/bitbake/lib/toaster/orm/views.py b/bitbake/lib/toaster/orm/views.py
new file mode 100644
index 0000000000..97d792b99e
--- /dev/null
+++ b/bitbake/lib/toaster/orm/views.py
@@ -0,0 +1,60 @@
1#
2# BitBake Toaster Implementation
3#
4# Copyright (C) 2014 Intel Corporation
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19from django.views.decorators.cache import cache_control
20from django.core.urlresolvers import reverse
21from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
22from django.http import HttpResponseBadRequest, HttpResponse
23from django.utils import timezone
24from django.utils.html import escape
25from datetime import timedelta
26from django.utils import formats
27from toastergui.templatetags.projecttags import json as jsonfilter
28import json
29import os
30import tempfile
31import subprocess
32import toastermain
33from django.views.decorators.csrf import csrf_exempt
34
35
36@csrf_exempt
37def eventfile(request):
38 """ Receives a file by POST, and runs toaster-eventreply on this file """
39 if request.method != "POST":
40 return HttpResponseBadRequest("This API only accepts POST requests. Post a file with:\n\ncurl -F eventlog=@bitbake_eventlog.json http[s]://[server-address]/orm/eventfile\n", content_type="text/plain;utf8")
41
42 # write temporary file
43 (handle, abstemppath) = tempfile.mkstemp(dir="/tmp/")
44 with os.fdopen(handle, "w") as tmpfile:
45 for chunk in request.FILES['eventlog'].chunks():
46 tmpfile.write(chunk)
47 tmpfile.close()
48
49 # compute the path to "bitbake/bin/toaster-eventreplay"
50 from os.path import dirname as DN
51 import_script = os.path.join(DN(DN(DN(DN(os.path.abspath(__file__))))), "bin/toaster-eventreplay")
52 if not os.path.exists(import_script):
53 raise Exception("script missing %s" % import_script)
54 scriptenv = os.environ.copy()
55 scriptenv["DATABASE_URL"] = toastermain.settings.getDATABASE_URL()
56
57 # run the data loading process and return the results
58 (out, err) = subprocess.Popen([import_script, abstemppath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=scriptenv).communicate()
59 os.remove(abstemppath)
60 return HttpResponse("%s\n%s" % (out, err), content_type="text/plain;utf8")