【Python工具开发】k3q_arxml 简单但是非常好用的arxml编辑器,可以称为arxml杀手包

k3q_arxml

介绍

仓库地址1
仓库地址2

极简的arxml编辑库,纯python实现

用法

python 复制代码
from pprint import pp # 可以美化打印对象,不然全打印在一行
import k3q_arxml
# 加载arxml文件
io_arxml = k3q_arxml.IOArxml(filepaths=['test/model_merge.arxml'])

# 打印arxml字符串绑定的python arxml实例
io_arxml.print(print_filepath='model_merge.txt')

# 刷新ref缓存数据,因为ref/ar/ref_to_ref/locate_filename访问的都是缓存数据,如果修改了数据后,影响到了ref,就需要主动刷新
io_arxml.scan_ref()

# 增/改
io_arxml.ref(('Implementations', 'HWIO')).resource_consumption = k3q_arxml.autosar.ResourceConsumption(
    short_name=k3q_arxml.autosar.Identifier(value='resourceConsumption'))

# 删
del io_arxml.ref(('Implementations', 'HWIO')).resource_consumption
io_arxml.ref(('Implementations', 'HWIO')).resource_consumption = None

# 查
## 根据ref查arxml实例
io_arxml.ref(('Implementations', 'HWIO'))
## 根据ref查哪些arxml实例用到了该ref
io_arxml.ref_to_ref(('Implementations', 'HWIO'))
## 根据标签查arxml实例(该需要带有short_name属性)
io_arxml.ar(clazz=k3q_arxml.autosar.ResourceConsumption)
## 根据标签查arxml实例,但限定ref路径下查找(该需要带有short_name属性)
io_arxml.ar(clazz=k3q_arxml.autosar.ResourceConsumption, ref_prefix=('Implementations',))

# 辅助函数
## 控制台打印uuid到ref的映射关系,能通过uuid快速定位ref路径,辅助编码
io_arxml.scan_ref(debug_uuid=True)
## 获取路径在那个arxml文件里
io_arxml.locate_filename(ref=('Implementations',))

# 切换autosar_00052版本,默认为autosar_00048
from autosar import autosar_00052
k3q_arxml.autosar = autosar_00052

# 回写到文件
io_arxml.flush_to_file()

技巧

  1. 手动添加完成后的arxml和原始arxml,都通过io_arxml.print函数打印在文件里
  2. 通过对比软件对比源arxml和打印的arxml,找出需要修改的arxml内容
  3. 该内容就是对象的定义代码,可以复制出来粘贴到代码里
相关推荐
孟健1 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽1 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程2 天前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪2 天前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook2 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田2 天前
使用 pkgutil 实现动态插件系统
python
前端付豪2 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽2 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战2 天前
Pydantic配置管理最佳实践(一)
python