| [838] | 1 | #!/usr/bin/python | 
|---|
|  | 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 | 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 """ | 
|---|
|  | 38 | This is the pyHesiodFS FUSE automounter. To access a Hesiod filsys, | 
|---|
|  | 39 | just access /mit/name. | 
|---|
|  | 40 |  | 
|---|
|  | 41 | If you're using the Finder, try pressing Cmd+Shift+G and then entering | 
|---|
|  | 42 | /mit/name | 
|---|
|  | 43 | """ | 
|---|
|  | 44 |  | 
|---|
|  | 45 | if __name__ == '__main__': | 
|---|
|  | 46 | routefs.main(PyHesiodFS) | 
|---|