From 816f8cc1d499bc6230da6037cea51bc116d63f50 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Mon, 13 Nov 2017 11:46:05 -0500 Subject: [PATCH] Base utils for xsd mi validation and saved sessions file Signed-off-by: Jonathan Rajotte --- lttng_ivc/settings.py | 1 + lttng_ivc/utils/project.py | 11 ++++++++++- lttng_ivc/utils/utils.py | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lttng_ivc/settings.py b/lttng_ivc/settings.py index 8a07dd2..5889b19 100644 --- a/lttng_ivc/settings.py +++ b/lttng_ivc/settings.py @@ -30,3 +30,4 @@ lttng_test_procfile = "/proc/lttng-test-filter-event" save_ext = ".lttng" +mi_xsd_file_name = ['mi_lttng.xsd', 'mi-lttng-3.0.xsd'] diff --git a/lttng_ivc/utils/project.py b/lttng_ivc/utils/project.py index bd389a5..9126120 100644 --- a/lttng_ivc/utils/project.py +++ b/lttng_ivc/utils/project.py @@ -6,7 +6,7 @@ import logging import lttng_ivc.settings as Settings from lttng_ivc.utils.utils import sha256_checksum -from lttng_ivc.utils.utils import find_dir +from lttng_ivc.utils.utils import find_dir, find_file _logger = logging.getLogger('project') @@ -339,6 +339,15 @@ class Lttng_tools(Project): self.add_special_env_variable("LTTNG_SESSION_CONFIG_XSD_PATH", os.path.join(self.installation_path, "share/xml/lttng/")) + # Find the mi xsd + for xsd in Settings.mi_xsd_file_name: + mi = find_file(self.source_path, xsd) + if mi: + break + if not mi: + raise Exception("MI xsd not found") + self.mi_xsd = mi + class Babeltrace(Project): pass diff --git a/lttng_ivc/utils/utils.py b/lttng_ivc/utils/utils.py index 37e09e1..1660aba 100644 --- a/lttng_ivc/utils/utils.py +++ b/lttng_ivc/utils/utils.py @@ -84,6 +84,31 @@ def find_dir(root, name): return abs_path +def find_file(root, name): + """ + Returns the absolute path or None. + """ + print(root) + print(name) + abs_path = None + for base, dirs, files in os.walk(root): + for tmp in files: + if tmp.endswith(name): + abs_path = os.path.abspath(os.path.join(base, tmp)) + print(abs_path) + return abs_path + + +def validate(xml_path, xsd_path): + + xmlschema_doc = etree.parse(xsd_path) + xmlschema = etree.XMLSchema(xmlschema_doc) + + xml_doc = etree.parse(xml_path) + result = xmlschema.validate(xml_doc) + + return result + def xpath_query(xml_file, xpath): """ Return a list of xml node corresponding to the xpath. The list can be of lenght -- 2.34.1