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) 2008 Fluendo, S.L. (www.fluendo.com). 
 6  # All rights reserved. 
 7   
 8  # This file may be distributed and/or modified under the terms of 
 9  # the GNU General Public License version 2 as published by 
10  # the Free Software Foundation. 
11  # This file is distributed without any warranty; without even the implied 
12  # warranty of merchantability or fitness for a particular purpose. 
13  # See "LICENSE.GPL" in the source distribution for more information. 
14   
15  # Licensees having purchased or holding a valid Flumotion Advanced 
16  # Streaming Server license may use this file in accordance with the 
17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
18  # See "LICENSE.Flumotion" in the source distribution for more information. 
19   
20  # Headers in this file shall remain intact. 
21   
22  """Virtual File System API. 
23  This module contains the API used to invoke the virtual file system. 
24  The virtual file system is a simple way of listing files, directories 
25  and their metadata. 
26  It's designed to be used over twisted.spread and is thus using deferreds. 
27  """ 
28   
29  from twisted.internet.defer import succeed 
30   
31  from flumotion.common import log 
32   
33  _backends = [] 
34   
35 -def listDirectory(path):
36 """List the directory called path 37 @returns: the directory 38 @rtype: deferred that will fire an object implementing L{IDirectory} 39 """ 40 global _backends 41 if not _backends: 42 _registerBackends() 43 if not _backends: 44 raise AssertionError( 45 "there are no vfs backends available") 46 backend = _backends[0] 47 log.info('vfs', 'listing directory %s using %r' % (path, backend)) 48 return succeed(backend(path))
49 50
51 -def _registerBackends():
52 global _backends 53 for backend, attributeName in [ 54 ('flumotion.common.vfsgio', 'GIODirectory'), 55 ('flumotion.common.vfsgnome', 'GnomeVFSDirectory'), 56 ]: 57 try: 58 module = __import__(backend, {}, {}, ' ') 59 except ImportError: 60 log.info('vfs', 'skipping backend %s, dependency missing' % ( 61 backend,)) 62 continue 63 64 log.info('vfs', 'adding backend %s' % (backend,)) 65 backend = getattr(module, attributeName) 66 try: 67 backend('/') 68 except ImportError: 69 continue 70 _backends.append(backend) 71 72 registerVFSJelly()
73
74 -def registerVFSJelly():
75 """Register the jelly used by different backends 76 """ 77 78 from flumotion.common.vfsgnome import registerGnomeVFSJelly 79 registerGnomeVFSJelly() 80 81 from flumotion.common.vfsgio import registerGIOJelly 82 registerGIOJelly() 83 84 log.info('jelly', 'VFS registered')
85