Package flumotion :: Package common :: Module vfs
[hide private]

Source Code for Module flumotion.common.vfs

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  """Virtual File System API. 
19  This module contains the API used to invoke the virtual file system. 
20  The virtual file system is a simple way of listing files, directories 
21  and their metadata. 
22  It's designed to be used over twisted.spread and is thus using deferreds. 
23  """ 
24   
25  from twisted.internet.defer import succeed, fail 
26   
27  from flumotion.common import log 
28   
29  _backends = [] 
30   
31   
32 -def listDirectory(path):
33 """List the directory called path 34 Raises L{flumotion.common.errors.NotDirectoryError} if directoryName is 35 not a directory. 36 37 @param path: the name of the directory to list 38 @type path: string 39 @returns: the directory 40 @rtype: deferred that will fire an object implementing L{IDirectory} 41 """ 42 global _backends 43 if not _backends: 44 _registerBackends() 45 if not _backends: 46 raise AssertionError( 47 "there are no vfs backends available") 48 backend = _backends[0] 49 log.info('vfs', 'listing directory %s using %r' % (path, backend)) 50 try: 51 directory = backend(path) 52 directory.cacheFiles() 53 return succeed(directory) 54 except Exception, e: 55 return fail(e)
56 57
58 -def _registerBackends():
59 global _backends 60 for backend, attributeName in [ 61 ('flumotion.common.vfsgio', 'GIODirectory'), 62 ('flumotion.common.vfsgnome', 'GnomeVFSDirectory'), 63 ]: 64 try: 65 module = __import__(backend, {}, {}, ' ') 66 except ImportError: 67 log.info('vfs', 'skipping backend %s, dependency missing' % ( 68 backend, )) 69 continue 70 71 log.info('vfs', 'adding backend %s' % (backend, )) 72 backend = getattr(module, attributeName) 73 try: 74 backend('/') 75 except ImportError: 76 continue 77 _backends.append(backend) 78 79 registerVFSJelly()
80 81
82 -def registerVFSJelly():
83 """Register the jelly used by different backends 84 """ 85 86 from flumotion.common.vfsgnome import registerGnomeVFSJelly 87 registerGnomeVFSJelly() 88 89 from flumotion.common.vfsgio import registerGIOJelly 90 registerGIOJelly() 91 92 log.info('jelly', 'VFS registered')
93