[PATCH 1/2] sanitytest.py parameters are now optional

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When called without parameters, sanitytest.py doesn't touch sys.path and
locates itself the patch to the libvirt-api.xml file using pkg-config.

This change makes possible to run sanitytest.py from tox.
---
 sanitytest.py | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/sanitytest.py b/sanitytest.py
index eb44cdb..faabccb 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -5,18 +5,31 @@ import lxml
 import lxml.etree
 import string
 
-# Munge import path to insert build location for libvirt mod
-sys.path.insert(0, sys.argv[1])
+if len(sys.argv) >= 2:
+    # Munge import path to insert build location for libvirt mod
+    sys.path.insert(0, sys.argv[1])
 import libvirt
 
 if sys.version > '3':
     long = int
 
+def get_libvirt_api_xml_path():
+    import subprocess
+    args = ["pkg-config", "--variable", "libvirt_api", "libvirt"]
+    proc = subprocess.Popen(args, stdout=subprocess.PIPE)
+    stdout, _ = proc.communicate()
+    if proc.returncode:
+        sys.exit(proc.returncode)
+    return stdout.splitlines()[0]
+
 # Path to the libvirt API XML file
-xml = sys.argv[2]
+if len(sys.argv) >= 3:
+    xml = sys.argv[2]
+else:
+    xml = get_libvirt_api_xml_path()
 
-f = open(xml, "r")
-tree = lxml.etree.parse(f)
+with open(xml, "r") as fp:
+    tree = lxml.etree.parse(fp)
 
 verbose = False
 fail = False
-- 
2.1.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]