6 fuse.fuse_python_api = (0, 2)
8 class RouteStat(fuse.Stat):
21 class RouteMeta(type):
22 def __init__(cls, classname, bases, dict_):
23 super(RouteMeta, cls).__init__(classname, bases, dict_)
24 if bases != (fuse.Fuse,):
25 new_funcs = set(dict_.keys()).difference(dir(RouteFS))
26 cls.controllers([func for func in new_funcs \
27 if not func.startswith('_')])
29 class RouteFS(fuse.Fuse):
30 __metaclass__ = RouteMeta
31 def __init__(self, *args, **kwargs):
32 super(RouteFS, self).__init__(*args, **kwargs)
34 self.map = self.make_map()
35 self.map.create_regs(self.controller_list)
40 m.connect(':controller')
45 def controllers(cls, lst):
46 cls.controller_list = lst
48 def _get_file(self, path):
49 match = self.map.match(path)
52 controller = match.pop('controller')
53 result = getattr(self, controller)(**match)
56 def readdir(self, path, offset):
57 obj = self._get_file(path)
58 if type(obj) is not Directory:
61 for member in ['.', '..'] + obj:
62 yield fuse.Direntry(str(member))
64 def getattr(self, path):
65 obj = self._get_file(path)
70 if type(obj) is Directory:
71 st.st_mode = stat.S_IFDIR | 0755
73 elif type(obj) is Symlink:
74 st.st_mode = stat.S_IFLNK | 0777
78 st.st_mode = stat.S_IFREG | 0444
84 def read(self, path, length, offset):
85 obj = self._get_file(path)
88 elif type(obj) in (Directory, Symlink):
91 return obj[offset:offset + length]
93 def readlink(self, path):
94 obj = self._get_file(path)
95 if type(obj) is not Symlink:
100 class Directory(list):
102 A dummy class representing a filesystem entry that should be a
109 A dummy class representing something that should be a symlink
114 server = cls(version="%prog " + fuse.__version__,
115 usage=fuse.Fuse.fusage,
116 dash_s_do='setsingle')
117 server.parse(errex=1)