Added cursor feedback in iot-client for index relevant commands

This commit is contained in:
Martin Schett 2020-12-06 19:14:40 +01:00
parent 08b30bb9cd
commit f313d18313

View File

@ -5,7 +5,6 @@ import json
import time import time
from datetime import datetime from datetime import datetime
def print_response(response): def print_response(response):
print("Code: " + str(response.status_code) + "; Body: " + str(response.json())) print("Code: " + str(response.status_code) + "; Body: " + str(response.json()))
@ -90,6 +89,21 @@ def delete_image(identifier):
return True 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(): def get_all():
print("Getting all images") print("Getting all images")
@ -114,7 +128,7 @@ def check_system():
response = requests.get(baseurl + get_url) response = requests.get(baseurl + get_url)
print_response(response) print_response(response)
except os.error: except os.error:
print("Error checking system health") print("Server not available")
return True return True
@ -138,25 +152,18 @@ if (os.path.isdir(image_folder)):
else: else:
print("Default image folder not found.") 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 # main input loop
command = "dummy" 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"]): while (command.lower() not in ["exit", "quit", "end"]):
try: try:
@ -187,7 +194,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("fetchall - get all images") print("fetchall - get all images")
print("delete - delets the next image from db if exists") print("delete - delets the next image from db if exists")
print("delete - delets all images from the service") 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("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("set <#index> - sets image on given <index> as next in line")
print("select |<identifier> - select image with given <identifier> 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)) print("Current lineup index is " + str(index))
if command.lower() == "info": if command.lower() == "info":
print_cursor()
if metadata is None: if metadata is None:
print("No metadata selected") print("No metadata selected")
else: else:
@ -262,6 +270,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
filename = meta_payload['filename'] filename = meta_payload['filename']
send_image(filename[:-4], image_folder + os.path.sep + filename, meta_payload) send_image(filename[:-4], image_folder + os.path.sep + filename, meta_payload)
index = index + 1 index = index + 1
print_cursor()
if command.lower() == "fetch": if command.lower() == "fetch":
if metadata is None: if metadata is None:
@ -274,6 +283,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
filename = meta_payload['filename'] filename = meta_payload['filename']
get_image(filename[:-4]) get_image(filename[:-4])
index = index + 1 index = index + 1
print_cursor()
if command.lower() == "fetchall": if command.lower() == "fetchall":
if metadata is None: if metadata is None:
@ -283,7 +293,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("No image folder selected") print("No image folder selected")
continue continue
get_all() get_all()
index = index + 1 print_cursor()
if command.lower() == "delete": if command.lower() == "delete":
if metadata is None: if metadata is None:
@ -296,6 +306,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
filename = meta_payload['filename'] filename = meta_payload['filename']
delete_image(filename[:-4]) delete_image(filename[:-4])
index = index + 1 index = index + 1
print_cursor()
if command.lower() == "deleteall": if command.lower() == "deleteall":
if metadata is None: if metadata is None:
@ -305,9 +316,10 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("No image folder selected") print("No image folder selected")
continue continue
delete_all_image() delete_all_image()
index = index + 1 print_cursor()
if command.lower() == "rapid": if command.lower() == "rapid":
t = 5
if metadata is None: if metadata is None:
print("No metadata loaded") print("No metadata loaded")
continue continue
@ -320,6 +332,12 @@ while (command.lower() not in ["exit", "quit", "end"]):
if not attributes[0].isnumeric(): if not attributes[0].isnumeric():
print("Error: amount is no number") print("Error: amount is no number")
continue 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]) amount = int(attributes[0])
for i in range(0, amount): for i in range(0, amount):
meta_payload = metadata[index] meta_payload = metadata[index]
@ -328,8 +346,11 @@ while (command.lower() not in ["exit", "quit", "end"]):
index = index + 1 index = index + 1
if index >= len(metadata) or index < 0: if index >= len(metadata) or index < 0:
index = 0 index = 0
print_cursor()
try: try:
time.sleep(2) if i < amount - 1:
print("Waiting " + str(t) + " seconds for next request")
time.sleep(t)
except: except:
print("Error on sleep") print("Error on sleep")
@ -345,6 +366,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
index = index + int(amount) index = index + int(amount)
if index >= len(metadata) or index < 0: if index >= len(metadata) or index < 0:
index = 0 index = 0
print_cursor()
if command.lower() == "set": if command.lower() == "set":
if metadata is None: if metadata is None:
@ -361,6 +383,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("Index outside length of metadata") print("Index outside length of metadata")
continue continue
index = ind index = ind
print_cursor()
if command.lower() == "select": if command.lower() == "select":
if metadata is None: if metadata is None:
@ -379,5 +402,6 @@ while (command.lower() not in ["exit", "quit", "end"]):
break break
if not found: if not found:
print("Could not find image by identifier " + identifier) print("Could not find image by identifier " + identifier)
print_cursor()
quit("Bye") quit("Bye")