diff --git a/flumotion/component/misc/httpserver/ourmimetypes.py b/flumotion/component/misc/httpserver/ourmimetypes.py index 4f67db8..7e240cd 100644 --- a/flumotion/component/misc/httpserver/ourmimetypes.py +++ b/flumotion/component/misc/httpserver/ourmimetypes.py @@ -22,6 +22,12 @@ import os from twisted.web import static +from twisted.internet import inotify +from twisted.python import filepath + +from flumotion.common import log + +MIMETYPE_LOCATIONS = ['/etc/mime.types'] class MimeTypes(object): @@ -29,7 +35,7 @@ class MimeTypes(object): @staticmethod def loadMimeTypes(): # Add our own mime types to the ones parsed from /etc/mime.types - d = static.loadMimeTypes() + d = static.loadMimeTypes(MIMETYPE_LOCATIONS) d['.flv'] = 'video/x-flv' d['.mp4'] = 'video/mp4' d['.webm'] = 'video/webm' @@ -37,7 +43,16 @@ class MimeTypes(object): def __init__(self): self._mimetypes = self.loadMimeTypes() + self.notifier = inotify.INotify() + self.notifier.startReading() + for loc in MIMETYPE_LOCATIONS: + self.notifier.watch(filepath.FilePath(loc), mask=inotify.IN_MODIFY, + callbacks=[self.notify]) def fromPath(self, path, default=None): ext = os.path.splitext(path)[1] return self._mimetypes.get(ext.lower(), default) + + def notify(self, ignored, filepath, mask): + log.debug('mimetypes', 'Mime type file changed %s' % filepath) + self._mimetypes = self.loadMimeTypes()