Added cursor feedback in iot-client for index relevant commands
This commit is contained in:
parent
08b30bb9cd
commit
f313d18313
@ -5,7 +5,6 @@ import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def print_response(response):
|
||||
print("Code: " + str(response.status_code) + "; Body: " + str(response.json()))
|
||||
|
||||
@ -90,6 +89,21 @@ def delete_image(identifier):
|
||||
return True
|
||||
|
||||
|
||||
def delete_all_image():
|
||||
print("Deleting all images")
|
||||
|
||||
baseurl = "http://127.0.0.1:8000"
|
||||
get_url = "/image/delete/all"
|
||||
|
||||
try:
|
||||
response = requests.delete(baseurl + get_url)
|
||||
payload = response.json()
|
||||
print(payload)
|
||||
except os.error:
|
||||
print("Error deleting request")
|
||||
return True
|
||||
|
||||
|
||||
def get_all():
|
||||
print("Getting all images")
|
||||
|
||||
@ -114,7 +128,7 @@ def check_system():
|
||||
response = requests.get(baseurl + get_url)
|
||||
print_response(response)
|
||||
except os.error:
|
||||
print("Error checking system health")
|
||||
print("Server not available")
|
||||
return True
|
||||
|
||||
|
||||
@ -138,25 +152,18 @@ if (os.path.isdir(image_folder)):
|
||||
else:
|
||||
print("Default image folder not found.")
|
||||
|
||||
|
||||
def print_cursor():
|
||||
if metadata is None:
|
||||
print('Cursor on 0 of 0')
|
||||
return
|
||||
print('Cursor on ' + str(index) + " out of " + str(len(metadata)) + " - " + metadata[index]['filename'])
|
||||
|
||||
|
||||
# main input loop
|
||||
command = "dummy"
|
||||
|
||||
|
||||
def delete_all_image():
|
||||
print("Deleting all images")
|
||||
|
||||
baseurl = "http://127.0.0.1:8000"
|
||||
get_url = "/image/delete/all"
|
||||
|
||||
try:
|
||||
response = requests.delete(baseurl + get_url)
|
||||
payload = response.json()
|
||||
print(payload)
|
||||
except os.error:
|
||||
print("Error deleting request")
|
||||
return True
|
||||
|
||||
|
||||
while (command.lower() not in ["exit", "quit", "end"]):
|
||||
|
||||
try:
|
||||
@ -187,7 +194,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
print("fetchall - get all images")
|
||||
print("delete - delets the next image from db if exists")
|
||||
print("delete - delets all images from the service")
|
||||
print("rapid <#amount> - next <amound> images in line are sent to backend in 2 second intervals")
|
||||
print("rapid <#amount> [<#time>] - next <amount> images in line are sent to backend in <time> (default: 5) second intervals")
|
||||
print("skip [<#amount>] - skips the next <amount> number of images in line or 1 if no <amount> is given")
|
||||
print("set <#index> - sets image on given <index> as next in line")
|
||||
print("select |<identifier> - select image with given <identifier> as next in line")
|
||||
@ -210,6 +217,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
print("Current lineup index is " + str(index))
|
||||
|
||||
if command.lower() == "info":
|
||||
print_cursor()
|
||||
if metadata is None:
|
||||
print("No metadata selected")
|
||||
else:
|
||||
@ -262,6 +270,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
filename = meta_payload['filename']
|
||||
send_image(filename[:-4], image_folder + os.path.sep + filename, meta_payload)
|
||||
index = index + 1
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "fetch":
|
||||
if metadata is None:
|
||||
@ -274,6 +283,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
filename = meta_payload['filename']
|
||||
get_image(filename[:-4])
|
||||
index = index + 1
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "fetchall":
|
||||
if metadata is None:
|
||||
@ -283,7 +293,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
print("No image folder selected")
|
||||
continue
|
||||
get_all()
|
||||
index = index + 1
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "delete":
|
||||
if metadata is None:
|
||||
@ -296,6 +306,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
filename = meta_payload['filename']
|
||||
delete_image(filename[:-4])
|
||||
index = index + 1
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "deleteall":
|
||||
if metadata is None:
|
||||
@ -305,9 +316,10 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
print("No image folder selected")
|
||||
continue
|
||||
delete_all_image()
|
||||
index = index + 1
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "rapid":
|
||||
t = 5
|
||||
if metadata is None:
|
||||
print("No metadata loaded")
|
||||
continue
|
||||
@ -320,6 +332,12 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
if not attributes[0].isnumeric():
|
||||
print("Error: amount is no number")
|
||||
continue
|
||||
if len(attributes) >= 2:
|
||||
if not attributes[1].isnumeric():
|
||||
print("Error: time is no number")
|
||||
continue
|
||||
else:
|
||||
t = int(attributes[1])
|
||||
amount = int(attributes[0])
|
||||
for i in range(0, amount):
|
||||
meta_payload = metadata[index]
|
||||
@ -328,8 +346,11 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
index = index + 1
|
||||
if index >= len(metadata) or index < 0:
|
||||
index = 0
|
||||
print_cursor()
|
||||
try:
|
||||
time.sleep(2)
|
||||
if i < amount - 1:
|
||||
print("Waiting " + str(t) + " seconds for next request")
|
||||
time.sleep(t)
|
||||
except:
|
||||
print("Error on sleep")
|
||||
|
||||
@ -345,6 +366,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
index = index + int(amount)
|
||||
if index >= len(metadata) or index < 0:
|
||||
index = 0
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "set":
|
||||
if metadata is None:
|
||||
@ -361,6 +383,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
print("Index outside length of metadata")
|
||||
continue
|
||||
index = ind
|
||||
print_cursor()
|
||||
|
||||
if command.lower() == "select":
|
||||
if metadata is None:
|
||||
@ -379,5 +402,6 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
||||
break
|
||||
if not found:
|
||||
print("Could not find image by identifier " + identifier)
|
||||
print_cursor()
|
||||
|
||||
quit("Bye")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user