上传初版SDK
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
核心基类和工具函数模块
|
||||
"""
|
||||
import uuid
|
||||
import re
|
||||
import xml.dom.minidom as Dom
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional, List
|
||||
|
||||
from .constants import UUID, SHORT_NAME
|
||||
from .enums import Category, Encoding, CalibrationAccess, UpperSts, LowerSts
|
||||
|
||||
|
||||
def create_uuid() -> str:
|
||||
"""生成 UUID"""
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
def create_text_element(doc: Dom.Document, tag: str, text: str) -> Dom.Element:
|
||||
"""创建文本元素"""
|
||||
element = doc.createElement(tag)
|
||||
node = doc.createTextNode(text)
|
||||
element.appendChild(node)
|
||||
return element
|
||||
|
||||
|
||||
@dataclass
|
||||
class Base:
|
||||
"""所有类的基类,提供名称和层级结构支持"""
|
||||
name: str
|
||||
id: Optional[int] = field(default=None)
|
||||
parent: Optional['Base'] = field(default=None, repr=False)
|
||||
description: Optional[str] = field(default=None)
|
||||
|
||||
@property
|
||||
def class_name(self) -> str:
|
||||
"""获取类型名称"""
|
||||
return self.__class__.__name__
|
||||
|
||||
@property
|
||||
def parent_id(self) -> Optional[int]:
|
||||
"""获取父类ID"""
|
||||
return self.parent.id if self.parent is not None else None
|
||||
|
||||
@property
|
||||
def package_path(self) -> str:
|
||||
"""获取完整路径(包路径+名称)"""
|
||||
path = []
|
||||
current = self
|
||||
while current is not None:
|
||||
path.append(current.name)
|
||||
current = current.parent
|
||||
return '/' + '/'.join(reversed(path))
|
||||
|
||||
def to_arxml(self, doc: Dom.Document) -> Dom.Element:
|
||||
"""转换为 ARXML 元素"""
|
||||
raise NotImplementedError("to_arxml method must be implemented by subclass")
|
||||
Reference in New Issue
Block a user