fix cowsay for py3

This commit is contained in:
Brian Coca 2017-01-30 15:16:15 -05:00
commit a26c771bd9

View file

@ -84,7 +84,7 @@ class Display:
try: try:
cmd = subprocess.Popen([self.b_cowsay, "-l"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd = subprocess.Popen([self.b_cowsay, "-l"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = cmd.communicate() (out, err) = cmd.communicate()
self.cows_available = set([ to_bytes(c) for c in out.split() ]) self.cows_available = set([ to_text(c) for c in out.split() ])
if C.ANSIBLE_COW_WHITELIST: if C.ANSIBLE_COW_WHITELIST:
self.cows_available = set(C.ANSIBLE_COW_WHITELIST).intersection(self.cows_available) self.cows_available = set(C.ANSIBLE_COW_WHITELIST).intersection(self.cows_available)
except: except:
@ -246,10 +246,10 @@ class Display:
runcmd = [self.b_cowsay, b"-W", b"60"] runcmd = [self.b_cowsay, b"-W", b"60"]
if self.noncow: if self.noncow:
thecow = self.noncow thecow = self.noncow
if thecow == b'random': if thecow == 'random':
thecow = random.choice(self.cows_available) thecow = random.choice(list(self.cows_available))
runcmd.append(b'-f') runcmd.append(b'-f')
runcmd.append(thecow) runcmd.append(to_bytes(thecow))
runcmd.append(to_bytes(msg)) runcmd.append(to_bytes(msg))
cmd = subprocess.Popen(runcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) cmd = subprocess.Popen(runcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = cmd.communicate() (out, err) = cmd.communicate()