diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-10-14 13:57:33 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-10-30 13:39:51 +0000 |
commit | 298c3d52bab5cf38c37438c54853d6803ca194bd (patch) | |
tree | 2113944f04d337bc6a2ddfd2484f95ab7ea2d775 /bitbake/lib | |
parent | 2837b110ae8fd5ff0ca3ac5959cadb7d4a5ce6cc (diff) | |
download | ast2050-yocto-poky-298c3d52bab5cf38c37438c54853d6803ca194bd.zip ast2050-yocto-poky-298c3d52bab5cf38c37438c54853d6803ca194bd.tar.gz |
bitbake: toastergui: provide download file capability
We add, for the localhost environments, the capability to
download build artifacts. This is a pontentially dangerous API,
because it gives unrestricted read access to the build environment
file system - do not expose the functionality directly to the
web layer, but use filtering/translation code, such as
exemplified in the build_artifact view.
The capability for remote build environments is dependent
on bug 6835, as to use the collect storage as intermediary
storage for serving files.
[YOCTO #6834]
(Bitbake rev: 5fce7f6e83c6143244faa9618b7ed20c1106e08f)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/toaster/bldcontrol/models.py | 13 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/builddashboard.html | 4 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/task.html | 4 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/urls.py | 5 | ||||
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 40 |
5 files changed, 65 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/models.py b/bitbake/lib/toaster/bldcontrol/models.py index df3635b..15270c3 100644 --- a/bitbake/lib/toaster/bldcontrol/models.py +++ b/bitbake/lib/toaster/bldcontrol/models.py @@ -40,6 +40,19 @@ class BuildEnvironment(models.Model): updated = models.DateTimeField(auto_now = True) + def get_artifact_type(self, path): + if self.betype == BuildEnvironment.TYPE_LOCAL: + import magic + m = magic.open(magic.MAGIC_MIME_TYPE) + m.load() + return m.file(path) + raise Exception("FIXME: not implemented") + + def get_artifact(self, path): + if self.betype == BuildEnvironment.TYPE_LOCAL: + return open(path, "r") + raise Exception("FIXME: not implemented") + # a BuildRequest is a request that the scheduler will build using a BuildEnvironment # the build request queue is the table itself, ordered by state diff --git a/bitbake/lib/toaster/toastergui/templates/builddashboard.html b/bitbake/lib/toaster/toastergui/templates/builddashboard.html index 8a6709c..2aa7b6b 100644 --- a/bitbake/lib/toaster/toastergui/templates/builddashboard.html +++ b/bitbake/lib/toaster/toastergui/templates/builddashboard.html @@ -58,7 +58,11 @@ <div class="span10"> {% for error in logmessages %}{% if error.level == 2 %} <div class="alert alert-error"> + {% if MANAGED and error.pathname %} + <pre><a href="{% url 'build_artifact' build.pk 'logmessagefile' error.pk %}" target="_blanc">{{error.message}}</pre> + {% else %} <pre>{{error.message}}</pre> + {% endif %} </div> {% endif %}{% endfor %} </div> diff --git a/bitbake/lib/toaster/toastergui/templates/task.html b/bitbake/lib/toaster/toastergui/templates/task.html index d7e2619..1b27042 100644 --- a/bitbake/lib/toaster/toastergui/templates/task.html +++ b/bitbake/lib/toaster/toastergui/templates/task.html @@ -28,7 +28,11 @@ <i class="icon-question-sign get-help" title="Path the task log file"></i> Log file </dt> <dd> + {% if MANAGED %} + <code><a href="{% url 'build_artifact' build.pk 'tasklogfile' task.pk %}" target="_blanc">{{task.logfile}}</a></code> + {% else %} <code>{{task.logfile}}</code> + {% endif %} </dd> {% endif %} {# show stack trace for failed task #} diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index 07821b6..f43bb64 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py @@ -59,11 +59,14 @@ urlpatterns = patterns('toastergui.views', url(r'^build/(?P<build_id>\d+)/cpuusage$', 'cpuusage', name='cpuusage'), url(r'^build/(?P<build_id>\d+)/diskio$', 'diskio', name='diskio'), - # image information dir - not yet implemented + # image information dir url(r'^build/(?P<build_id>\d+)/target/(?P<target_id>\d+)/packagefile/(?P<packagefile_id>\d+)$', 'image_information_dir', name='image_information_dir'), + # build download artifact + url(r'^build/(?P<build_id>\d+)/artifact/(?P<artifact_type>\w+)/id/(?P<artifact_id>\w+)', 'build_artifact', name="build_artifact"), + # urls not linked from the dashboard url(r'^layerversions/(?P<layerversion_id>\d+)/recipes/.*$', 'layer_versions_recipes', name='layer_versions_recipes'), diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 38d67e3..e568ee7 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2603,6 +2603,43 @@ if toastermain.settings.MANAGED: + def build_artifact(request, build_id, artifact_type, artifact_id): + try: + b = Build.objects.get(pk=build_id) + if b.buildrequest is None or b.buildrequest.environment is None: + raise Exception("Cannot download file") + + file_name = None + fsock = None + content_type='application/force-download' + # Target_Image_File file_name + # Task logfile + if artifact_type == "tasklogfile": + file_name = Task.objects.get(build = b, pk = artifact_id).logfile + + # Task path_to_sstate_obj + # Package_File path + # Recipe file_path + # VariableHistory file_name + # LogMessage pathname + if artifact_type == "logmessagefile": + file_name = LogMessage.objects.get(build = b, pk = artifact_id).pathname + + if file_name is not None: + content_type = b.buildrequest.environment.get_artifact_type(file_name) + fsock = b.buildrequest.environment.get_artifact(file_name) + file_name = os.path.basename(file_name) + + response = HttpResponse(fsock, content_type = content_type) + + # returns a file from the environment + response['Content-Disposition'] = 'attachment; filename=' + file_name + return response + except: + raise + + + def projects(request): template="projects.html" @@ -2725,5 +2762,8 @@ else: def projectbuilds(request): raise Exception("page not available in interactive mode") + def build_artifact(request, build_id, artifact_type, artifact_id): + raise Exception("page not available in interactive mode") + def projects(request): raise Exception("page not available in interactive mode") |