2024-bsc-sebastian-lenzlinger/code/kydcap/utils/device_metadata_utils.py
Sebastian Lenzlinger a78222a0e6 Devel
2024-05-02 02:08:09 +00:00

50 lines
1.7 KiB
Python

import json
from datetime import datetime
from pathlib import Path
from kydcap.config import ReturnCodes
def update_firmware_version(version: str, file_path: Path):
assert file_path.is_file()
with file_path.open('r') as file:
metadata = json.load(file)
metadata['device_firmware_version'] = version
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
with file_path.open('w') as file:
json.dump(metadata, file)
return ReturnCodes.SUCCESS
def add_capture_file_reference(capture_file_reference: str, file_path: Path):
assert file_path.is_file()
with file_path.open('r') as file:
metadata = json.load(file)
metadata['capture_files'] = capture_file_reference
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
with file_path.open('w') as file:
json.dump(metadata, file)
return ReturnCodes.SUCCESS
def update_device_serial_number(device_id: str, file_path: Path):
assert file_path.is_file()
with file_path.open('r') as file:
metadata = json.load(file)
metadata['device_id'] = device_id
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
with file_path.open('w') as file:
json.dump(metadata, file)
return ReturnCodes.SUCCESS
def update_device_type(device_type: str, file_path: Path):
assert file_path.is_file()
with file_path.open('r') as file:
metadata = json.load(file)
metadata['device_type'] = device_type
metadata['date_updated'] = datetime.now().strftime('%d-%m-%YT%H:%M:%S').lower()
with file_path.open('w') as file:
json.dump(metadata, file)
return ReturnCodes.SUCCESS