summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/toaster/bldcontrol/models.py34
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py18
2 files changed, 17 insertions, 35 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/models.py b/bitbake/lib/toaster/bldcontrol/models.py
index 02cfaf7086..770ce40ae0 100644
--- a/bitbake/lib/toaster/bldcontrol/models.py
+++ b/bitbake/lib/toaster/bldcontrol/models.py
@@ -39,40 +39,6 @@ class BuildEnvironment(models.Model):
39 created = models.DateTimeField(auto_now_add = True) 39 created = models.DateTimeField(auto_now_add = True)
40 updated = models.DateTimeField(auto_now = True) 40 updated = models.DateTimeField(auto_now = True)
41 41
42
43 def get_artifact_type(self, path):
44 if self.betype == BuildEnvironment.TYPE_LOCAL:
45 try:
46 import magic
47
48 # fair warning: this is a mess; there are multiple competeing and incompatible
49 # magic modules floating around, so we try some of the most common combinations
50
51 try: # we try ubuntu's python-magic 5.4
52 m = magic.open(magic.MAGIC_MIME_TYPE)
53 m.load()
54 return m.file(path)
55 except AttributeError:
56 pass
57
58 try: # we try python-magic 0.4.6
59 m = magic.Magic(magic.MAGIC_MIME)
60 return m.from_file(path)
61 except AttributeError:
62 pass
63
64 try: # we try pip filemagic 1.6
65 m = magic.Magic(flags=magic.MAGIC_MIME_TYPE)
66 return m.id_filename(path)
67 except AttributeError:
68 pass
69
70 return "binary/octet-stream"
71 except ImportError:
72 return "binary/octet-stream"
73 raise Exception("FIXME: artifact type not implemented for build environment type %s" % be.get_betype_display())
74
75
76 def get_artifact(self, path): 42 def get_artifact(self, path):
77 if self.betype == BuildEnvironment.TYPE_LOCAL: 43 if self.betype == BuildEnvironment.TYPE_LOCAL:
78 return open(path, "r") 44 return open(path, "r")
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index be59c83651..98b040e5ab 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -39,6 +39,22 @@ from datetime import timedelta, datetime, date
39from django.utils import formats 39from django.utils import formats
40from toastergui.templatetags.projecttags import json as jsonfilter 40from toastergui.templatetags.projecttags import json as jsonfilter
41import json 41import json
42import mimetypes
43
44class MimeTypeFinder(object):
45 # setting this to False enables additional non-standard mimetypes
46 # to be included in the guess
47 _strict = False
48
49 # returns the mimetype for a file path as a string,
50 # or 'application/octet-stream' if the type couldn't be guessed
51 @classmethod
52 def get_mimetype(self, path):
53 guess = mimetypes.guess_type(path, self._strict)
54 guessed_type = guess[0]
55 if guessed_type == None:
56 guessed_type = 'application/octet-stream'
57 return guessed_type
42 58
43# all new sessions should come through the landing page; 59# all new sessions should come through the landing page;
44# determine in which mode we are running in, and redirect appropriately 60# determine in which mode we are running in, and redirect appropriately
@@ -3209,7 +3225,7 @@ if toastermain.settings.MANAGED:
3209 if file_name is None: 3225 if file_name is None:
3210 raise Exception("Could not handle artifact %s id %s" % (artifact_type, artifact_id)) 3226 raise Exception("Could not handle artifact %s id %s" % (artifact_type, artifact_id))
3211 else: 3227 else:
3212 content_type = b.buildrequest.environment.get_artifact_type(file_name) 3228 content_type = MimeTypeFinder.get_mimetype(file_name)
3213 fsock = b.buildrequest.environment.get_artifact(file_name) 3229 fsock = b.buildrequest.environment.get_artifact(file_name)
3214 file_name = os.path.basename(file_name) # we assume that the build environment system has the same path conventions as host 3230 file_name = os.path.basename(file_name) # we assume that the build environment system has the same path conventions as host
3215 3231