Commit 4246a2db authored by Lucas Carvalho's avatar Lucas Carvalho

implemented the basic usage of select method.

parent e5ca9dd3
......@@ -129,6 +129,23 @@ class NetworkcacheClient(object):
raise FileNotFound(result.read())
return result
def select(self, directory_key=None):
'''Download a file from shacache by selecting the entry in shadir
Raise DirectoryNotFound if multiple files are found.
'''
path_info = self.shadir_path
if directory_key is not None
path_info = os.path.join(self.shadir_path, directory_key)
self.shadir_connection = httplib.HTTPConnection(self.shadir_host)
self.shadir_connection.request('GET', path_info, headers=self.shadir_header_dict)
result = self.shadir_connection.getresponse()
if result.status != 200:
raise DirectoryNotFound(result.read())
data = json.loads(result.read())
self.close()
return data
def close(self):
''' It must be called to close the HTTP Connection. '''
if hasattr(self, 'shacache_connection'):
......@@ -137,5 +154,10 @@ class NetworkcacheClient(object):
if hasattr(self, 'shadir_connection'):
self.shadir_connection.close()
class FileNotFound(Exception):
pass
class DirectoryNotFound(Exception):
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment