1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """GIO backend for Virtual File System.
19 """
20
21 import os
22
23 import gobject
24 from twisted.internet.defer import succeed
25 from twisted.spread.flavors import Copyable, RemoteCopy
26 from twisted.spread.jelly import setUnjellyableForClass
27 from zope.interface import implements
28
29 from flumotion.common import log
30 from flumotion.common.errors import AccessDeniedError, NotDirectoryError
31 from flumotion.common.interfaces import IDirectory, IFile
32
33
34
35
36 __pychecker__ = 'keepgoing'
37
38
39 -class GIOFile(Copyable, RemoteCopy):
40 """I am object implementing L{IFile} on top of GIO,
41 see L{IFile} for more information.
42 """
43 implements(IFile)
44
49
51 import gio
52 gFile = gio.File(self.getPath())
53 gFileInfo = gFile.query_info('standard::icon')
54 gIcon = gFileInfo.get_icon()
55 return gIcon.get_names()
56
57
58
61
62
64 """I am object implementing L{IDirectory} on top of GIO,
65 see L{IDirectory} for more information.
66 """
67 implements(IDirectory)
68
83
85 gFileInfo = gFile.query_info('standard::icon')
86 gIcon = gFileInfo.get_icon()
87 return gIcon.get_names()
88
89
90
93
94
95
97 return succeed(self._cachedFiles)
98
100 """
101 Fetches the files contained on the directory for posterior usage of
102 them. This should be called on the worker side to work or the files
103 wouldn't be the expected ones.
104 """
105 import gio
106 log.debug('vfsgio', 'getting files for %s' % (self.path, ))
107 retval = []
108 gfile = gio.File(os.path.abspath(self.path))
109 try:
110 gfileinfos = gfile.enumerate_children('standard::*')
111 except gobject.GError, e:
112 if (e.domain == gio.ERROR and
113 e.code == gio.ERROR_PERMISSION_DENIED):
114 raise AccessDeniedError
115 raise
116 if self.path != '/':
117 retval.append(GIODirectory(os.path.dirname(self.path), name='..'))
118 for gfileinfo in gfileinfos:
119 filename = gfileinfo.get_name()
120 if filename.startswith('.') and filename != '..':
121 continue
122 if gfileinfo.get_file_type() == gio.FILE_TYPE_DIRECTORY:
123 obj = GIODirectory(os.path.join(self.path,
124 gfileinfo.get_name()))
125 else:
126 obj = GIOFile(self.path, gfileinfo)
127 retval.append(obj)
128 log.log('vfsgio', 'returning %r' % (retval, ))
129 self._cachedFiles = retval
130
131
138