bitbake: toaster: Rework mimetype guessing to fix artifact downloads

Artifact download links were broken because the function to
get the mimetype for the artifact was incorrectly using the
underlying mimetype library. The function was also attached
to the build environment controller, which was unnecessary, as
we only support local controllers anyway.

Remove the mimetype getter on the build environment and
use the one in the view code instead. This prevents the download error
from occurring.

(Backport of dd957fe0f2 and
dd957fe0f2 from master to Yocto 1.8)

[YOCTO #8472]

(Bitbake rev: b09966906ef054834f0b465f0c5a2a937b4c4a4c)

Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Elliot Smith
2015-12-18 11:55:25 +02:00
committed by Richard Purdie
parent aff2257e0b
commit 6e3eefb997
2 changed files with 17 additions and 35 deletions

View File

@@ -39,6 +39,22 @@ from datetime import timedelta, datetime, date
from django.utils import formats
from toastergui.templatetags.projecttags import json as jsonfilter
import json
import mimetypes
class MimeTypeFinder(object):
# setting this to False enables additional non-standard mimetypes
# to be included in the guess
_strict = False
# returns the mimetype for a file path as a string,
# or 'application/octet-stream' if the type couldn't be guessed
@classmethod
def get_mimetype(self, path):
guess = mimetypes.guess_type(path, self._strict)
guessed_type = guess[0]
if guessed_type == None:
guessed_type = 'application/octet-stream'
return guessed_type
# all new sessions should come through the landing page;
# determine in which mode we are running in, and redirect appropriately
@@ -3209,7 +3225,7 @@ if toastermain.settings.MANAGED:
if file_name is None:
raise Exception("Could not handle artifact %s id %s" % (artifact_type, artifact_id))
else:
content_type = b.buildrequest.environment.get_artifact_type(file_name)
content_type = MimeTypeFinder.get_mimetype(file_name)
fsock = b.buildrequest.environment.get_artifact(file_name)
file_name = os.path.basename(file_name) # we assume that the build environment system has the same path conventions as host