Use requests library for the initial WAPI connection.

master
Sven Slootweg 12 years ago
parent 490641cab6
commit b58bdd5b07

@ -1,4 +1,4 @@
import urllib, urllib2, json, time, os, re, requests import json, time, os, re, requests
try: try:
from fs.contrib.tahoelafs import TahoeLAFS from fs.contrib.tahoelafs import TahoeLAFS
@ -35,17 +35,12 @@ class Filesystem:
url = url[:-1] url = url[:-1]
try: try:
result = urllib.urlopen("%s/statistics?t=json" % url).read() data = requests.get("%s/statistics?t=json" % url).json
except urllib.URLError: except requests.exceptions.RequestException:
raise FilesystemException("The provided WAPI URL is not reachable.") raise FilesystemException("The provided WAPI URL is either not reachable, or not running a recent version of Tahoe-LAFS.")
try:
data = json.loads(result)
except ValueError:
raise FilesystemException("The provided WAPI URL is either not running Tahoe-LAFS, or running a version that is too old.")
if "node.uptime" not in data['stats']: if data is None:
raise FilesystemException("The provided WAPI URL is either not running Tahoe-LAFS, or running a version that is too old.") raise FilesystemException("The provided URL is not running a recent version of Tahoe-LAFS.")
self.url = url self.url = url
self.start_date = time.time() - data['stats']['node.uptime'] self.start_date = time.time() - data['stats']['node.uptime']

@ -1,10 +1,11 @@
import pytahoe import pytahoe
fs = pytahoe.Filesystem("http://localhost:3456/") fs = pytahoe.Filesystem("http://localhost:3456/")
print fs
#tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa") #tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa")
#print tdir #print tdir
#for name, item in tdir.children.iteritems(): #for name, item in tdir.children.iteritems():
# print "%s: %s" % (name, item) # print "%s: %s" % (name, item)
#print fs.create_directory().mount("test") #print fs.create_directory().mount("test")
print fs.upload("test.py") #print fs.upload("test.py")

Loading…
Cancel
Save