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