From c4bda46189d697fffd5a4493b6d01c76f628750b Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 28 Aug 2018 01:42:36 +0200 Subject: [PATCH] [enh] start to work on api listing --- cli.py | 17 +++++++++++++++-- run.py | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index 8a53d9a..d03a0c3 100644 --- a/cli.py +++ b/cli.py @@ -45,7 +45,8 @@ def request_api(path, domain, verb, data): # TODO: real error message assert response.status_code == 200, response.content - assert response.content == b"ok", response.content + + return response def add(name, url_or_path, test_type="stable", yunohost_version="unstable", debian_version="stretch", revision="master", domain=DOMAIN): @@ -65,7 +66,19 @@ def add(name, url_or_path, test_type="stable", yunohost_version="unstable", debi @named("list") -def list_(all=False, domain=DOMAIN): pass +def list_(all=False, domain=DOMAIN): + response = request_api( + path="job", + verb="get", + domain=domain, + data={ + "all": all, + }, + ) + + for i in response.json(): + print(f"{i['id']:4d} - {i['name']}") + def delete(job_id, domain=DOMAIN): pass def update(job_id, domain=DOMAIN): pass def cancel(job_id, domain=DOMAIN): pass diff --git a/run.py b/run.py index 7652ad9..d32359e 100644 --- a/run.py +++ b/run.py @@ -384,6 +384,17 @@ async def api_new_job(request): return response.text("ok") +@app.route("/api/job", methods=['GET']) +@require_token() +async def api_list_job(request): + query = Job.select() + + if not all: + query.where(Job.state in ('scheduled', 'running')) + + return response.json([model_to_dict(x) for x in query.order_by(-Job.id)]) + + @app.route("/api/job//stop", methods=['POST']) async def api_stop_job(request, job_id): # TODO auth or some kind