@@ -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`)