mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-02 13:44:00 +00:00
There is an increasing demand of composing different operations around XML schemas and/or data in different ways for different purpose. Today we already have: - Validate XML data, which takes XML schemas and data (board and scenario) as inputs. - Fill in missing nodes in XML data with default values, which takes XML schema and data (scenario only) as inputs. In the near future we'll extend the operations around XMLs by introducing XML schema preprocessing and XML data upgrading, adding more possibilities to construct a larger operation by composing smaller ones. In order for minimized code repetition and easier composition, this patch introduces an infrasturcture that abstracts each operation as a pipeline stage. Each stage defines its own inputs and outputs and can be composed sequentially as a larger, single operation. The existing operations listed above, along with XML file loaders, are then refactored to provide pipeline stages. The main methods are also refined to complete their tasks by constructing and invoking pipelines. Tracked-On: #6690 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
20 lines
465 B
Python
20 lines
465 B
Python
#!/usr/bin/env python3
|
|
#
|
|
# Copyright (C) 2022 Intel Corporation.
|
|
#
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
#
|
|
|
|
from defusedxml.ElementTree import parse
|
|
from pipeline import PipelineStage
|
|
|
|
class XMLLoadStage(PipelineStage):
|
|
def __init__(self, tag):
|
|
self.consumes = f"{tag}_path"
|
|
self.provides = f"{tag}_etree"
|
|
|
|
def run(self, obj):
|
|
xml_path = obj.get(self.consumes)
|
|
etree = parse(xml_path)
|
|
obj.set(self.provides, etree)
|