1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
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
97