Skip to content

Commit

Permalink
rpc: support python 2.6
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
joejulian committed Oct 27, 2016
1 parent 65e4629 commit c5eb1c5
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions splitmount/rpc.py
Expand Up @@ -23,9 +23,51 @@
import ctypes.util
import os
import subprocess
import sys

# Monkeypatch subprocess for 2.6
if sys.version_info[:2] == (2,6):
try:
from subprocess import STDOUT, check_output, CalledProcessError
except ImportError: # pragma: no cover
# python 2.6 doesn't include check_output
# monkey patch it in!
import subprocess
STDOUT = subprocess.STDOUT

def check_output(*popenargs, **kwargs):
if 'stdout' in kwargs: # pragma: no cover
raise ValueError('stdout argument not allowed, '
'it will be overridden.')
process = subprocess.Popen(stdout=subprocess.PIPE,
*popenargs, **kwargs)
output, _ = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise subprocess.CalledProcessError(retcode, cmd,
output=output)
return output
subprocess.check_output = check_output

# overwrite CalledProcessError due to `output`
# keyword not being available (in 2.6)
class CalledProcessError(Exception):

def __init__(self, returncode, cmd, output=None):
self.returncode = returncode
self.cmd = cmd
self.output = output

def __str__(self):
return "Command '%s' returned non-zero exit status %d" % (
self.cmd, self.returncode)
subprocess.CalledProcessError = CalledProcessError

def cli_get_volfile (host, volume):
res = subprocess.check_output(["/usr/sbin/gluster","--remote-host={}".format(host),
res = subprocess.check_output(["/usr/sbin/gluster","--remote-host={0}".format(host),
"system","getspec",volume])
return res

Expand Down Expand Up @@ -90,5 +132,5 @@ def api_get_volfile (host, volume):
for line in res.split(u'\n'):
print(line)
except:
print("bad return value {}".format(res))
print("bad return value {0}".format(res))
raise

0 comments on commit c5eb1c5

Please sign in to comment.