From 1f3c0913eae5f9d4d3738f61e0467b59683e132c Mon Sep 17 00:00:00 2001 From: James Guthrie Date: Fri, 22 May 2015 16:59:58 +0200 Subject: [PATCH] Decouple backend exec from python Current backends (pox, ryu) are python-based, so executing them through python works, but it ties the frontend and backend to the same python version. This change should make it easier to move pyretic to python3 independent of the backend python version. --- pyretic.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pyretic.py b/pyretic.py index 52526bed..e91114de 100755 --- a/pyretic.py +++ b/pyretic.py @@ -197,22 +197,28 @@ def log_writer(queue, log_level): if backend_path is None: print 'Error: {} not found in PYTHONPATH'.format(backend_client) sys.exit(1) - backend_exec = os.path.join(backend_path,'pox.py') + # Pox is still py2-only + if sys.version_info[0] == 2: + python = sys.executable + else: + python = which("python2") + if not python: + print "Error: Could not find 'python2' in path." + sys.exit(1) + backend_exec = [python, os.path.join(backend_path, 'pox.py'), backend_client] elif options.backend == 'ryu': backend_client = 'of_client.ryu_shim' - backend_exec = which('ryu-manager') - if not backend_exec: + ryu_exec = which('ryu-manager') + if not ryu_exec: print "Error: Could not find 'ryu-manager' in path. Is ryu installed?" + backend_exec = [ryu_exec, backend_client] else: print "Error: Invalid backend '{}' specified".format(options.backend) sys.exit(1) - python=sys.executable # TODO(josh): pipe backend stdout to subprocess.PIPE or # other log file descriptor if necessary - of_client = subprocess.Popen([python, - backend_exec, - backend_client ], + of_client = subprocess.Popen(backend_exec, stdout=sys.stdout, stderr=subprocess.STDOUT)