28 lines
818 B
Python
28 lines
818 B
Python
import json
|
|
import uuid
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
|
|
class DeviceMetadata:
|
|
def __init__(self, device_name, device_root_path):
|
|
self.device_name = device_name
|
|
self.device_short_name = device_name.lower().replace(' ', '_')
|
|
self.device_id = str(uuid.uuid4())
|
|
self.date_created = datetime.now().isoformat()
|
|
self.device_root_path = Path(device_root_path)
|
|
|
|
def to_dict(self):
|
|
return self.__dict__
|
|
|
|
def save_to_file(self):
|
|
file_path = self.device_root_path / 'device_metadata.json'
|
|
with open(file_path, 'w') as f:
|
|
json.dump(self.to_dict(), f, indent=4)
|
|
|
|
@classmethod
|
|
def load_from_file(cls, file_path):
|
|
with open(file_path, 'r') as f:
|
|
data = json.load(f)
|
|
return cls(**data)
|