Add subcommand 'list' to the client
Change-Id: Ie15881e530a888d1844f1258779d61b4e1a3ec46
This commit is contained in:
parent
aa89e45df6
commit
47f2fbab8e
27
bin/faafo
27
bin/faafo
|
@ -117,7 +117,32 @@ def do_show_fractal():
|
|||
|
||||
|
||||
def do_list_fractals():
|
||||
LOG.error("command 'list' not yet implemented")
|
||||
LOG.info("listing all fractals")
|
||||
|
||||
fractals = get_fractals()
|
||||
output = PrettyTable(["UUID", "Dimensions", "Filesize"])
|
||||
for fractal in fractals:
|
||||
output.add_row([
|
||||
fractal["uuid"],
|
||||
"%d x %d pixels" % (fractal["width"], fractal["height"]),
|
||||
"%d bytes" % (fractal["size"] or 0),
|
||||
])
|
||||
print(output)
|
||||
|
||||
|
||||
def get_fractals(page=1):
|
||||
result = requests.get("%s/v1/fractal?page=%d" %
|
||||
(CONF.endpoint_url, page))
|
||||
|
||||
fractals = []
|
||||
if result.status_code == 200:
|
||||
data = json.loads(result.text)
|
||||
if page < data['total_pages']:
|
||||
fractals = data['objects'] + get_fractals(page + 1)
|
||||
else:
|
||||
return data['objects']
|
||||
|
||||
return fractals
|
||||
|
||||
|
||||
def do_delete_fractal():
|
||||
|
|
|
@ -129,6 +129,7 @@ def generate_fractal(**kwargs):
|
|||
def main():
|
||||
manager.create_api(Fractal, methods=['GET', 'POST', 'DELETE', 'PUT'],
|
||||
postprocessors={'POST': [generate_fractal]},
|
||||
exclude_columns=['image'],
|
||||
url_prefix='/v1')
|
||||
app.run(host=CONF.listen_address, port=CONF.bind_port)
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ class WorkerEndpoint(object):
|
|||
image = base64.b64encode(fp.read())
|
||||
checksum = hashlib.sha256(open(filename, 'rb').read()).hexdigest()
|
||||
os.remove(filename)
|
||||
LOG.debug("removed temporary file %s" % task['uuid'], filename)
|
||||
LOG.debug("removed temporary file %s" % filename)
|
||||
|
||||
result = {
|
||||
'uuid': task['uuid'],
|
||||
|
|
Loading…
Reference in New Issue