Skip to content
Snippets Groups Projects
Commit 98a2475e authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

use the http api instead of the shell.

also, make it work.
parent b25c02d3
Branches
No related tags found
1 merge request!10End-to-end with ristretto
#!/usr/bin/env python2
#!/usr/bin/env python3
from sys import argv
from os import urandom
from subprocess import check_output
from io import BytesIO
import requests
def main():
(clientDir,) = argv[1:]
someData = urandom(2 ** 16)
with mkstemp() as (fd, name):
write(fd, someData)
cap = get([
"tahoe", "-d", clientDir,
"put", name,
])
dataReadBack = get([
"tahoe", "-d", clientDir,
"get", cap,
])
api_root = get_api_root(clientDir)
cap = put(api_root, someData)
dataReadBack = get(api_root, cap)
assert someData == dataReadBack
def get(argv):
return check_output(argv)
def get_api_root(path):
with open(path + u"/node.url") as f:
return f.read().strip()
def put(api_root, data):
response = requests.put(api_root + u"uri", BytesIO(data))
response.raise_for_status()
return response.text
def get(api_root, cap):
response = requests.get(api_root + u"uri/" + cap, stream=True)
response.raise_for_status()
return response.raw.read()
if __name__ == '__main__':
if __name__ == u'__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment