libdo

Untitled

Oct 27th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/flumotion/component/misc/httpserver/ourmimetypes.py b/flumotion/component/misc/httpserver/ourmimetypes.py
  2. index 4f67db8..7e240cd 100644
  3. --- a/flumotion/component/misc/httpserver/ourmimetypes.py
  4. +++ b/flumotion/component/misc/httpserver/ourmimetypes.py
  5. @@ -22,6 +22,12 @@
  6.  import os
  7.  
  8.  from twisted.web import static
  9. +from twisted.internet import inotify
  10. +from twisted.python import filepath
  11. +
  12. +from flumotion.common import log
  13. +
  14. +MIMETYPE_LOCATIONS = ['/etc/mime.types']
  15.  
  16.  
  17.  class MimeTypes(object):
  18. @@ -29,7 +35,7 @@ class MimeTypes(object):
  19.      @staticmethod
  20.      def loadMimeTypes():
  21.          # Add our own mime types to the ones parsed from /etc/mime.types
  22. -        d = static.loadMimeTypes()
  23. +        d = static.loadMimeTypes(MIMETYPE_LOCATIONS)
  24.          d['.flv'] = 'video/x-flv'
  25.          d['.mp4'] = 'video/mp4'
  26.          d['.webm'] = 'video/webm'
  27. @@ -37,7 +43,16 @@ class MimeTypes(object):
  28.  
  29.      def __init__(self):
  30.          self._mimetypes = self.loadMimeTypes()
  31. +        self.notifier = inotify.INotify()
  32. +        self.notifier.startReading()
  33. +        for loc in MIMETYPE_LOCATIONS:
  34. +            self.notifier.watch(filepath.FilePath(loc), mask=inotify.IN_MODIFY,
  35. +                                callbacks=[self.notify])
  36.  
  37.      def fromPath(self, path, default=None):
  38.          ext = os.path.splitext(path)[1]
  39.          return self._mimetypes.get(ext.lower(), default)
  40. +
  41. +    def notify(self, ignored, filepath, mask):
  42. +        log.debug('mimetypes', 'Mime type file changed %s' % filepath)
  43. +        self._mimetypes = self.loadMimeTypes()
Add Comment
Please, Sign In to add comment