Skip to content

Commit

Permalink
Add more error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
xinzhel97 committed Oct 28, 2020
1 parent a8ecd3a commit 2709762
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:<https://planimation.planning.domains/>
28 changes: 14 additions & 14 deletions planimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
print("Error: no such command " + "'" + sys.argv[1] + "'")
exit(1)
9 changes: 9 additions & 0 deletions planimation_api.py
Original file line number Diff line number Diff line change
@@ -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<filename>[^/]+)$"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2709762

Please # to comment.