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
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._filename)
57 gFileInfo = gFile.query_info('standard::icon')
58 gIcon = gFileInfo.get_icon()
59 return gIcon.get_names()
60
61
62
64 return os.path.join(self.parent.get_path(), self.name)
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
79
81 gFileInfo = gFile.query_info('standard::icon')
82 gIcon = gFileInfo.get_icon()
83 return gIcon.get_names()
84
85
86
87
90
91
92
94 import gio
95 log.info('vfsgio', 'getting files for %s' % (self.path,))
96 retval = []
97 gfile = gio.File(os.path.abspath(self.path))
98 try:
99 gfiles = gfile.enumerate_children('standard::*')
100 except gobject.GError, e:
101 if (e.domain == gio.ERROR and
102 e.code == gio.ERROR_PERMISSION_DENIED):
103 raise AccessDeniedError
104 raise
105 for gfile in gfiles:
106 filename = gfile.get_basename()
107 if filename.startswith('.') and filename != '..':
108 continue
109 if gfile.get_file_type() == gio.FILE_TYPE_DIRECTORY:
110 obj = GIODirectory(os.path.join(self.path, gfile.name))
111 else:
112 obj = GIOFile(self.path, gfile)
113 retval.append(obj)
114 log.info('vfsgio', 'returning %r' % (retval,))
115 return succeed(retval)
116
117
124