Skip to content

Commit 2709762

Browse files
committed
Add more error messages
1 parent a8ecd3a commit 2709762

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ An example of usage is demonstrated below:
1717
```python
1818
import planimation_api as api
1919
result = api.pddl_visualise("domain.pddl", "problem.pddl", "ap.pddl", "mp4")
20-
print(result) // display the name of received file
20+
print(result) # display the name of the received file or an error message
2121
```
2222

2323
### 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
3939
### Thanks
4040
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.
4141

42-
[//]: #
42+
[//]: #
4343
[here]:<https://planimation.planning.domains/>

planimation.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@
2626
if vfg.endswith('.vfg'):
2727
i+=1
2828
downloadtype = sys.argv[i].strip()
29-
29+
3030
if downloadtype!='png' and downloadtype!='webm' and downloadtype!='gif' and downloadtype!='mp4':
31-
print("invalid download type")
31+
print("Error: desired output format is not supported; only png, gif, webm and mp4 are supported")
3232
exit(1)
3333
else:
34-
print(vfg)
35-
print(downloadtype)
36-
api.vfg_visualise(vfg,downloadtype)
34+
#print(vfg)
35+
#print(downloadtype)
36+
print(api.vfg_visualise(vfg,downloadtype))
3737
exit(0)
3838
else:
39-
print("Invalid vfg file type")
39+
print("Error: incorrect input format; input should be in vfg format")
4040
exit(1)
4141
else:
42-
print("Invalid argument entered for submitVFG")
42+
print("Error: incorrect number of arguments entered for submitVFG")
4343
exit(1)
44-
# check submitPlan function
44+
# check submitPlan function
4545
elif sys.argv[i] == "submitPDDL":
4646
i+=1
4747
if len(sys.argv) == 6:
@@ -54,20 +54,20 @@
5454
i+=1
5555
downloadtype = sys.argv[i].strip()
5656
if downloadtype!='png' and downloadtype!='webm' and downloadtype!='gif' and downloadtype!='mp4' and downloadtype!='vfg':
57-
print("invalid download type")
57+
print("Error: desired output format is not supported; only vfg, png, gif, webm and mp4 are supported")
5858
exit(1)
5959
else:
60-
api.pddl_visualise(domainFile,problemFile,animationFile,downloadtype)
60+
print(api.pddl_visualise(domainFile,problemFile,animationFile,downloadtype))
6161
exit(0)
6262

6363
else:
64-
print("invalid input for pddls,please check your pddl files")
64+
print("Error: incorrect input format; all input files should be in pddl format")
6565
exit(1)
6666

6767
else:
68-
print("Invalid argument numbers entered for submitPlan")
68+
print("Error: incorrect number of arguments numbers entered for submitPDDL")
6969
exit(1)
7070

7171
else:
72-
print("no such argument input!!!")
73-
exit(1)
72+
print("Error: no such command " + "'" + sys.argv[1] + "'")
73+
exit(1)

planimation_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
from datetime import datetime
33
import re
4+
import json
45

56
# To be changed once deployed on actural server
67
pddl_url = "http://127.0.0.1:8000/upload/(?P<filename>[^/]+)$"
@@ -35,7 +36,11 @@ def pddl_visualise(domain_file, problem_file, animation_profile, output_format):
3536
animation = read_file(animation_profile)
3637
files = ("domain", (None, domain)), ("problem", (None, problem)), ("animation", (None, animation)), \
3738
("fileType", (None, output_format))
39+
print("Waiting for response...")
3840
r = requests.post(pddl_url, files=files)
41+
if "message" in r.text:
42+
message = json.loads(r.text)
43+
return message['message']
3944
if output_format == "png":
4045
output_format = "zip"
4146
output_name = "planimation " + datetime.now().strftime("%Y-%m-%d_%X.") + output_format
@@ -55,7 +60,11 @@ def vfg_visualise(vfg_file, output_format):
5560
return None
5661
vfg = read_file(vfg_file)
5762
files = ('vfg', (None, vfg)), ('fileType', (None, output_format))
63+
print("Waiting for response...")
5864
r = requests.post(vfg_url, files=files)
65+
if "message" in r.text:
66+
message = json.loads(r.text)
67+
return message['message']
5968
if output_format == "png":
6069
output_format = "zip"
6170
output_name = "planimation " + datetime.now().strftime("%Y-%m-%d_%X.") + output_format

0 commit comments

Comments
 (0)