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.getPath())
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, self.filename)
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
74 import gio
75 if not os.path.exists(path):
76 self.path = '/'
77 else:
78 self.path = os.path.abspath(path)
79
80 gfile = gio.File(self.path)
81 if name is None:
82 name = gfile.get_basename()
83 self.filename = name
84 self.iconNames = self._getIconNames(gfile)
85
87 gFileInfo = gFile.query_info('standard::icon')
88 gIcon = gFileInfo.get_icon()
89 return gIcon.get_names()
90
91
92
95
96
97
99 return succeed(self._cachedFiles)
100
102 """
103 Fetches the files contained on the directory for posterior usage of
104 them. This should be called on the worker side to work or the files
105 wouldn't be the expected ones.
106 """
107 import gio
108 log.debug('vfsgio', 'getting files for %s' % (self.path, ))
109 retval = []
110 gfile = gio.File(os.path.abspath(self.path))
111 try:
112 gfileinfos = gfile.enumerate_children('standard::*')
113 except gobject.GError, e:
114 if (e.domain == gio.ERROR and
115 e.code == gio.ERROR_PERMISSION_DENIED):
116 raise AccessDeniedError
117 raise
118 if self.path != '/':
119 retval.append(GIODirectory(os.path.dirname(self.path), name='..'))
120 for gfileinfo in gfileinfos:
121 filename = gfileinfo.get_name()
122 if filename.startswith('.') and filename != '..':
123 continue
124 if gfileinfo.get_file_type() == gio.FILE_TYPE_DIRECTORY:
125 obj = GIODirectory(os.path.join(self.path,
126 gfileinfo.get_name()))
127 else:
128 obj = GIOFile(self.path, gfileinfo)
129 retval.append(obj)
130 log.log('vfsgio', 'returning %r' % (retval, ))
131 self._cachedFiles = retval
132
133
140