Merge lp:~mhr3/zeitgeist/mimetypes into lp:zeitgeist/0.1

Proposed by Michal Hruby
Status: Rejected
Rejected by: Seif Lotfy
Proposed branch: lp:~mhr3/zeitgeist/mimetypes
Merge into: lp:zeitgeist/0.1
Diff against target: 500 lines (+248/-172)
5 files modified
_zeitgeist/loggers/datasources/recent.py (+2/-170)
test/engine-test.py (+25/-1)
test/test-mimetypes.py (+25/-0)
zeitgeist/Makefile.am (+2/-1)
zeitgeist/mimetypes.py (+194/-0)
To merge this branch: bzr merge lp:~mhr3/zeitgeist/mimetypes
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen visual review Needs Information
Review via email: mp+26233@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

Looks good on a quick glance over the diff. Nice work.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

While we are at improving our mime handling situation we might as well go the extra mile - especially now that we want to make it public API.

We now have interpretations like Interpretation.SPREADSHEET/PAGINATED_TEXT_DOCUMENT so we can do a much finer grained mapping of the mimetypes. This in turn works out beautifully with the queries because we now expand queries to also match all child types.

As an example take a look at my mimetype mappings libzeitgeist: http://bazaar.launchpad.net/~libzeitgeist-developers/libzeitgeist/trunk/annotate/head:/src/zeitgeist-mimetypes.c#L239

Anoter note: The public API should be added to our generated sphinx docs too...

review: Needs Information (visual review)
Revision history for this message
Markus Korn (thekorn) wrote :

I did not do a review yet, but I've one first comment: I don't like that we have the same logic in two places, in zeitgeist and in libzeitgeist. (and in the future also in C# and JS, ...)

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Perhaps we can compile the mimetype->interpretation map from some XML or JSON schemas, like we do for the ontologies, and have that be the authoritative place? For libzeitgeist I compile the ontology C-bindings from the Zeitgeist's Python module so there is no code dupe there. I could easily do the same for the mimetypes, but that requires a bit more structure in the mimetype spec than what is in Michal's proposal.

However doing all of this probably requires more work than I think we should put in for 0.3.4 at this point. I think the best route would be to either:

 1) Defer this task for post 0.3.4, or
 2) Make sure the implementation is done in a way so that we can add the extra introspection API for post 0.3.4 without breaking the mimetypes API from 0.3.4

I am not entirely sure which route I prefer, but I would hate to delay 0.3.4 more than we already have...

Revision history for this message
Seif Lotfy (seif) wrote :

Ok I am up for a mimetype-interpretation map:
I would prefer JSON for this issue...
what do u guys think?

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Why JSON and not straight Python? JSON would only slow down startup time, and Python already supports a very JSON-like syntax for declaring maps...

Revision history for this message
Seif Lotfy (seif) wrote :

Beacuse I think we want libzeitgeist and other languages to be able to
parse it... Or do u want to parse python syntax ?

On Mon, Jul 19, 2010 at 10:07 AM, Mikkel Kamstrup Erlandsen
<email address hidden> wrote:
> Why JSON and not straight Python? JSON would only slow down startup time, and Python already supports a very JSON-like syntax for declaring maps...
> --
> https://code.launchpad.net/~mhr3/zeitgeist/mimetypes/+merge/26233
> You are subscribed to branch lp:zeitgeist.
>

--
This is me doing some advertisement for my blog http://seilo.geekyogre.com

Revision history for this message
Markus Korn (thekorn) wrote :

This is not a reviewer comment, but I would like to add another possible way to solve this, python applications which would like to use this kind of mapper, could depend on libzeitgeist and use ctypes to access the mapper functions:

from ctypes import CDLL, c_char_p

libzeitgeist = CDLL("libzeitgeist-1.0.so.0")

interpretation_for_mimetype = libzeitgeist.zeitgeist_interpretation_for_mimetype
interpretation_for_mimetype.argtypes = [c_char_p,]
interpretation_for_mimetype.restype = c_char_p

print interpretation_for_mimetype("text/html")
print interpretation_for_mimetype("image/png")

manifestation_for_uri = libzeitgeist.zeitgeist_manifestation_for_uri
manifestation_for_uri.argtypes = [c_char_p,]
manifestation_for_uri.restype = c_char_p

