Browse Source

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]
v0.3
John-Mark Gurney 19 years ago
parent
commit
d7df045134
1 changed files with 27 additions and 7 deletions
  1. +27
    -7
      FSStorage.py

+ 27
- 7
FSStorage.py View File

@@ -19,17 +19,31 @@ from twisted.python import log
from twisted.internet import abstract, interfaces, process, protocol, reactor from twisted.internet import abstract, interfaces, process, protocol, reactor
from zope.interface import implements from zope.interface import implements


__all__ = [ 'registerklassfun', 'FSObject', 'FSItem', 'FSVideoItem', __all__ = [ 'registerklassfun', 'registerfiletoignore',
'FSAudioItem', 'FSTextItem', 'FSImageItem', 'mimetoklass', 'FSObject', 'FSItem', 'FSDirectory',
'FSDirectory', 'FSVideoItem', 'FSAudioItem', 'FSTextItem', 'FSImageItem',
'mimetoklass',
] ]


mimedict = static.loadMimeTypes() mimedict = static.loadMimeTypes()


klassfuns = [] _klassfuns = []


def registerklassfun(fun): 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', ]): def statcmp(a, b, cmpattrs = [ 'st_ino', 'st_dev', 'st_size', 'st_mtime', ]):
if a is None or b is None: 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')) self.res.append(Resource(self.url + '/xvid', 'http-get:*:%s:*' % 'video/avi'))
Item.doUpdate(self) Item.doUpdate(self)


def ignoreFiles(path, fobj):
if os.path.basename(path) in _filestoignore:
return IgnoreFile, None

return None, None

def defFS(path, fobj): def defFS(path, fobj):
if os.path.isdir(path): if os.path.isdir(path):
# new dir # new dir
@@ -206,7 +226,7 @@ def dofileadd(cd, parent, path, name):
fobj = open(fsname) fobj = open(fsname)
except: except:
fobj = None fobj = None
for i in itertools.chain(klassfuns, ( defFS, )): for i in itertools.chain(( ignoreFiles, ), _klassfuns, ( defFS, )):
try: try:
try: try:
fobj.seek(0) # incase the call expects a clean file 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) #traceback.print_exc(file=log.logfile)
pass pass


if klass is None: if klass is None or klass is IgnoreFile:
return return


#log.msg('matched:', os.path.join(path, name), `i`, `klass`) #log.msg('matched:', os.path.join(path, name), `i`, `klass`)


||||||
x
 
000:0
Loading…
Cancel
Save