]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu-parse: Wrap with python script
authorTim Wiederhake <twiederh@redhat.com>
Tue, 15 Dec 2020 16:25:02 +0000 (17:25 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Dec 2020 22:20:23 +0000 (23:20 +0100)
This changes the invocation from
  ./cpu-gather.py | ./cpu-parse.sh
to
  ./cpu-gather.py [--gather] | ./cpu-gather.py --parse

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/cputestdata/cpu-gather.py
tests/cputestdata/cpu-parse.sh

index 005d1019b6bb5c78c2561f479c3cd7415851598d..83f175d342220c21f2b2165957da27c38f499d90 100755 (executable)
@@ -192,6 +192,15 @@ def gather(args):
     return result
 
 
+def parse(args):
+    os.environ["CPU_GATHER_PY"] = "true"
+    output = subprocess.check_output(
+        "./cpu-parse.sh",
+        stderr=subprocess.STDOUT,
+        universal_newlines=True)
+    print(output)
+
+
 def output_to_text(data):
     output = list()
 
@@ -231,8 +240,21 @@ def main():
         "If unset, will try '/usr/bin/qemu-system-x86_64', "
         "'/usr/bin/qemu-kvm', and '/usr/libexec/qemu-kvm'.")
 
+    mode = parser.add_mutually_exclusive_group()
+    mode.add_argument(
+        "--gather",
+        action="store_true",
+        help="Acquire data on target system. This is the default.")
+    mode.add_argument(
+        "--parse",
+        action="store_true",
+        help="Parse data for libvirt use.")
+
     args = parser.parse_args()
 
+    if not args.gather and not args.parse:
+        args.gather = True
+
     if not args.path_to_qemu:
         args.path_to_qemu = "qemu-system-x86_64"
         search = [
@@ -243,8 +265,11 @@ def main():
             if os.path.isfile(f):
                 args.path_to_qemu = f
 
-    data = gather(args)
-    print(output_to_text(data))
+    if args.gather:
+        data = gather(args)
+        print(output_to_text(data))
+    else:
+        parse(args)
 
 
 if __name__ == "__main__":
index 2981e9193c1e6379b8545228aef766fb9e63ef45..fa4344b6ad04e0c4a1b601704fb798f256773b16 100755 (executable)
@@ -1,7 +1,9 @@
 #!/bin/bash
 
-# Usage:
-# ./cpu-gather.py | ./cpu-parse.sh
+if [ -z "${CPU_GATHER_PY}" ]; then
+    echo >&2 "Do not call this script directly. Use 'cpu-gather.py' instead."
+    exit 1
+fi
 
 data=`cat`