From dad18f816478ec16f38dd3ccd42b6f282d02632b Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Wed, 9 Jan 2013 15:15:01 -0600 Subject: [PATCH] * usr/bin/byobu-select-session: - update python code for python3 compatibility --- debian/changelog | 2 ++ usr/bin/byobu-select-session | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/debian/changelog b/debian/changelog index b079489a..409b8044 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ byobu (5.25) unreleased; urgency=low * usr/bin/byobu-config, usr/bin/byobu-ctrl-a, usr/share/doc/byobu/help.screen.txt: - update python code for python3 compatibility + * usr/bin/byobu-select-session: + - update python code for python3 compatibility -- Dustin Kirkland Wed, 09 Jan 2013 09:49:47 -0600 diff --git a/usr/bin/byobu-select-session b/usr/bin/byobu-select-session index 049243e1..ec86e4e2 100755 --- a/usr/bin/byobu-select-session +++ b/usr/bin/byobu-select-session @@ -20,7 +20,6 @@ # along with this program. If not, see . -import commands import os import re import sys @@ -42,24 +41,26 @@ def get_sessions(): sessions = [] i = 0 if BYOBU_BACKEND == "screen": - output = commands.getstatusoutput("screen -ls") - if output[0] >= 0: - for s in output[1].split("\n"): + output = subprocess.check_output(["screen", "-ls"]) + output = output.decode(sys.stdout.encoding) + if output: + for s in output.splitlines(): s = re.sub(r'\s+', ' ', s) # Ignore hidden sessions (named sessions that start with a ".") - if (s.find(" ") == 0 and len(s) > 1 and s.count("..") == 0): + if s and (s.find(" ") == 0 and len(s) > 1 and s.count("..") == 0): text.append("screen: %s" % s.strip()) items = s.split(" ") sessions.append("screen____%s" % items[1]) i += 1 if BYOBU_BACKEND == "tmux": - output = commands.getstatusoutput("tmux list-sessions") - if output[0] == 0: - for s in output[1].split("\n"): - text.append("tmux: %s" % s.strip()) - items = s.split(":") - sessions.append("tmux____%s" % items[0]) - i += 1 + output = subprocess.check_output(["tmux", "list-sessions"]) + output = output.decode(sys.stdout.encoding) + if output: + for s in output.splitlines(): + if s: + text.append("tmux: %s" % s.strip()) + sessions.append("tmux____%s" % s.split(":")[0]) + i += 1 return sessions @@ -72,7 +73,7 @@ def update_environment(session): cmd = ["tmux", "setenv", "-t", session_name, var, value] else: cmd = ["screen", "-S", session_name, "-X", "setenv", var, value] - print "Sending variable: %s" % (cmd, ) + print("Sending variable: %s" % (cmd, )) subprocess.call(cmd, stdout=open(os.devnull, "w")) @@ -104,7 +105,7 @@ if len(sessions) > 1: sys.stdout.write(" %d. %s\n" % (i, s)) i += 1 try: - choice = int(raw_input("\nChoose 1-%d [1]: " % (i - 1))) + choice = int(input("\nChoose 1-%d [1]: " % (i - 1))) if choice >= 1 and choice < i: break else: @@ -112,7 +113,7 @@ if len(sessions) > 1: choice = "" sys.stderr.write("\nERROR: Invalid input\n") except KeyboardInterrupt: - print + print() sys.exit(0) except: if choice == "":