First hack at a version
[invirt/packages/python-routefs.git] / routefs / examples / pyhesiodfs.py
1 #!/sw/bin/python2.5
2
3 import hesiod
4 import routefs
5 from routes import Mapper
6
7 class PyHesiodFS(routefs.RouteFS):
8     def __init__(self, *args, **kwargs):
9         super(PyHesiodFS, self).__init__(*args, **kwargs)
10         
11         self.cache = {}
12     
13     def make_map(self):
14         m = Mapper()
15         m.connect('', controller='getList')
16         m.connect(':action', controller='getLocker')
17         return m
18     
19     def getLocker(self, action):
20         if action in self.cache:
21             return routefs.Symlink(self.cache[action])
22         
23         try:
24             filsys = hesiod.FilsysLookup(action).filsys[0]
25             if filsys['type'] == 'AFS':
26                 self.cache[action] = filsys['location']
27                 return routefs.Symlink(self.cache[action])
28         except (TypeError, KeyError, IndexError):
29             return
30     
31     def getList(self, action):
32         return routefs.Directory(self.cache.keys())
33
34 if __name__ == '__main__':
35     routefs.main(PyHesiodFS)