fuse/impl_{a,b}: improve node-url handling

specifically change the expectation of the code to be such that the node-url
(self.url) always includes the trailing slash to be a correctly formed url

moreover read the node-url from the 'node.url' file found in the node 'basedir'
and only if that doesn't exist, then fall back to reading the 'webport' file
from therein and assuming localhost.  This then supports the general tahoe 
pattern that tools needing only a webapi server can be pointed at a directory
containing the node.url file, which can optionally point to another server,
rather than requiring a complete node dir and locally running node instance.
This commit is contained in:
robk-tahoe 2008-09-24 11:28:54 -07:00
parent 97229238b0
commit 4f04bf99a5
2 changed files with 30 additions and 20 deletions

View File

@ -162,15 +162,19 @@ class TahoeFS (fuse.Fuse):
self._init_rootdir()
def _init_url(self):
f = open(os.path.join(self.confdir, 'webport'), 'r')
contents = f.read()
f.close()
fields = contents.split(':')
proto, port = fields[:2]
assert proto == 'tcp'
port = int(port)
self.url = 'http://localhost:%d' % (port,)
if os.path.exists(os.path.join(self.confdir, 'node.url')):
self.url = file(os.path.join(self.confdir, 'node.url'), 'rb').read().strip()
if not self.url.endswith('/'):
self.url += '/'
else:
f = open(os.path.join(self.confdir, 'webport'), 'r')
contents = f.read()
f.close()
fields = contents.split(':')
proto, port = fields[:2]
assert proto == 'tcp'
port = int(port)
self.url = 'http://localhost:%d' % (port,)
def _init_rootdir(self):
# For now we just use the same default as the CLI:
@ -334,9 +338,11 @@ class TahoeNode (object):
return TahoeFile(baseurl, uri)
def __init__(self, baseurl, uri):
if not baseurl.endswith('/'):
baseurl += '/'
self.burl = baseurl
self.uri = uri
self.fullurl = '%s/uri/%s' % (self.burl, self.uri)
self.fullurl = '%suri/%s' % (self.burl, self.uri)
self.inode = TahoeNode.NextInode
TahoeNode.NextInode += 1

View File

@ -30,15 +30,19 @@ class TahoeConnection:
self._init_url()
def _init_url(self):
f = open(os.path.join(self.confdir, 'webport'), 'r')
contents = f.read()
f.close()
fields = contents.split(':')
proto, port = fields[:2]
assert proto == 'tcp'
port = int(port)
self.url = 'http://localhost:%d' % (port,)
if os.path.exists(os.path.join(self.confdir, 'node.url')):
self.url = file(os.path.join(self.confdir, 'node.url'), 'rb').read().strip()
if not self.url.endswith('/'):
self.url += '/'
else:
f = open(os.path.join(self.confdir, 'webport'), 'r')
contents = f.read()
f.close()
fields = contents.split(':')
proto, port = fields[:2]
assert proto == 'tcp'
port = int(port)
self.url = 'http://localhost:%d/' % (port,)
def get_root(self):
# For now we just use the same default as the CLI:
@ -61,7 +65,7 @@ class TahoeNode:
return simplejson.loads(json)
def _open(self, postfix=''):
url = '%s/uri/%s%s' % (self.conn.url, self.uri, postfix)
url = '%suri/%s%s' % (self.conn.url, self.uri, postfix)
log('*** Fetching: %r', url)
return urllib.urlopen(url)