Base utils for xsd mi validation and saved sessions file
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 13 Nov 2017 16:46:05 +0000 (11:46 -0500)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 13 Nov 2017 16:46:05 +0000 (11:46 -0500)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
lttng_ivc/settings.py
lttng_ivc/utils/project.py
lttng_ivc/utils/utils.py

index 8a07dd205ca67b829754d64a6fda72e311b8f140..5889b19707286121bb0bc6491c5030c244212315 100644 (file)
@@ -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']
index bd389a59b4fb6b7257f63757b6074390fc098dad..912612067e294766dba9285ed0e902caf1fdd8c9 100644 (file)
@@ -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
index 37e09e197226ec1b9c9abf9a5da5f17aaa60ae6a..1660aba1383469d0f6d289aeab431dc87ceedea0 100644 (file)
@@ -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
This page took 0.026471 seconds and 5 git commands to generate.