diff options
| -rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 42 | ||||
| -rw-r--r-- | bitbake/toaster-requirements.txt | 1 |
2 files changed, 11 insertions, 32 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 784272fd70..e918b052fd 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
| @@ -47,10 +47,19 @@ import json | |||
| 47 | from os.path import dirname | 47 | from os.path import dirname |
| 48 | import itertools | 48 | import itertools |
| 49 | 49 | ||
| 50 | import magic | ||
| 50 | import logging | 51 | import logging |
| 51 | 52 | ||
| 52 | logger = logging.getLogger("toaster") | 53 | logger = logging.getLogger("toaster") |
| 53 | 54 | ||
| 55 | class MimeTypeFinder(object): | ||
| 56 | _magic = magic.Magic(flags = magic.MAGIC_MIME_TYPE) | ||
| 57 | |||
| 58 | # returns the mimetype for a file path | ||
| 59 | @classmethod | ||
| 60 | def get_mimetype(self, path): | ||
| 61 | return self._magic.id_filename(path) | ||
| 62 | |||
| 54 | # all new sessions should come through the landing page; | 63 | # all new sessions should come through the landing page; |
| 55 | # determine in which mode we are running in, and redirect appropriately | 64 | # determine in which mode we are running in, and redirect appropriately |
| 56 | def landing(request): | 65 | def landing(request): |
| @@ -68,8 +77,6 @@ def landing(request): | |||
| 68 | 77 | ||
| 69 | return render(request, 'landing.html', context) | 78 | return render(request, 'landing.html', context) |
| 70 | 79 | ||
| 71 | |||
| 72 | |||
| 73 | # returns a list for most recent builds; | 80 | # returns a list for most recent builds; |
| 74 | def _get_latest_builds(prj=None): | 81 | def _get_latest_builds(prj=None): |
| 75 | queryset = Build.objects.all() | 82 | queryset = Build.objects.all() |
| @@ -2710,40 +2717,11 @@ if True: | |||
| 2710 | 2717 | ||
| 2711 | def build_artifact(request, build_id, artifact_type, artifact_id): | 2718 | def build_artifact(request, build_id, artifact_type, artifact_id): |
| 2712 | if artifact_type in ["cookerlog"]: | 2719 | if artifact_type in ["cookerlog"]: |
| 2713 | def _mimetype_for_artifact(path): | ||
| 2714 | try: | ||
| 2715 | import magic | ||
| 2716 | |||
| 2717 | # fair warning: this is a mess; there are multiple competing and incompatible | ||
| 2718 | # magic modules floating around, so we try some of the most common combinations | ||
| 2719 | |||
| 2720 | try: # we try ubuntu's python-magic 5.4 | ||
| 2721 | m = magic.open(magic.MAGIC_MIME_TYPE) | ||
| 2722 | m.load() | ||
| 2723 | return m.file(path) | ||
| 2724 | except AttributeError: | ||
| 2725 | pass | ||
| 2726 | |||
| 2727 | try: # we try python-magic 0.4.6 | ||
| 2728 | m = magic.Magic(magic.MAGIC_MIME) | ||
| 2729 | return m.from_file(path) | ||
| 2730 | except AttributeError: | ||
| 2731 | pass | ||
| 2732 | |||
| 2733 | try: # we try pip filemagic 1.6 | ||
| 2734 | m = magic.Magic(flags=magic.MAGIC_MIME_TYPE) | ||
| 2735 | return m.id_filename(path) | ||
| 2736 | except AttributeError: | ||
| 2737 | pass | ||
| 2738 | |||
| 2739 | return "binary/octet-stream" | ||
| 2740 | except ImportError: | ||
| 2741 | return "binary/octet-stream" | ||
| 2742 | try: | 2720 | try: |
| 2743 | build = Build.objects.get(pk = build_id) | 2721 | build = Build.objects.get(pk = build_id) |
| 2744 | file_name = build.cooker_log_path | 2722 | file_name = build.cooker_log_path |
| 2745 | fsock = open(file_name, "r") | 2723 | fsock = open(file_name, "r") |
| 2746 | content_type = _mimetype_for_artifact(file_name) | 2724 | content_type = MimeTypeFinder.get_mimetype(file_name) |
| 2747 | 2725 | ||
| 2748 | response = HttpResponse(fsock, content_type = content_type) | 2726 | response = HttpResponse(fsock, content_type = content_type) |
| 2749 | 2727 | ||
diff --git a/bitbake/toaster-requirements.txt b/bitbake/toaster-requirements.txt index 19b5293722..1d92d5e3a7 100644 --- a/bitbake/toaster-requirements.txt +++ b/bitbake/toaster-requirements.txt | |||
| @@ -2,3 +2,4 @@ Django==1.6 | |||
| 2 | South==0.8.4 | 2 | South==0.8.4 |
| 3 | argparse==1.2.1 | 3 | argparse==1.2.1 |
| 4 | wsgiref==0.1.2 | 4 | wsgiref==0.1.2 |
| 5 | filemagic==1.6 | ||
