From 2709762ccd9eacf9955fbd1abab1d22419704033 Mon Sep 17 00:00:00 2001 From: xinzhel97 Date: Thu, 29 Oct 2020 09:07:03 +1100 Subject: [PATCH] Add more error messages --- README.md | 4 ++-- planimation.py | 28 ++++++++++++++-------------- planimation_api.py | 9 +++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b21dfd7..76f580b 100755 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ An example of usage is demonstrated below: ```python import planimation_api as api result = api.pddl_visualise("domain.pddl", "problem.pddl", "ap.pddl", "mp4") -print(result) // display the name of received file +print(result) # display the name of the received file or an error message ``` ### Command Line Utility @@ -39,5 +39,5 @@ The API should be considered to be in a very alpha phase at the moment. It's not ### Thanks The first version of Planimation API is developed by Changyuan Liu, Lingfeng Qiang, Mengyi Fan, Xinzhe Li and Zhaoqi Fang under Nir Lipovetzky's guidance. -[//]: # +[//]: # [here]: diff --git a/planimation.py b/planimation.py index d247f92..414a0dd 100644 --- a/planimation.py +++ b/planimation.py @@ -26,22 +26,22 @@ if vfg.endswith('.vfg'): i+=1 downloadtype = sys.argv[i].strip() - + if downloadtype!='png' and downloadtype!='webm' and downloadtype!='gif' and downloadtype!='mp4': - print("invalid download type") + print("Error: desired output format is not supported; only png, gif, webm and mp4 are supported") exit(1) else: - print(vfg) - print(downloadtype) - api.vfg_visualise(vfg,downloadtype) + #print(vfg) + #print(downloadtype) + print(api.vfg_visualise(vfg,downloadtype)) exit(0) else: - print("Invalid vfg file type") + print("Error: incorrect input format; input should be in vfg format") exit(1) else: - print("Invalid argument entered for submitVFG") + print("Error: incorrect number of arguments entered for submitVFG") exit(1) - # check submitPlan function + # check submitPlan function elif sys.argv[i] == "submitPDDL": i+=1 if len(sys.argv) == 6: @@ -54,20 +54,20 @@ i+=1 downloadtype = sys.argv[i].strip() if downloadtype!='png' and downloadtype!='webm' and downloadtype!='gif' and downloadtype!='mp4' and downloadtype!='vfg': - print("invalid download type") + print("Error: desired output format is not supported; only vfg, png, gif, webm and mp4 are supported") exit(1) else: - api.pddl_visualise(domainFile,problemFile,animationFile,downloadtype) + print(api.pddl_visualise(domainFile,problemFile,animationFile,downloadtype)) exit(0) else: - print("invalid input for pddls,please check your pddl files") + print("Error: incorrect input format; all input files should be in pddl format") exit(1) else: - print("Invalid argument numbers entered for submitPlan") + print("Error: incorrect number of arguments numbers entered for submitPDDL") exit(1) else: - print("no such argument input!!!") - exit(1) \ No newline at end of file + print("Error: no such command " + "'" + sys.argv[1] + "'") + exit(1) diff --git a/planimation_api.py b/planimation_api.py index 730941a..31f7cf8 100644 --- a/planimation_api.py +++ b/planimation_api.py @@ -1,6 +1,7 @@ import requests from datetime import datetime import re +import json # To be changed once deployed on actural server pddl_url = "http://127.0.0.1:8000/upload/(?P[^/]+)$" @@ -35,7 +36,11 @@ def pddl_visualise(domain_file, problem_file, animation_profile, output_format): animation = read_file(animation_profile) files = ("domain", (None, domain)), ("problem", (None, problem)), ("animation", (None, animation)), \ ("fileType", (None, output_format)) + print("Waiting for response...") r = requests.post(pddl_url, files=files) + if "message" in r.text: + message = json.loads(r.text) + return message['message'] if output_format == "png": output_format = "zip" output_name = "planimation " + datetime.now().strftime("%Y-%m-%d_%X.") + output_format @@ -55,7 +60,11 @@ def vfg_visualise(vfg_file, output_format): return None vfg = read_file(vfg_file) files = ('vfg', (None, vfg)), ('fileType', (None, output_format)) + print("Waiting for response...") r = requests.post(vfg_url, files=files) + if "message" in r.text: + message = json.loads(r.text) + return message['message'] if output_format == "png": output_format = "zip" output_name = "planimation " + datetime.now().strftime("%Y-%m-%d_%X.") + output_format