【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. 该内容就是对象的定义代码,可以复制出来粘贴到代码里
相关推荐
丁浩66616 小时前
Python机器学习---2.算法:逻辑回归
python·算法·机器学习
yudiandian201416 小时前
02 Oracle JDK 下载及配置(解压缩版)
java·开发语言
要加油哦~16 小时前
JS | 知识点总结 - 原型链
开发语言·javascript·原型模式
B站_计算机毕业设计之家16 小时前
计算机毕业设计:Python农业数据可视化分析系统 气象数据 农业生产 粮食数据 播种数据 爬虫 Django框架 天气数据 降水量(源码+文档)✅
大数据·爬虫·python·机器学习·信息可视化·课程设计·农业
Q_Q51100828516 小时前
python+uniapp基于微信小程序的旅游信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
鄃鳕16 小时前
python迭代器解包【python】
开发语言·python
new coder16 小时前
[c++语法学习]Day10:c++引用
开发语言·c++·学习
驰羽16 小时前
[GO]GORM 常用 Tag 速查手册
开发语言·后端·golang
Narcissiffo17 小时前
【C语言】str系列函数
c语言·开发语言
楚韵天工17 小时前
宠物服务平台(程序+文档)
java·网络·数据库·spring cloud·编辑器·intellij-idea·宠物