that should be the basic delete impl

This commit is contained in:
Robin Müller 2023-02-17 18:43:20 +01:00
parent 2ef56ae8c4
commit aabfcf83ac
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -1,4 +1,6 @@
import datetime
import logging
import math
import struct
from eive_tmtc.config.object_ids import (
@ -40,19 +42,14 @@ def pack_tm_store_commands(p: ServiceProviderParams):
q = p.queue_helper
o = p.op_code
if o == OpCode.DELETE:
q.add_log_cmd(Info.DELETE)
delete_up_to_time = parse(
input(
"Please enter delete end time in any format supported by dateutil.parser.parse\n"
"Recommended format: UTC ISO format YYYY-MM-DDThh:mm:ssZ: "
)
)
print(f"Parsed timestamp: {delete_up_to_time}")
end_stamp = delete_up_to_time.timestamp()
obj_id = store_select_prompt()
obj_id, store_string = store_select_prompt()
app_data = bytearray(obj_id.as_bytes)
delete_up_to_time = time_prompt()
end_stamp = int(math.floor(delete_up_to_time.timestamp()))
app_data.extend(struct.pack("!I", end_stamp))
# q.add_pus_tc(
q.add_log_cmd(Info.DELETE)
q.add_log_cmd(f"Selected Store: {obj_id}")
q.add_log_cmd(f"Deletion up to time {delete_up_to_time}")
print(
PusTelecommand(
service=15, subservice=Subservice.DELETE_UP_TO, app_data=app_data
@ -83,20 +80,33 @@ STORE_DICT = {
}
def store_select_prompt() -> ObjectIdU32:
def time_prompt() -> datetime.datetime:
# TODO: Add support for offset from now in seconds
delete_up_to_time = parse(
input(
"Please enter delete end time in any format supported by dateutil.parser.parse\n"
"Recommended format: UTC ISO format YYYY-MM-DDThh:mm:ssZ: "
)
)
print(f"Parsed timestamp: {delete_up_to_time}")
return delete_up_to_time
def store_select_prompt() -> (ObjectIdU32, str):
obj_id_dict = get_object_ids()
print("Available TM stores:")
idx_to_obj_id = dict()
for idx, (k, v) in enumerate(STORE_DICT.items()):
idx_to_obj_id.update({idx: k})
idx_to_obj_id.update({idx: (k, v)})
print(f"{idx}: {v}")
while True:
target_index = int(
input("Please enter the target store for the TM store transaction: ")
)
obj_id_raw = idx_to_obj_id.get(target_index)
if obj_id_raw is None:
obj_id_and_store_str = idx_to_obj_id.get(target_index)
if obj_id_and_store_str is None:
_LOGGER.warning("Invalid index. Try again")
continue
break
return obj_id_dict.get(obj_id_raw)
obj_id_raw = obj_id_and_store_str[0]
return obj_id_dict.get(obj_id_raw), obj_id_and_store_str[1]