mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
tools: ynl: load jsonschema on demand
The CLI script tries to validate jsonschema by default. It's seems better to validate too many times than too few. However, when copying the scripts to random servers having to install jsonschema is tedious. Load jsonschema via importlib, and let the user opt out. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import collections
|
||||
import jsonschema
|
||||
import importlib
|
||||
import os
|
||||
import traceback
|
||||
import yaml
|
||||
|
||||
|
||||
# To be loaded dynamically as needed
|
||||
jsonschema = None
|
||||
|
||||
|
||||
class SpecElement:
|
||||
"""Netlink spec element.
|
||||
|
||||
@@ -197,9 +201,14 @@ class SpecFamily(SpecElement):
|
||||
if schema_path is None:
|
||||
schema_path = os.path.dirname(os.path.dirname(spec_path)) + f'/{self.proto}.yaml'
|
||||
if schema_path:
|
||||
global jsonschema
|
||||
|
||||
with open(schema_path, "r") as stream:
|
||||
schema = yaml.safe_load(stream)
|
||||
|
||||
if jsonschema is None:
|
||||
jsonschema = importlib.import_module("jsonschema")
|
||||
|
||||
jsonschema.validate(self.yaml, schema)
|
||||
|
||||
self.attr_sets = collections.OrderedDict()
|
||||
|
Reference in New Issue
Block a user