]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/tahoe_webopen.py
891d8db0de5c18c8f99db509f0cb5ce74e27a907
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / tahoe_webopen.py
1
2 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
3                                      UnknownAliasError
4 import urllib
5
6 def webopen(options, opener=None):
7     nodeurl = options['node-url']
8     stderr = options.stderr
9     if not nodeurl.endswith("/"):
10         nodeurl += "/"
11     where = options.where
12     if where:
13         try:
14             rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
15         except UnknownAliasError, e:
16             print >>stderr, "error: %s" % e.args[0]
17             return 1
18         if path == '/':
19             path = ''
20         url = nodeurl + "uri/%s" % urllib.quote(rootcap)
21         if path:
22             url += "/" + escape_path(path)
23     else:
24         url = nodeurl
25     if options['info']:
26         url += "?t=info"
27     if not opener:
28         import webbrowser
29         opener = webbrowser.open
30     opener(url)
31     return 0
32