* debian/control, debian/rules, usr/bin/byobu-config, usr/bin/byobu-

select-session: LP: #1043048
  - get our python code pep8 compliant
    + except use tabs instead of spaces, and allow lines longer than
      80 characters
  - this should get byobu's python code working better with python3
This commit is contained in:
Dustin Kirkland 2013-01-08 22:30:04 -06:00
commit f541a82be9
5 changed files with 322 additions and 275 deletions

6
debian/changelog vendored
View file

@ -27,6 +27,12 @@ byobu (5.23) unreleased; urgency=low
- simplify, removing detail - simplify, removing detail
* usr/lib/byobu/distro, usr/lib/byobu/logo: LP: #1094716 * usr/lib/byobu/distro, usr/lib/byobu/logo: LP: #1094716
- try to improve logo printing and distro detection on Mac - try to improve logo printing and distro detection on Mac
* debian/control, debian/rules, usr/bin/byobu-config, usr/bin/byobu-
select-session: LP: #1043048
- get our python code pep8 compliant
+ except use tabs instead of spaces, and allow lines longer than
80 characters
- this should get byobu's python code working better with python3
[ Dustin Kirkland and Philip Muškovac ] [ Dustin Kirkland and Philip Muškovac ]
* usr/lib/byobu/battery: LP: #1090831 * usr/lib/byobu/battery: LP: #1090831

2
debian/control vendored
View file

@ -5,7 +5,7 @@ Maintainer: Dustin Kirkland <kirkland@ubuntu.com>
DM-Upload-Allowed: yes DM-Upload-Allowed: yes
Uploaders: Antoine Beaupré <anarcat@koumbit.org> Uploaders: Antoine Beaupré <anarcat@koumbit.org>
Standards-Version: 3.9.3 Standards-Version: 3.9.3
Build-Depends: debhelper (>= 7.0.50~), gettext-base, automake, autoconf Build-Depends: debhelper (>= 7.0.50~), gettext-base, automake, autoconf, pep8
Homepage: http://byobu.co Homepage: http://byobu.co
Vcs-Bzr: http://bazaar.launchpad.net/~kirkland/byobu/trunk Vcs-Bzr: http://bazaar.launchpad.net/~kirkland/byobu/trunk

5
debian/rules vendored
View file

@ -2,6 +2,11 @@
%: %:
dh $@ dh $@
override_dh_auto_build:
# Check syntax
pep8 --verbose --repeat --ignore W191,E501 usr/bin/byobu-config usr/bin/byobu-select-session
dh_auto_build
override_dh_perl: override_dh_perl:
dh_perl -d dh_perl -d

View file

