2 PyFuse client for the Tahoe distributed file system.
3 See http://allmydata.org/
8 # Portions copied from the file contrib/fuse/tahoe_fuse.py distributed
12 from objectfs import ObjectFs
13 from handler import Handler
19 TahoeConfigDir = '~/.tahoe'
22 ### Utilities for debug:
27 class TahoeConnection:
28 def __init__(self, confdir):
29 self.confdir = confdir
33 if os.path.exists(os.path.join(self.confdir, 'node.url')):
34 self.url = file(os.path.join(self.confdir, 'node.url'), 'rb').read().strip()
35 if not self.url.endswith('/'):
38 f = open(os.path.join(self.confdir, 'webport'), 'r')
41 fields = contents.split(':')
42 proto, port = fields[:2]
45 self.url = 'http://localhost:%d/' % (port,)
48 # For now we just use the same default as the CLI:
49 rootdirfn = os.path.join(self.confdir, 'private', 'root_dir.cap')
50 f = open(rootdirfn, 'r')
51 cap = f.read().strip()
53 return TahoeDir(self, canonicalize_cap(cap))
57 def __init__(self, conn, uri):
61 def get_metadata(self):
62 f = self._open('?t=json')
65 return simplejson.loads(json)
67 def _open(self, postfix=''):
68 url = '%suri/%s%s' % (self.conn.url, self.uri, postfix)
69 log('*** Fetching: %r', url)
70 return urllib.urlopen(url)
73 class TahoeDir(TahoeNode):
75 flag, md = self.get_metadata()
76 assert flag == 'dirnode'
78 for name, (childflag, childmd) in md['children'].items():
79 if childflag == 'dirnode':
83 result.append((str(name), cls(self.conn, childmd['ro_uri'])))
86 class TahoeFile(TahoeNode):
88 rawsize = self.get_metadata()[1]['size']
92 return self._open().read()
95 def canonicalize_cap(cap):
96 cap = urllib.unquote(cap)
98 assert i != -1, 'A cap must contain "URI:...", but this does not: ' + cap
101 def main(mountpoint, basedir):
102 conn = TahoeConnection(basedir)
103 root = conn.get_root()
104 handler = Handler(mountpoint, ObjectFs(root))
105 handler.loop_forever()
107 if __name__ == '__main__':
108 basedir = os.path.expanduser(TahoeConfigDir)
109 for i, arg in enumerate(sys.argv):
110 if arg == '--basedir':
111 basedir = sys.argv[i+1]
114 [mountpoint] = sys.argv[1:]
115 main(mountpoint, basedir)