Ejemplo n.º 1
0
 def link(self, dircap, childname, childcap):
     dircap_hash = trunchash(dircap)
     childcap_hash = trunchash(childcap)
     log.debug(
         'Linking "%s" (%s) into %s...',
         childname,
         childcap_hash,
         dircap_hash,
     )
     yield self.await_ready()
     yield self.lock.acquire()
     try:
         resp = yield treq.post("{}uri/{}/?t=uri&name={}&uri={}".format(
             self.nodeurl, dircap, childname, childcap))
     finally:
         yield self.lock.release()
     if resp.code != 200:
         content = yield treq.content(resp)
         raise TahoeWebError(content.decode("utf-8"))
     log.debug(
         'Done linking "%s" (%s) into %s',
         childname,
         childcap_hash,
         dircap_hash,
     )
Ejemplo n.º 2
0
 def unlink(self, dircap, childname):
     lock = yield self.lock.acquire()
     try:
         resp = yield treq.post('{}uri/{}/?t=unlink&name={}'.format(
             self.nodeurl, dircap, childname))
     finally:
         yield lock.release()
     if resp.code != 200:
         content = yield treq.content(resp)
         raise TahoeWebError(content.decode('utf-8'))
Ejemplo n.º 3
0
 def download(self, cap, local_path):
     log.debug("Downloading %s...", local_path)
     resp = yield treq.get('{}uri/{}'.format(self.nodeurl, cap))
     if resp.code == 200:
         with open(local_path, 'wb') as f:
             yield treq.collect(resp, f.write)
         log.debug("Successfully downloaded %s", local_path)
     else:
         content = yield treq.content(resp)
         raise TahoeWebError(content.decode('utf-8'))
Ejemplo n.º 4
0
 def upload(self, local_path):
     log.debug("Uploading %s...", local_path)
     with open(local_path, 'rb') as f:
         resp = yield treq.put('{}uri'.format(self.nodeurl), f)
     if resp.code == 200:
         content = yield treq.content(resp)
         log.debug("Successfully uploaded %s", local_path)
         return content.decode('utf-8')
     content = yield treq.content(resp)
     raise TahoeWebError(content.decode('utf-8'))
Ejemplo n.º 5
0
 def download(self, cap, local_path):
     log.debug("Downloading %s...", local_path)
     yield self.await_ready()
     resp = yield treq.get("{}uri/{}".format(self.nodeurl, cap))
     if resp.code == 200:
         with atomic_write(local_path, mode="wb", overwrite=True) as f:
             yield treq.collect(resp, f.write)
         log.debug("Successfully downloaded %s", local_path)
     else:
         content = yield treq.content(resp)
         raise TahoeWebError(content.decode("utf-8"))
Ejemplo n.º 6
0
 def upload(self, local_path):
     log.debug("Uploading %s...", local_path)
     yield self.await_ready()
     with open(local_path, "rb") as f:
         resp = yield treq.put("{}uri".format(self.nodeurl), f)
     if resp.code == 200:
         content = yield treq.content(resp)
         log.debug("Successfully uploaded %s", local_path)
         return content.decode("utf-8")
     content = yield treq.content(resp)
     raise TahoeWebError(content.decode("utf-8"))
Ejemplo n.º 7
0
 def mkdir(self, parentcap=None, childname=None):
     url = self.nodeurl + 'uri'
     params = {'t': 'mkdir'}
     if parentcap and childname:
         url += '/' + parentcap
         params['name'] = childname
     resp = yield treq.post(url, params=params)
     if resp.code == 200:
         content = yield treq.content(resp)
         return content.decode('utf-8').strip()
     raise TahoeWebError("Error creating Tahoe-LAFS directory: {}".format(
         resp.code))
Ejemplo n.º 8
0
 def mkdir(self, parentcap=None, childname=None):
     yield self.await_ready()
     url = self.nodeurl + "uri"
     params = {"t": "mkdir"}
     if parentcap and childname:
         url += "/" + parentcap
         params["name"] = childname
     resp = yield treq.post(url, params=params)
     if resp.code == 200:
         content = yield treq.content(resp)
         return content.decode("utf-8").strip()
     raise TahoeWebError("Error creating Tahoe-LAFS directory: {}".format(
         resp.code))
Ejemplo n.º 9
0
 def unlink(self, dircap, childname):
     dircap_hash = hashlib.sha256(dircap.encode()).hexdigest()
     log.debug('Unlinking "%s" from %s...', childname, dircap_hash)
     yield self.lock.acquire()
     try:
         resp = yield treq.post('{}uri/{}/?t=unlink&name={}'.format(
             self.nodeurl, dircap, childname))
     finally:
         yield self.lock.release()
     if resp.code != 200:
         content = yield treq.content(resp)
         raise TahoeWebError(content.decode('utf-8'))
     log.debug('Done unlinking "%s" from %s', childname, dircap_hash)
Ejemplo n.º 10
0
 def link(self, dircap, childname, childcap):
     dircap_hash = hashlib.sha256(dircap.encode()).hexdigest()
     childcap_hash = hashlib.sha256(childcap.encode()).hexdigest()
     log.debug('Linking "%s" (%s) into %s...', childname, childcap_hash,
               dircap_hash)
     yield self.await_ready()
     yield self.lock.acquire()
     try:
         resp = yield treq.post('{}uri/{}/?t=uri&name={}&uri={}'.format(
             self.nodeurl, dircap, childname, childcap))
     finally:
         yield self.lock.release()
     if resp.code != 200:
         content = yield treq.content(resp)
         raise TahoeWebError(content.decode('utf-8'))
     log.debug('Done linking "%s" (%s) into %s', childname, childcap_hash,
               dircap_hash)