2008-06-18 13:19:40 -07:00
|
|
|
|
2010-02-10 18:43:18 -08:00
|
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
|
|
|
UnknownAliasError
|
2008-09-24 08:20:02 -07:00
|
|
|
import urllib
|
2008-06-18 13:19:40 -07:00
|
|
|
|
2008-09-24 08:20:02 -07:00
|
|
|
def webopen(options, opener=None):
|
|
|
|
nodeurl = options['node-url']
|
2010-02-10 18:43:18 -08:00
|
|
|
stderr = options.stderr
|
2008-06-18 13:19:40 -07:00
|
|
|
if not nodeurl.endswith("/"):
|
|
|
|
nodeurl += "/"
|
2008-09-24 08:20:02 -07:00
|
|
|
where = options.where
|
2009-07-01 13:05:48 -07:00
|
|
|
if where:
|
2010-02-10 18:43:18 -08:00
|
|
|
try:
|
|
|
|
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
|
|
|
|
except UnknownAliasError, e:
|
2010-06-06 18:02:15 -07:00
|
|
|
e.display(stderr)
|
2010-02-10 18:43:18 -08:00
|
|
|
return 1
|
2009-07-01 13:05:48 -07:00
|
|
|
if path == '/':
|
|
|
|
path = ''
|
|
|
|
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
|
|
|
|
if path:
|
|
|
|
url += "/" + escape_path(path)
|
|
|
|
else:
|
|
|
|
url = nodeurl
|
2010-04-24 16:30:03 -07:00
|
|
|
if options['info']:
|
|
|
|
url += "?t=info"
|
2008-09-24 08:20:02 -07:00
|
|
|
if not opener:
|
|
|
|
import webbrowser
|
|
|
|
opener = webbrowser.open
|
|
|
|
opener(url)
|
2008-06-18 13:19:40 -07:00
|
|
|
return 0
|
|
|
|
|