1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
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
93