diff --git a/pytahoe/__init__.py b/pytahoe/__init__.py index 29a6083..90127aa 100644 --- a/pytahoe/__init__.py +++ b/pytahoe/__init__.py @@ -54,13 +54,12 @@ class Filesystem: url = url[:-1] try: - data = requests.get("%s/statistics?t=json" % url).json + data = requests.get("%s/statistics?t=json" % url).json() except requests.exceptions.RequestException: raise FilesystemException("The provided WAPI URL is either not reachable, or not running a recent version of Tahoe-LAFS.") - - if data is None: + except: raise FilesystemException("The provided URL is not running a recent version of Tahoe-LAFS.") - + self.url = url self.start_date = time.time() - data['stats']['node.uptime'] @@ -77,9 +76,9 @@ class Filesystem: """ if data is None: - data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json - - if data is None: + try: + data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json() + except: raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") return Directory(self, uri, data) @@ -94,9 +93,9 @@ class Filesystem: """ if data is None: - data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json - - if data is None: + try: + data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json() + except: raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") return File(self, uri, data) @@ -111,9 +110,9 @@ class Filesystem: """ if data is None: - data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json - - if data is None: + try: + data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json() + except: raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") if "filenode" in data: @@ -232,9 +231,9 @@ class Directory: def _get_data(self): """Actually retrieves the data for this Directory.""" - data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(self.uri))).json - - if data is None: + try: + data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(self.uri))).json() + except: raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") if "dirnode" in data: @@ -367,9 +366,9 @@ class File: self.uri = uri if data is None: - data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(uri))).json - - if data is None: + try: + data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(uri))).json() + except: raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") if "filenode" in data: diff --git a/test.py b/test.py index 146fd20..01e0336 100644 --- a/test.py +++ b/test.py @@ -1,7 +1,8 @@ import pytahoe -#fs = pytahoe.Filesystem("http://localhost:3456/") +fs = pytahoe.Filesystem("http://localhost:3456/") +print "Get filesystem" #print fs #tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa") #print tdir @@ -16,7 +17,7 @@ import pytahoe #print tdir.attach(fs.File("URI:CHK:j3jkuy73tnkj7glyatasluq2xe:hcluqizbrhdpqa7fugmiwtaxf42f2ssvk7emyyat7wm4xr3ehgfa:3:10:534"), "derp.py") #print tdir.attach(fs.File("URI:CHK:j3jkuy73tnkj7glyatasluq2xe:hcluqizbrhdpqa7fugmiwtaxf42f2ssvk7emyyat7wm4xr3ehgfa:3:10:534"), "This is just a (*@Y#%)()@#&%)(*@&#% test to see how well it sanitizes a filename..py") -fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/") +#fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/") #tfile = fs.File("URI:CHK:iyq5houj2fqavmnqccqezcssle:5px5tdctmmvci4al2r3vskpblhrepuugfe6ghiuutpe6cllvo36a:3:10:997") #print tfile.read(65) @@ -26,11 +27,14 @@ fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/") #tfile = fs.upload("test.py") #print tfile # -tdir = fs.Directory("URI:DIR2:cbk47f5lybaj5qh6bm6eedezwe:m525plntx47u44xvf44r6rliec3gp6yeyio7olndibtke75zb6fa") - +tdir = fs.Directory("URI:DIR2:73a5pbgk2wpgtjylw4x6d3p4ne:ygfn7uzmpyzrat7u2yigalhqlf77xq5uavc3fvaphsnlncoy5hnq") +print "Get dir" print tdir.create_directory("testing subdir4") +print "Create dir" tdir.refresh() +print "Refresh" print tdir.children +print "Children" #print tdir.upload("test.py") #print tdir