print manifestation_for_uri("file:///home")
print manifestation_for_uri("http://www.google.de")

Revision history for this message
Siegfried Gevatter (rainct) wrote :

2010/7/19 Markus Korn <email address hidden>:
> This is not a reviewer comment, but I would like to add another possible way to solve this, python applications which would like to use this kind of mapper, could depend on libzeitgeist and use ctypes to access the mapper functions:

Eerk, making a real C->Python interface is not so difficult.

--
Siegfried-Angel Gevatter Pujals (RainCT)
Free Software Developer       363DEAE3

Revision history for this message
Michal Hruby (mhr3) wrote :

I think the cross-dependency of zg->libzg->zg is not a good idea, +1 for making it like the ontologies.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Markus, RainCT: Depending on libzeitgeist would add ~1mb to the Zeitgeist runtime I guess - which I think is a very steep price to pay for this.

As I noted in comment from 2010-05-28 I'd actually prefer a Python module for libzeitgeist, so I just write a small tool for libzeitgeist that outputs the C code at build time. Very easy for me, and fast and light for ZG.

Alternatively go full monty and write the autofoo magic that compiles some JSON/XML schema into Python code like we do for the ontology. In the end giving me a Python module to use in the libzeitgeist build process

Revision history for this message
Seif Lotfy (seif) wrote :

+1 for the alternative

On Mon, Jul 19, 2010 at 2:51 PM, Mikkel Kamstrup Erlandsen
<email address hidden> wrote:
> Markus, RainCT: Depending on libzeitgeist would add ~1mb to the Zeitgeist runtime I guess - which I think is a very steep price to pay for this.
>
> As I noted in comment from 2010-05-28 I'd actually prefer a Python module for libzeitgeist, so I just write a small tool for libzeitgeist that outputs the C code at build time. Very easy for me, and fast and light for ZG.
>
> Alternatively go full monty and write the autofoo magic that compiles some JSON/XML schema into Python code like we do for the ontology. In the end giving me a Python module to use in the libzeitgeist build process
> --
> https://code.launchpad.net/~mhr3/zeitgeist/mimetypes/+merge/26233
> You are subscribed to branch lp:zeitgeist.
>

--
This is me doing some advertisement for my blog http://seilo.geekyogre.com

Revision history for this message
Siegfried Gevatter (rainct) wrote :

Let's go with Python code, there's no reason to have it as JSON.

Revision history for this message
Seif Lotfy (seif) wrote :

Markus finished a module for that

Unmerged revisions

1460. By Michal Hruby

Interpretation.MUSIC -> Interpretation.AUDIO

1459. By Michal Hruby

Recent datasource: Use the zg.mimetypes module

1458. By Michal Hruby

