2024-bsc-sebastian-lenzlinger/code/kydcap/utils/capture_metadata_utils.py

41 lines
1.4 KiB
Python

import json
from pathlib import Path
from kydcap.config import ReturnCodes
def set_device_ip_address(ip_addr: str, file_path: Path):
assert ip_addr is not None
assert file_path.is_file()
with file_path.open('r') as f:
data = json.load(f)
current_ip = data["device_ip_address"]
if current_ip is not None:
print(f"Device IP Address is set to {current_ip}")
response = input(f"Do you want to change the recorded IP address to {ip_addr}? [Y/N] ")
if response.upper() == "N":
print("Aborting change to device IP address")
return ReturnCodes.ABORTED
with file_path.open('w') as f:
json.dump(data, f)
return ReturnCodes.SUCCESS
def set_device_mac_address(mac_addr: str, file_path: Path):
assert mac_addr is not None
assert file_path.is_file()
with file_path.open('r') as f:
data = json.load(f)
current_mac = data["device_mac_address"]
if current_mac is not None:
print(f"Device MAC Address is set to {current_mac}")
response = input(f"Do you want to change the recorded MAC address to {mac_addr}? [Y/N] ")
if response.upper() == "N":
print("Aborting change to device MAC address")
return ReturnCodes.ABORTED
with file_path.open('w') as f:
json.dump(data, f)
return ReturnCodes.SUCCESS
# TODO finnish for other fields in capture metadata