From 10652212dfa04427d82103012c1f434a94264c1a Mon Sep 17 00:00:00 2001
From: Merlin Mathesius <merlinm@redhat.com>
Date: Aug 14 2017 15:58:17 +0000
Subject: Make python code version 2/3 agnostic.


---

diff --git a/inventory/standard-inventory-docker b/inventory/standard-inventory-docker
index 81c44a0..b8d625d 100755
--- a/inventory/standard-inventory-docker
+++ b/inventory/standard-inventory-docker
@@ -30,7 +30,7 @@ def main(argv):
         else:
             data = list(opts.subjects, opts.docker_extra_args)
         sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))
-    except RuntimeError, ex:
+    except RuntimeError as ex:
         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))
         return 1
 
@@ -81,7 +81,7 @@ def host(image, docker_extra_args):
     ]
     try:
         subprocess.check_call(cmd, stdout=sys.stderr.fileno())
-    except subprocess.CalledProcessError, ex:
+    except subprocess.CalledProcessError as ex:
         raise RuntimeError("Could not start docker service")
 
     # And launch the actual container
@@ -92,7 +92,7 @@ def host(image, docker_extra_args):
     ]
     try:
         subprocess.check_call(cmd, stdout=sys.stderr.fileno())
-    except subprocess.CalledProcessError, ex:
+    except subprocess.CalledProcessError as ex:
         raise RuntimeError("Could not start container image: {0}".format(image))
 
     # Read out the container environment variable
@@ -113,7 +113,7 @@ def host(image, docker_extra_args):
     ]
     try:
         subprocess.check_call(install, stdout=sys.stderr.fileno())
-    except subprocess.CalledProcessError, ex:
+    except subprocess.CalledProcessError as ex:
         raise RuntimeError("Could not install Ansible dependencies in launched container")
 
     # Directory to place artifacts
diff --git a/inventory/standard-inventory-local b/inventory/standard-inventory-local
index 14c52a9..6482bec 100755
--- a/inventory/standard-inventory-local
+++ b/inventory/standard-inventory-local
@@ -18,7 +18,7 @@ def main(argv):
         else:
             data = list()
         sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))
-    except RuntimeError, ex:
+    except RuntimeError as ex:
         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))
         return 1
 
diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2
index 52112cf..9ab2a5f 100755
--- a/inventory/standard-inventory-qcow2
+++ b/inventory/standard-inventory-qcow2
@@ -71,7 +71,7 @@ def main(argv):
         else:
             data = list(opts.subjects)
         sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))
-    except RuntimeError, ex:
+    except RuntimeError as ex:
         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))
         return 1
 
@@ -118,7 +118,7 @@ def host(image):
     identity = os.path.join(directory, "identity")
     with open(identity, 'w') as f:
         f.write(IDENTITY)
-    os.chmod(identity, 0600)
+    os.chmod(identity, 0o600)
     metadata = os.path.join(directory, "meta-data")
     with open(metadata, 'w') as f:
         f.write("")
diff --git a/inventory/standard-inventory-rpm b/inventory/standard-inventory-rpm
index 0a475d3..31ca4a6 100755
--- a/inventory/standard-inventory-rpm
+++ b/inventory/standard-inventory-rpm
@@ -20,7 +20,7 @@ def main(argv):
         else:
             data = list(opts.subjects)
         sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))
-    except RuntimeError, ex:
+    except RuntimeError as ex:
         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))
         return 1
 
diff --git a/roles/standard-test-beakerlib/files/rpm.py b/roles/standard-test-beakerlib/files/rpm.py
index dade015..83093be 100644
--- a/roles/standard-test-beakerlib/files/rpm.py
+++ b/roles/standard-test-beakerlib/files/rpm.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
 # The purpose of this file is to satisfy /usr/bin/beakerlib-journalling use of "import rpm",
 # particularly on Atomic Host which doesn't have python2-rpm package. beakerlib-journalling
diff --git a/scripts/merge-standard-inventory b/scripts/merge-standard-inventory
index 64fcdc1..4ee0bf0 100755
--- a/scripts/merge-standard-inventory
+++ b/scripts/merge-standard-inventory
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/env python
 
 import json
 import os
@@ -37,7 +37,7 @@ def main(argv):
         merged_data = merge_standard_inventories(argv[1:])
 
         # send merged data to parent via output pipe
-        os.write(pipeout, merged_data)
+        os.write(pipeout, merged_data.encode('utf-8'))
 
         # close the pipe so the parent knows we are done
         os.close(pipeout)
@@ -59,7 +59,7 @@ def main(argv):
         if not data:
             os.close(pipein)
             break
-        sys.stdout.write(data)
+        sys.stdout.write(data.decode('utf-8'))
 
     return 0
 
@@ -89,7 +89,7 @@ def merge_standard_inventories(args):
         except subprocess.CalledProcessError as ex:
             raise RuntimeError("Could not run: {0}".format(str(cmd)))
 
-        merged.merge(inv_out)
+        merged.merge(inv_out.decode('utf-8'))
 
     return merged.dumps()
 