Added mimetype to interpretation getter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_zeitgeist/loggers/datasources/recent.py'
2--- _zeitgeist/loggers/datasources/recent.py 2010-04-29 11:33:01 +0000
3+++ _zeitgeist/loggers/datasources/recent.py 2010-05-27 19:34:36 +0000
4@@ -24,8 +24,6 @@
5
6 from __future__ import with_statement
7 import os
8-import re
9-import fnmatch
10 import urllib
11 import time
12 import logging
13@@ -34,6 +32,7 @@
14 from zeitgeist import _config
15 from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \
16 DataSource, get_timestamp_for_now
17+from zeitgeist.mimetypes import get_interpretation_for_mimetype
18 from _zeitgeist.loggers.zeitgeist_base import DataProvider
19
20 log = logging.getLogger("zeitgeist.logger.datasources.recent")
21@@ -51,166 +50,9 @@
22 else:
23 enabled = True
24
25-class SimpleMatch(object):
26- """ Wrapper around fnmatch.fnmatch which allows to define mimetype
27- patterns by using shell-style wildcards.
28- """
29-
30- def __init__(self, pattern):
31- self.__pattern = pattern
32-
33- def match(self, text):
34- return fnmatch.fnmatch(text, self.__pattern)
35-
36- def __repr__(self):
37- return "%s(%r)" %(self.__class__.__name__, self.__pattern)
38-
39-DOCUMENT_MIMETYPES = [
40- # Covers:
41- # vnd.corel-draw
42- # vnd.ms-powerpoint
43- # vnd.ms-excel
44- # vnd.oasis.opendocument.*
45- # vnd.stardivision.*
46- # vnd.sun.xml.*
47- SimpleMatch(u"application/vnd.*"),
48- # Covers: x-applix-word, x-applix-spreadsheet, x-applix-presents
49- SimpleMatch(u"application/x-applix-*"),
50- # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
51- re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
52- u"application/ms-powerpoint",
53- u"application/msword",
54- u"application/pdf",
55- u"application/postscript",
56- u"application/ps",
57- u"application/rtf",
58- u"application/x-abiword",
59- u"application/x-gnucash",
60- u"application/x-gnumeric",
61- SimpleMatch(u"application/x-java*"),
62- SimpleMatch(u"*/x-tex"),
63- SimpleMatch(u"*/x-latex"),
64- SimpleMatch(u"*/x-dvi"),
65- u"text/plain"
66-]
67-
68-IMAGE_MIMETYPES = [
69- # Covers:
70- # vnd.corel-draw
71- u"application/vnd.corel-draw",
72- # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
73- re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
74- SimpleMatch(u"image/*"),
75-]
76-
77-AUDIO_MIMETYPES = [
78- SimpleMatch(u"audio/*"),
79- u"application/ogg"
80-]
81-
82-VIDEO_MIMETYPES = [
83- SimpleMatch(u"video/*"),
84- u"application/ogg"
85-]
86-
87-DEVELOPMENT_MIMETYPES = [
88- u"application/ecmascript",
89- u"application/javascript",
90- u"application/x-csh",
91- u"application/x-designer",
92- u"application/x-desktop",
93- u"application/x-dia-diagram",
94- u"application/x-fluid",
95- u"application/x-glade",
96- u"application/xhtml+xml",
97- u"application/x-java-archive",
98- u"application/x-m4",
99- u"application/xml",
100- u"application/x-object",
101- u"application/x-perl",
102- u"application/x-php",
103- u"application/x-ruby",
104- u"application/x-shellscript",
105- u"application/x-sql",
106- u"text/css",
107- u"text/html",
108- u"text/x-c",
109- u"text/x-c++",
110- u"text/x-chdr",
111- u"text/x-copying",
112- u"text/x-credits",
113- u"text/x-csharp",
114- u"text/x-c++src",
115- u"text/x-csrc",
116- u"text/x-dsrc",
117- u"text/x-eiffel",
118- u"text/x-gettext-translation",
119- u"text/x-gettext-translation-template",
120- u"text/x-haskell",
121- u"text/x-idl",
122- u"text/x-java",
123- u"text/x-lisp",
124- u"text/x-lua",
125- u"text/x-makefile",
126- u"text/x-objcsrc",
127- u"text/x-ocaml",
128- u"text/x-pascal",
129- u"text/x-patch",
130- u"text/x-python",
131- u"text/x-sql",
132- u"text/x-tcl",
133- u"text/x-troff",
134- u"text/x-vala",
135- u"text/x-vhdl",
136-]
137-
138-ALL_MIMETYPES = DOCUMENT_MIMETYPES + IMAGE_MIMETYPES + AUDIO_MIMETYPES + \
139- VIDEO_MIMETYPES + DEVELOPMENT_MIMETYPES
140-
141-class MimeTypeSet(set):
142- """ Set which allows to match against a string or an object with a
143- match() method.
144- """
145-
146- def __init__(self, *items):
147- super(MimeTypeSet, self).__init__()
148- self.__pattern = set()
149- for item in items:
150- if isinstance(item, (str, unicode)):
151- self.add(item)
152- elif hasattr(item, "match"):
153- self.__pattern.add(item)
154- else:
155- raise ValueError("Bad mimetype '%s'" %item)
156-
157- def __contains__(self, mimetype):
158- result = super(MimeTypeSet, self).__contains__(mimetype)
159- if not result:
160- for pattern in self.__pattern:
161- if pattern.match(mimetype):
162- return True
163- return result
164-
165- def __len__(self):
166- return super(MimeTypeSet, self).__len__() + len(self.__pattern)
167-
168- def __repr__(self):
169- items = ", ".join(sorted(map(repr, self | self.__pattern)))
170- return "%s(%s)" %(self.__class__.__name__, items)
171-
172
173 class RecentlyUsedManagerGtk(DataProvider):
174
175- FILTERS = {
176- # dict of name as key and the matching mimetypes as value
177- # if the value is None this filter matches all mimetypes
178- "DOCUMENT": MimeTypeSet(*DOCUMENT_MIMETYPES),
179- "IMAGE": MimeTypeSet(*IMAGE_MIMETYPES),
180- "MUSIC": MimeTypeSet(*AUDIO_MIMETYPES),
181- "VIDEO": MimeTypeSet(*VIDEO_MIMETYPES),
182- "SOURCE_CODE": MimeTypeSet(*DEVELOPMENT_MIMETYPES),
183- }
184-
185 def __init__(self, client):
186 DataProvider.__init__(self,
187 unique_id="com.zeitgeist-project,datahub,recent",
188@@ -269,16 +111,6 @@
189 pass # file may be a broken symlink (LP: #523761)
190 return None
191
192- def _get_interpretation_for_mimetype(self, mimetype):
193- matching_filter = None
194- for filter_name, mimetypes in self.FILTERS.iteritems():
195- if mimetype and mimetype in mimetypes:
196- matching_filter = filter_name
197- break
198- if matching_filter:
199- return getattr(Interpretation, matching_filter).uri
200- return ""
201-
202 def _get_items(self):
203 # We save the start timestamp to avoid race conditions
204 last_seen = get_timestamp_for_now()
205@@ -297,7 +129,7 @@
206
207 subject = Subject.new_for_values(
208 uri = unicode(uri),
209- interpretation = self._get_interpretation_for_mimetype(
210+ interpretation = get_interpretation_for_mimetype(
211 unicode(info.get_mime_type())),
212 manifestation = Manifestation.FILE_DATA_OBJECT.uri,
213 text = info.get_display_name(),
214
215=== modified file 'test/engine-test.py'
216--- test/engine-test.py 2010-05-15 13:15:44 +0000
217+++ test/engine-test.py 2010-05-27 19:34:36 +0000
218@@ -10,6 +10,7 @@
219 from _zeitgeist.engine import constants
220 from _zeitgeist.engine import get_engine
221 from zeitgeist.datamodel import *
222+from zeitgeist.mimetypes import *
223 from testutils import import_events
224
225 import unittest
226@@ -366,7 +367,30 @@
227 self.assertEquals(2, len(result))
228 events = self.engine.get_events(result)
229
230-
231+ def testMimetypeToInterpretation(self):
232+ mimetype = "text/plain"
233+ interpretation = get_interpretation_for_mimetype(mimetype)
234+
235+ event = Event()
236+ event.interpretation = Manifestation.USER_ACTIVITY
237+ event.manifestation = Interpretation.CREATE_EVENT
238+ event.actor = "/usr/share/applications/gnome-about.desktop"
239+
240+ subject = Subject()
241+ subject.uri = "file:///tmp/file.txt"
242+ subject.manifestation = Manifestation.FILE_DATA_OBJECT
243+ subject.interpretation = interpretation
244+ subject.origin = "test://"
245+ subject.mimetype = "text/plain"
246+ subject.text = "This subject has no text"
247+
248+ event.append_subject(subject)
249+ ids = self.engine.insert_events([event,])
250+
251+ results = self.engine.get_events([1])
252+ self.assertEquals(1, len(results))
253+ self.assertEquals(
254+ interpretation, results[0].subjects[0].interpretation)
255
256 def testDontFindState(self):
257 # searchin by storage state is currently not implemented
258
259=== added file 'test/test-mimetypes.py'
260--- test/test-mimetypes.py 1970-01-01 00:00:00 +0000
261+++ test/test-mimetypes.py 2010-05-27 19:34:36 +0000
262@@ -0,0 +1,25 @@
263+#! /usr/bin/python
264+
265+# Update python path to use local zeitgeist module
266+import sys
267+import os
268+
269+import zeitgeist.mimetypes
270+
271+# Test the mimetype -> Interpretation conversion
272+mimetype = "image/png"
273+i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
274+print "Interpretation for %s: %s" % (mimetype, i)
275+
276+mimetype = "text/plain"
277+i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
278+print "Interpretation for %s: %s" % (mimetype, i)
279+
280+mimetype = "application/ogg"
281+i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
282+print "Interpretation for %s: %s" % (mimetype, i)
283+
284+mimetype = "unknown/invalid"
285+i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
286+print "Interpretation for %s: %s" % (mimetype, i)
287+
288
289=== modified file 'zeitgeist/Makefile.am'
290--- zeitgeist/Makefile.am 2009-11-27 20:32:54 +0000
291+++ zeitgeist/Makefile.am 2010-05-27 19:34:36 +0000
292@@ -3,7 +3,8 @@
293 app_PYTHON = \
294 __init__.py \
295 datamodel.py \
296- client.py
297+ client.py \
298+ mimetypes.py
299
300 nodist_app_PYTHON = _config.py
301
302
303=== added file 'zeitgeist/mimetypes.py'
304--- zeitgeist/mimetypes.py 1970-01-01 00:00:00 +0000
305+++ zeitgeist/mimetypes.py 2010-05-27 19:34:36 +0000
306@@ -0,0 +1,194 @@
307+# -.- coding: utf-8 -.-
308+
309+# Zeitgeist
310+#
311+# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
312+# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
313+# Copyright © 2009 Markus Korn <thekorn@gmx.de>
314+# Copyright © 2010 Michal Hruby <michal.mhr@gmail.com>
315+#
316+# This program is free software: you can redistribute it and/or modify
317+# it under the terms of the GNU Lesser General Public License as published by
318+# the Free Software Foundation, either version 3 of the License, or
319+# (at your option) any later version.
320+#
321+# This program is distributed in the hope that it will be useful,
322+# but WITHOUT ANY WARRANTY; without even the implied warranty of
323+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
324+# GNU Lesser General Public License for more details.
325+#
326+# You should have received a copy of the GNU Lesser General Public License
327+# along with this program. If not, see <http://www.gnu.org/licenses/>.
328+
329+import re
330+import fnmatch
331+
332+from zeitgeist.datamodel import Interpretation
333+
334+class SimpleMatch(object):
335+ """ Wrapper around fnmatch.fnmatch which allows to define mimetype
336+ patterns by using shell-style wildcards.
337+ """
338+
339+ def __init__(self, pattern):
340+ self.__pattern = pattern
341+
342+ def match(self, text):
343+ return fnmatch.fnmatch(text, self.__pattern)
344+
345+ def __repr__(self):
346+ return "%s(%r)" %(self.__class__.__name__, self.__pattern)
347+
348+class MimeTypeSet(set):
349+ """ Set which allows to match against a string or an object with a
350+ match() method.
351+ """
352+
353+ def __init__(self, *items):
354+ super(MimeTypeSet, self).__init__()
355+ self.__pattern = set()
356+ for item in items:
357+ if isinstance(item, (str, unicode)):
358+ self.add(item)
359+ elif hasattr(item, "match"):
360+ self.__pattern.add(item)
361+ else:
362+ raise ValueError("Bad mimetype '%s'" %item)
363+
364+ def __contains__(self, mimetype):
365+ result = super(MimeTypeSet, self).__contains__(mimetype)
366+ if not result:
367+ for pattern in self.__pattern:
368+ if pattern.match(mimetype):
369+ return True
370+ return result
371+
372+ def __len__(self):
373+ return super(MimeTypeSet, self).__len__() + len(self.__pattern)
374+
375+ def __repr__(self):
376+ items = ", ".join(sorted(map(repr, self | self.__pattern)))
377+ return "%s(%s)" %(self.__class__.__name__, items)
378+
379+DOCUMENT_MIMETYPES = [
380+ # Covers:
381+ # vnd.corel-draw
382+ # vnd.ms-powerpoint
383+ # vnd.ms-excel
384+ # vnd.oasis.opendocument.*
385+ # vnd.stardivision.*
386+ # vnd.sun.xml.*
387+ SimpleMatch(u"application/vnd.*"),
388+ # Covers: x-applix-word, x-applix-spreadsheet, x-applix-presents
389+ SimpleMatch(u"application/x-applix-*"),
390+ # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
391+ re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
392+ u"application/ms-powerpoint",
393+ u"application/msword",
394+ u"application/pdf",
395+ u"application/postscript",
396+ u"application/ps",
397+ u"application/rtf",
398+ u"application/x-abiword",
399+ u"application/x-gnucash",
400+ u"application/x-gnumeric",
401+ SimpleMatch(u"application/x-java*"),
402+ SimpleMatch(u"*/x-tex"),
403+ SimpleMatch(u"*/x-latex"),
404+ SimpleMatch(u"*/x-dvi"),
405+ u"text/plain"
406+]
407+
408+IMAGE_MIMETYPES = [
409+ # Covers:
410+ # vnd.corel-draw
411+ u"application/vnd.corel-draw",
412+ # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
413+ re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
414+ SimpleMatch(u"image/*"),
415+]
416+
417+AUDIO_MIMETYPES = [
418+ SimpleMatch(u"audio/*"),
419+ u"application/ogg"
420+]
421+
422+VIDEO_MIMETYPES = [
423+ SimpleMatch(u"video/*"),
424+ u"application/ogg"
425+]
426+
427+DEVELOPMENT_MIMETYPES = [
428+ u"application/ecmascript",
429+ u"application/javascript",
430+ u"application/x-csh",
431+ u"application/x-designer",
432+ u"application/x-desktop",
433+ u"application/x-dia-diagram",
434+ u"application/x-fluid",
435+ u"application/x-glade",
436+ u"application/xhtml+xml",
437+ u"application/x-java-archive",
438+ u"application/x-m4",
439+ u"application/xml",
440+ u"application/x-object",
441+ u"application/x-perl",
442+ u"application/x-php",
443+ u"application/x-ruby",
444+ u"application/x-shellscript",
445+ u"application/x-sql",
446+ u"text/css",
447+ u"text/html",
448+ u"text/x-c",
449+ u"text/x-c++",
450+ u"text/x-chdr",
451+ u"text/x-copying",
452+ u"text/x-credits",
453+ u"text/x-csharp",
454+ u"text/x-c++src",
455+ u"text/x-csrc",
456+ u"text/x-dsrc",
457+ u"text/x-eiffel",
458+ u"text/x-gettext-translation",
459+ u"text/x-gettext-translation-template",
460+ u"text/x-haskell",
461+ u"text/x-idl",
462+ u"text/x-java",
463+ u"text/x-lisp",
464+ u"text/x-lua",
465+ u"text/x-makefile",
466+ u"text/x-objcsrc",
467+ u"text/x-ocaml",
468+ u"text/x-pascal",
469+ u"text/x-patch",
470+ u"text/x-python",
471+ u"text/x-sql",
472+ u"text/x-tcl",
473+ u"text/x-troff",
474+ u"text/x-vala",
475+ u"text/x-vhdl",
476+]
477+
478+ALL_MIMETYPES = DOCUMENT_MIMETYPES + IMAGE_MIMETYPES + AUDIO_MIMETYPES + \
479+ VIDEO_MIMETYPES + DEVELOPMENT_MIMETYPES
480+
481+FILTERS = {
482+ # dict of name as key and the matching mimetypes as value
483+ # if the value is None this filter matches all mimetypes
484+ "DOCUMENT": MimeTypeSet(*DOCUMENT_MIMETYPES),
485+ "IMAGE": MimeTypeSet(*IMAGE_MIMETYPES),
486+ "AUDIO": MimeTypeSet(*AUDIO_MIMETYPES),
487+ "VIDEO": MimeTypeSet(*VIDEO_MIMETYPES),
488+ "SOURCE_CODE": MimeTypeSet(*DEVELOPMENT_MIMETYPES),
489+}
490+
491+def get_interpretation_for_mimetype(mimetype):
492+ matching_filter = None
493+ for filter_name, mimetypes in FILTERS.iteritems():
494+ if mimetype and mimetype in mimetypes:
495+ matching_filter = filter_name
496+ break
497+ if matching_filter:
498+ return getattr(Interpretation, matching_filter).uri
499+ return ""
500+