From d7df045134667c6e8d1d669236c4f10bc1e2d743 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sun, 9 Jul 2006 12:32:00 -0800 Subject: [PATCH] add function to register files that should be ignore... make this the first function called in the chain, this mean no more anoying 'no mime-type for: media/.DS_Store' messages... should we just ignore dot files? [git-p4: depot-paths = "//depot/": change = 865] --- FSStorage.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/FSStorage.py b/FSStorage.py index 24962eb..8e781b4 100644 --- a/FSStorage.py +++ b/FSStorage.py @@ -19,17 +19,31 @@ from twisted.python import log from twisted.internet import abstract, interfaces, process, protocol, reactor from zope.interface import implements -__all__ = [ 'registerklassfun', 'FSObject', 'FSItem', 'FSVideoItem', - 'FSAudioItem', 'FSTextItem', 'FSImageItem', 'mimetoklass', - 'FSDirectory', +__all__ = [ 'registerklassfun', 'registerfiletoignore', + 'FSObject', 'FSItem', 'FSDirectory', + 'FSVideoItem', 'FSAudioItem', 'FSTextItem', 'FSImageItem', + 'mimetoklass', ] mimedict = static.loadMimeTypes() -klassfuns = [] +_klassfuns = [] def registerklassfun(fun): - klassfuns.append(fun) + _klassfuns.append(fun) + +_filestoignore = { + '.DS_Store': None + } + +def registerfiletoignore(f): + _filestoignore[f] = None + +# Return this class when you want the file to be skipped. If you return this, +# no other modules will be applied, and it won't be added. Useful for things +# like .DS_Store which are known to useless on a media server. +class IgnoreFile: + pass def statcmp(a, b, cmpattrs = [ 'st_ino', 'st_dev', 'st_size', 'st_mtime', ]): if a is None or b is None: @@ -184,6 +198,12 @@ class FSItem(FSObject, Item): self.res.append(Resource(self.url + '/xvid', 'http-get:*:%s:*' % 'video/avi')) Item.doUpdate(self) +def ignoreFiles(path, fobj): + if os.path.basename(path) in _filestoignore: + return IgnoreFile, None + + return None, None + def defFS(path, fobj): if os.path.isdir(path): # new dir @@ -206,7 +226,7 @@ def dofileadd(cd, parent, path, name): fobj = open(fsname) except: fobj = None - for i in itertools.chain(klassfuns, ( defFS, )): + for i in itertools.chain(( ignoreFiles, ), _klassfuns, ( defFS, )): try: try: fobj.seek(0) # incase the call expects a clean file @@ -222,7 +242,7 @@ def dofileadd(cd, parent, path, name): #traceback.print_exc(file=log.logfile) pass - if klass is None: + if klass is None or klass is IgnoreFile: return #log.msg('matched:', os.path.join(path, name), `i`, `klass`)