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, fail 
30   
31  from flumotion.common import log 
32   
33  _backends = [] 
34   
35   
36 -def listDirectory(path):
37 """List the directory called path 38 Raises L{flumotion.common.errors.NotDirectoryError} if directoryName is 39 not a directory. 40 41 @param path: the name of the directory to list 42 @type path: string 43 @returns: the directory 44 @rtype: deferred that will fire an object implementing L{IDirectory} 45 """ 46 global _backends 47 if not _backends: 48 _registerBackends() 49 if not _backends: 50 raise AssertionError( 51 "there are no vfs backends available") 52 backend = _backends[0] 53 log.info('vfs', 'listing directory %s using %r' % (path, backend)) 54 try: 55 directory = backend(path) 56 directory.cacheFiles() 57 return succeed(directory) 58 except Exception, e: 59 return fail(e)
60 61
62 -def _registerBackends():
63 global _backends 64 for backend, attributeName in [ 65 ('flumotion.common.vfsgio', 'GIODirectory'), 66 ('flumotion.common.vfsgnome', 'GnomeVFSDirectory'), 67 ]: 68 try: 69 module = __import__(backend, {}, {}, ' ') 70 except ImportError: 71 log.info('vfs', 'skipping backend %s, dependency missing' % ( 72 backend, )) 73 continue 74 75 log.info('vfs', 'adding backend %s' % (backend, )) 76 backend = getattr(module, attributeName) 77 try: 78 backend('/') 79 except ImportError: 80 continue 81 _backends.append(backend) 82 83 registerVFSJelly()
84 85
86 -def registerVFSJelly():
87 """Register the jelly used by different backends 88 """ 89 90 from flumotion.common.vfsgnome import registerGnomeVFSJelly 91 registerGnomeVFSJelly() 92 93 from flumotion.common.vfsgio import registerGIOJelly 94 registerGIOJelly() 95 96 log.info('jelly', 'VFS registered')
97