Michal Hruby has proposed merging lp:~mhr3/zeitgeist/mimetypes into
lp:zeitgeist.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
--
https://code.launchpad.net/~mhr3/zeitgeist/mimetypes/+merge/26233
Your team Zeitgeist Framework Team is requested to review the proposed merge of
lp:~mhr3/zeitgeist/mimetypes into lp:zeitgeist.
=== modified file '_zeitgeist/loggers/datasources/recent.py'
--- _zeitgeist/loggers/datasources/recent.py 2010-04-29 11:33:01 +
+++ _zeitgeist/loggers/datasources/recent.py 2010-05-27 19:34:36 +
@@ -24,8 +24,6 @@
from __future__ import with_statement
import os
-import re
-import fnmatch
import urllib
import time
import logging
@@ -34,6 +32,7 @@
from zeitgeist import _config
from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \
DataSource, get_timestamp_for_now
+from zeitgeist.mimetypes import get_interpretation_for_mimetype
from _zeitgeist.loggers.zeitgeist_base import DataProvider
log = logging.getLogger(zeitgeist.logger.datasources.recent)
@@ -51,166 +50,9 @@
else:
enabled = True
-class SimpleMatch(object):
- Wrapper around fnmatch.fnmatch which allows to define mimetype
- patterns by using shell-style wildcards.
-
-
- def __init__(self, pattern):
- self.__pattern = pattern
-
- def match(self, text):
- return fnmatch.fnmatch(text, self.__pattern)
-
- def __repr__(self):
- return %s(%r) %(self.__class__.__name__, self.__pattern)
-
-DOCUMENT_MIMETYPES = [
- # Covers:
- # vnd.corel-draw
- # vnd.ms-powerpoint
- # vnd.ms-excel
- # vnd.oasis.opendocument.*
- # vnd.stardivision.*
- # vnd.sun.xml.*
- SimpleMatch(uapplication/vnd.*),
- # Covers: x-applix-word, x-applix-spreadsheet, x-applix-presents
- SimpleMatch(uapplication/x-applix-*),
- # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
- re.compile(uapplication/x-k(word|spread|presenter|illustrator)),
- uapplication/ms-powerpoint,
- uapplication/msword,
- uapplication/pdf,
- uapplication/postscript,
- uapplication/ps,
- uapplication/rtf,
- uapplication/x-abiword,
- uapplication/x-gnucash,
- uapplication/x-gnumeric,
- SimpleMatch(uapplication/x-java*),
- SimpleMatch(u*/x-tex),
- SimpleMatch(u*/x-latex),
- SimpleMatch(u*/x-dvi),
- utext/plain
-]
-
-IMAGE_MIMETYPES = [
- # Covers:
- # vnd.corel-draw
- uapplication/vnd.corel-draw,
- # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
- re.compile(uapplication/x-k(word|spread|presenter|illustrator)),
- SimpleMatch(uimage/*),
-]
-
-AUDIO_MIMETYPES = [
- SimpleMatch(uaudio/*),
- uapplication/ogg
-]
-
-VIDEO_MIMETYPES = [
- SimpleMatch(uvideo/*),
- uapplication/ogg
-]
-
-DEVELOPMENT_MIMETYPES = [
- uapplication/ecmascript,
- uapplication/javascript,
- uapplication/x-csh,
- uapplication/x-designer,
- uapplication/x-desktop,
- uapplication/x-dia-diagram,
- uapplication/x-fluid,
- uapplication/x-glade,
- uapplication/xhtml+xml,
- uapplication/x-java-archive,
- uapplication/x-m4,
- uapplication/xml,
- uapplication/x-object,
- uapplication/x-perl,
- uapplication/x-php,
- uapplication/x-ruby,
- uapplication/x-shellscript,
- uapplication/x-sql,
- utext/css,
- utext/html,
- utext/x-c,
- utext/x-c++,
- utext/x-chdr,
- utext/x-copying,
- utext/x-credits,
- utext/x-csharp,
- utext/x-c++src,
- utext/x-csrc,
- utext/x-dsrc,
- utext/x-eiffel,
- utext/x-gettext-translation,
- utext/x-gettext-translation-template,
- utext/x-haskell,
- utext/x-idl,
- utext/x-java,
- utext/x-lisp,
- utext/x-lua,
- utext/x-makefile,
- utext/x-objcsrc,
- utext/x-ocaml,
- utext/x-pascal,
- utext/x-patch,
- utext/x-python,
- utext/x-sql,
- utext/x-tcl,
- utext/x-troff,
- utext/x-vala,
- utext/x-vhdl,
-]
-
-ALL_MIMETYPES = DOCUMENT_MIMETYPES + IMAGE_MIMETYPES + AUDIO_MIMETYPES + \
-VIDEO_MIMETYPES + DEVELOPMENT_MIMETYPES
-
-class MimeTypeSet(set):
- Set which allows to match against a string or an object with a
- match() method.
-
-
- def __init__(self, *items):
- super(MimeTypeSet, self).__init__()
- self.__pattern = set()
- for item in items:
- if isinstance(item, (str, unicode)):
-self.add(item)
- elif hasattr(item, match):
-self.__pattern.add(item)
- else:
-raise ValueError(Bad mimetype '%s' %item)
-
- def __contains__(self, mimetype):
- result = super(MimeTypeSet, self).__contains__(mimetype)
- if not result:
- for pattern in self.__pattern:
-if pattern.match(mimetype):
- return True
- return result
-
- def __len__(self):
- return super(MimeTypeSet, self).__len__() + len(self.__pattern)
-
- def __repr__(self):
- items = , .join(sorted(map(repr, self | self.__pattern)))
- return %s(%s) %(self.__class__.__name__, items)
-
class RecentlyUsedManagerGtk(DataProvider):
- FILTERS = {
- # dict of name as key and the matching mimetypes as value
- # if the value is None this filter matches all mimetypes
- DOCUMENT: MimeTypeSet(*DOCUMENT_MIMETYPES),
- IMAGE: MimeTypeSet(*IMAGE_MIMETYPES),
- MUSIC