@ -21,8 +21,15 @@
# If you change any strings, please generate localization information with: # If you change any strings, please generate localization information with:
# ./debian/rules get-po # ./debian/rules get-po
import sys
import sys, os, os.path, time, string, commands, gettext, glob, snack import os
import os.path
import time
import string
import commands
import gettext
import glob
import snack
from ConfigParser import SafeConfigParser from ConfigParser import SafeConfigParser
from snack import * from snack import *
@ -54,14 +61,20 @@ gettext.bindtextdomain(PKG, SHARE+'/po')
gettext.textdomain(PKG) gettext.textdomain(PKG)
_ = gettext.gettext _ = gettext.gettext
def ioctl_GWINSZ(fd): #### TABULATION FUNCTIONS
try: ### Discover terminal width def ioctl_GWINSZ(fd):
import fcntl, termios, struct, os # Discover terminal width
try:
import fcntl
import termios
import struct
import os
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')) cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
except: except:
return None return None
return cr return cr
def reload_required(): def reload_required():
try: try:
if not os.path.exists(BYOBU_CONFIG_DIR): if not os.path.exists(BYOBU_CONFIG_DIR):
@ -72,21 +85,28 @@ def reload_required():
except: except:
True True
def terminal_size(): ### decide on *some* terminal size
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) # try open fds def terminal_size():
if not cr: # ...then ctty # decide on some terminal size
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
# try open fds
if not cr:
# ...then ctty
try: try:
fd = os.open(os.ctermid(), os.O_RDONLY) fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd) cr = ioctl_GWINSZ(fd)
os.close(fd) os.close(fd)
except: except:
pass pass
if not cr: # env vars or finally defaults if not cr:
# env vars or finally defaults
try: try:
cr = (env['LINES'], env['COLUMNS']) cr = (env['LINES'], env['COLUMNS'])
except: except:
cr = (25, 80) cr = (25, 80)
return int(cr[1]-5), int(cr[0]-5) # reverse rows, cols # reverse rows, cols
return int(cr[1] - 5), int(cr[0] - 5)
def menu(snackScreen, size, isInstalled): def menu(snackScreen, size, isInstalled):
if isInstalled: if isInstalled:
@ -107,8 +127,8 @@ def menu(snackScreen, size, isInstalled):
else: else:
return li.current() return li.current()
def messagebox(snackScreen, width, height, title, text, scroll=0, \
buttons=((_("Okay"), "okay"),(_("Cancel"), "cancel", ESC)) ): def messagebox(snackScreen, width, height, title, text, scroll=0, buttons=((_("Okay"), "okay"), (_("Cancel"), "cancel", ESC))):
t = Textbox(width, height, text, scroll=scroll) t = Textbox(width, height, text, scroll=scroll)
bb = ButtonBar(snackScreen, buttons, compact=1) bb = ButtonBar(snackScreen, buttons, compact=1)
g = GridForm(snackScreen, title, 1, 2) g = GridForm(snackScreen, title, 1, 2)
@ -116,6 +136,7 @@ def messagebox(snackScreen, width, height, title, text, scroll=0, \
g.add(bb, 0, 1, padding=(1, 1, 0, 0)) g.add(bb, 0, 1, padding=(1, 1, 0, 0))
return bb.buttonPressed(g.runOnce()) return bb.buttonPressed(g.runOnce())
def help(snackScreen, size, config): def help(snackScreen, size, config):
f = file(DOC + '/help.' + BYOBU_BACKEND + '.txt') f = file(DOC + '/help.' + BYOBU_BACKEND + '.txt')
text = f.read() text = f.read()
@ -130,6 +151,7 @@ def help(snackScreen, size, config):
button = bb.buttonPressed(g.runOnce()) button = bb.buttonPressed(g.runOnce())
return 100 return 100
def readstatus(): def readstatus():
status = {} status = {}
glo = {} glo = {}
@ -158,6 +180,7 @@ def readstatus():
li.append(window) li.append(window)
return li return li
def genstatusstring(s, status): def genstatusstring(s, status):
new = "" new = ""
glo = {} glo = {}
@ -172,6 +195,7 @@ def genstatusstring(s, status):
new += " #" + i new += " #" + i
return new return new
def writestatus(items): def writestatus(items):
status = {} status = {}
path = BYOBU_CONFIG_DIR + '/status' path = BYOBU_CONFIG_DIR + '/status'
@ -189,6 +213,7 @@ def writestatus(items):
commands.getoutput("%s -i -e '/^%s=/d' %s" % (BYOBU_SED, key, path)) commands.getoutput("%s -i -e '/^%s=/d' %s" % (BYOBU_SED, key, path))
commands.getoutput("echo '%s=\"%s\"' >> %s" % (key, val, path)) commands.getoutput("echo '%s=\"%s\"' >> %s" % (key, val, path))
def togglestatus(snackScreen, size): def togglestatus(snackScreen, size):
itemlist = readstatus() itemlist = readstatus()
rl = Label("") rl = Label("")
@ -213,6 +238,7 @@ def togglestatus(snackScreen, size):
reload_required() reload_required()
return 100 return 100
def install(snackScreen, size, isInstalled): def install(snackScreen, size, isInstalled):
if isInstalled: if isInstalled:
out = commands.getoutput("byobu-launcher-uninstall") out = commands.getoutput("byobu-launcher-uninstall")
@ -227,6 +253,7 @@ def install(snackScreen, size, isInstalled):
button = messagebox(snackScreen, 60, 2, "Message", out, buttons=((_("Menu"), ))) button = messagebox(snackScreen, 60, 2, "Message", out, buttons=((_("Menu"), )))
return 100 return 100
def appendtofile(p, s): def appendtofile(p, s):
f = open(p, 'a') f = open(p, 'a')
try: try:
@ -237,6 +264,7 @@ def appendtofile(p, s):
f.close() f.close()
return return
def getesckey(): def getesckey():
if BYOBU_BACKEND == "tmux": if BYOBU_BACKEND == "tmux":
path = BYOBU_CONFIG_DIR + '/keybindings.tmux' path = BYOBU_CONFIG_DIR + '/keybindings.tmux'
@ -253,10 +281,12 @@ def getesckey():
esc = " " esc = " "
return esc return esc
def setesckey(key): def setesckey(key):
if key.isalpha(): if key.isalpha():
out = commands.getoutput("byobu-ctrl-a screen %s" % key) out = commands.getoutput("byobu-ctrl-a screen %s" % key)
def chgesc(snackScreen, size): def chgesc(snackScreen, size):
esc = Entry(2, text=getesckey(), returnExit=1) esc = Entry(2, text=getesckey(), returnExit=1)
escl = Label(_("Escape key: ctrl-")) escl = Label(_("Escape key: ctrl-"))
@ -294,6 +324,7 @@ def chgesc(snackScreen, size):
return 0 return 0
return 100 return 100
def autolaunch(): def autolaunch():
if os.path.exists(BYOBU_CONFIG_DIR + "/disable-autolaunch"): if os.path.exists(BYOBU_CONFIG_DIR + "/disable-autolaunch"):
return 0 return 0
@ -305,8 +336,7 @@ def autolaunch():
def main(): def main():
"""This is the main loop of our utility """This is the main loop of our utility"""
"""
size = terminal_size() size = terminal_size()
snackScreen = SnackScreen() snackScreen = SnackScreen()
snackScreen.drawRootText(1, 0, _('Byobu Configuration Menu')) snackScreen.drawRootText(1, 0, _('Byobu Configuration Menu'))
@ -329,4 +359,5 @@ def main():
sys.exit(0) sys.exit(0)
if __name__ == "__main__": main() if __name__ == "__main__":
main()

View file

@ -20,7 +20,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import commands, os, re, sys, subprocess import commands
import os
import re
import sys
import subprocess
PKG = "byobu" PKG = "byobu"
SHELL = os.getenv("SHELL", "/bin/bash") SHELL = os.getenv("SHELL", "/bin/bash")
@ -31,9 +35,8 @@ choice = ""
sessions = [] sessions = []
text = [] text = []
BYOBU_UPDATE_ENVVARS=["DISPLAY", "DBUS_SESSION_BUS_ADDRESS", "SESSION_MANAGER", "GPG_AGENT_INFO", BYOBU_UPDATE_ENVVARS = ["DISPLAY", "DBUS_SESSION_BUS_ADDRESS", "SESSION_MANAGER", "GPG_AGENT_INFO", "XDG_SESSION_COOKIE", "XDG_SESSION_PATH", "GNOME_KEYRING_CONTROL", "GNOME_KEYRING_PID", "GPG_AGENT_INFO", "SSH_AUTH_SOCK", "SSH_AGENT_PID"]
"XDG_SESSION_COOKIE", "XDG_SESSION_PATH", "GNOME_KEYRING_CONTROL",
"GNOME_KEYRING_PID", "GPG_AGENT_INFO", "SSH_AUTH_SOCK", "SSH_AGENT_PID"]
def get_sessions(): def get_sessions():
sessions = [] sessions = []
@ -59,6 +62,7 @@ def get_sessions():
i += 1 i += 1
return sessions return sessions
def update_environment(session): def update_environment(session):
backend, session_name = session.split("____", 2) backend, session_name = session.split("____", 2)
for var in BYOBU_UPDATE_ENVVARS: for var in BYOBU_UPDATE_ENVVARS:
@ -71,6 +75,7 @@ def update_environment(session):
print "Sending variable: %s" % (cmd, ) print "Sending variable: %s" % (cmd, )
subprocess.call(cmd, stdout=open(os.devnull, "w")) subprocess.call(cmd, stdout=open(os.devnull, "w"))
def attach_session(session): def attach_session(session):
print("Attaching: [%s]\n" % session) print("Attaching: [%s]\n" % session)
update_environment(session) update_environment(session)
@ -105,7 +110,7 @@ if len(sessions) > 1:
else: else:
tries += 1 tries += 1
choice = "" choice = ""
sys.stderr.write("\nERROR: Invalid input\n"); sys.stderr.write("\nERROR: Invalid input\n")
except KeyboardInterrupt: except KeyboardInterrupt:
print print
sys.exit(0) sys.exit(0)
@ -115,7 +120,7 @@ if len(sessions) > 1:
break break
tries += 1 tries += 1
choice = "" choice = ""
sys.stderr.write("\nERROR: Invalid input\n"); sys.stderr.write("\nERROR: Invalid input\n")
elif len(sessions) == 1: elif len(sessions) == 1:
# Auto-select the only session # Auto-select the only session
choice = 1 choice = 1