【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. 该内容就是对象的定义代码,可以复制出来粘贴到代码里
相关推荐
用户8356290780516 分钟前
Python设置PowerPoint幻灯片背景的方法
后端·python
wang_yb6 分钟前
Python 中 10 个最常用的统计函数
python·databook
databook11 分钟前
Python 中 10 个最常用的统计函数
python·数据分析
大白同学42139 分钟前
初识Qt——创建第一个Qt项目
开发语言·qt
祈禾41 分钟前
计算机组成原理之编译、汇编、链接、解释
开发语言·汇编·笔记·学习
吴声子夜歌1 小时前
正则指引——Ruby
开发语言·正则表达式·ruby
艾琳_lab1 小时前
Python环境配置:pip镜像设置
python
nnerddboy1 小时前
Rust教程06:ESP32-rust环境搭建
开发语言·后端·rust
橘好き1 小时前
Python
python
鹿鹿学长1 小时前
从英伟达开源Nemotron 3.5看“本地跑大模型“:一张显卡够用的时代来了
python·自动化