source: trunk/packages/python-routefs/routefs/examples/pyhesiodfs.py @ 2155

Last change on this file since 2155 was 981, checked in by broder, 16 years ago

Import RouteFS for new versions of ConsoleFS and RemconfFS

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/python
2
3import hesiod
4import routefs
5from routes import Mapper
6
7class PyHesiodFS(routefs.RouteFS):
8    def __init__(self, *args, **kwargs):
9        super(PyHesiodFS, self).__init__(*args, **kwargs)
10        self.fuse_args.add("allow_other", True)
11       
12        self.cache = {}
13   
14    def make_map(self):
15        m = Mapper()
16        m.connect('', controller='getList')
17        m.connect('README.txt', controller='getReadme')
18        m.connect(':action', controller='getLocker')
19        return m
20   
21    def getLocker(self, action, **kwargs):
22        if action in self.cache:
23            return routefs.Symlink(self.cache[action])
24       
25        try:
26            filsys = hesiod.FilsysLookup(action).filsys[0]
27            if filsys['type'] == 'AFS':
28                self.cache[action] = filsys['location']
29                return routefs.Symlink(self.cache[action])
30        except (TypeError, KeyError, IndexError):
31            return
32   
33    def getList(self, **kwargs):
34        return self.cache.keys() + ['README.txt']
35   
36    def getReadme(self, **kwargs):
37        return """
38This is the pyHesiodFS FUSE automounter. To access a Hesiod filsys,
39just access /mit/name.
40
41If you're using the Finder, try pressing Cmd+Shift+G and then entering
42/mit/name
43"""
44
45if __name__ == '__main__':
46    routefs.main(PyHesiodFS)
Note: See TracBrowser for help on using the repository browser.