Re: [PATCH 1/2] config_tools: format vitio input in configurator


Kunhui Li
 

-----Original Message-----
From: Mao, Junjie <junjie.mao@...>
Sent: Monday, May 16, 2022 1:39 PM
To: Li, KunhuiX <kunhuix.li@...>
Cc: acrn-dev@...; Xie, Nanlin <nanlin.xie@...>; Feng, WeiyiX <weiyix.feng@...>
Subject: Re: [PATCH 1/2] config_tools: format vitio input in configurator

Kunhui-Li <kunhuix.li@...> writes:

This patch formats virtio input entry as "Device name: xxx, Device physical path: xxx".

Tracked-On: #6691
Signed-off-by: Kunhui-Li <kunhuix.li@...>
---
misc/config_tools/configurator/pyodide/loadBoard.py | 12 ++++++++++--
misc/config_tools/schema/VMtypes.xsd | 3 ++-
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/misc/config_tools/configurator/pyodide/loadBoard.py b/misc/config_tools/configurator/pyodide/loadBoard.py
index 48bb02715..035c89fa2 100644
--- a/misc/config_tools/configurator/pyodide/loadBoard.py
+++ b/misc/config_tools/configurator/pyodide/loadBoard.py
@@ -2,6 +2,7 @@
__package__ = 'configurator.pyodide'

import json
+import logging
from copy import deepcopy

import elementpath
@@ -20,7 +21,11 @@ def get_dynamic_scenario(board):
board_xml = etree.fromstring(board)

def get_enum(source, options, obj_type):
- elements = [str(x) for x in elementpath.select(source, options) if x]
+ if options == "//inputs/input":
+ inputs_etree = [x for x in elementpath.select(source, options) if x is not None]
+ elements = [f"Device name: {str(elementpath.select(i, './name/text()')[0])}, Device physical path: {str(elementpath.select(i,
'./phys/text()')[0])}" for i in inputs_etree]
+ else:
+ elements = [str(x) for x in elementpath.select(source, options) if x]
This file contains the general logic to extract enum values from
annotations and is not where item-specific logic should be placed. XPATH
2.0 already supports functions like string-join and for-expressions. You
should be able to express what you need using a single XPATH.
Will update.

elements = list(set(elements))
if not elements:
elements = ['']
@@ -42,7 +47,10 @@ def get_dynamic_scenario(board):
# get enum data
enum = function(source, selector, obj_type)
if sorted_func:
- enum = sorted(enum, key=eval(sorted_func))
+ try:
+ enum = sorted(enum, key=eval(sorted_func))
+ except IndexError as e:
+ logging.warning(e)
Why do you need catch this exception?
Because the "IndexError" will be raise if the //input/name and //input/phys data is not found in board xml file, then user will fail to import board xml.
May I can remove this because it is unnecessary if we use XPATH to parse data.

--
Best Regards
Junjie Mao

return enum

def dynamic_enum_apply(obj):
diff --git a/misc/config_tools/schema/VMtypes.xsd b/misc/config_tools/schema/VMtypes.xsd
index 302e152b6..8fe381caa 100644
--- a/misc/config_tools/schema/VMtypes.xsd
+++ b/misc/config_tools/schema/VMtypes.xsd
@@ -395,7 +395,8 @@ device file when user config it as virtio serial port, which can be read and wri
<xs:complexType name="VirtioInputConfiguration">
<xs:sequence>
<xs:element name="backend_device_file" type="xs:string" minOccurs="0">
- <xs:annotation acrn:title="Backend device file" acrn:widget-options="'placeholder': '/dev/input/eventX'">
+ <xs:annotation acrn:title="Backend device file" acrn:widget-options="'placeholder': '/dev/input/eventX'"
acrn:options="//inputs/input"
+ acrn:options-sorted-by="lambda s: (s.split('Device name: ')[1].split(', Device physical path')[0], s.split('Device physical path:
')[1])">
<xs:documentation>Specifying backend device in service vm with device description.</xs:documentation>
</xs:annotation>
</xs:element>

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.