From 21c1ba9e3fe0f52f636a6ead17043438b5545e80 Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 27 Jun 2015 02:05:49 +0300 Subject: [PATCH 01/39] Make new powerline release ebuilds symlinks Note: not powerline-vim, it is not prepared for this. --- scripts/powerline-release.py | 60 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/scripts/powerline-release.py b/scripts/powerline-release.py index 65d46b63..42381bde 100755 --- a/scripts/powerline-release.py +++ b/scripts/powerline-release.py @@ -147,38 +147,42 @@ def create_ebuilds(version_string, overlay, user, **kwargs): live_ebuild = None for ebuild in os.listdir(pdir): if ebuild.endswith('.ebuild') and '9999' in ebuild: + live_ebuild_base = ebuild live_ebuild = os.path.join(pdir, ebuild) break assert(live_ebuild) vcur = os.path.join(pdir, '{0}-{1}.ebuild'.format(pn, version_string)) - with open(live_ebuild) as LEF: - with open(vcur, 'w') as F: - dropnext = False - for line in LEF: - if line.startswith('EGIT'): - # Drop all EGIT_… and the next empty line - dropnext = True - next_re = re.compile('^$') - continue - if dropnext: - assert(next_re.match(line)) - dropnext = False - continue - if line.startswith('# Note the lack of an assignment to ${S}'): - next_re = re.compile('^#') - dropnext = True - line = 'S="${WORKDIR}/${MY_P}"\n' - if line.startswith('inherit'): - line = line.replace(' git-r3', '') - line += '\n' - line += 'MY_PN="powerline-status"\n' - line += 'MY_P="${MY_PN}-${PV}"' - line += '\n' - elif line.startswith('HOMEPAGE'): - line += 'SRC_URI="mirror://pypi/p/${MY_PN}/${MY_P}.tar.gz"\n' - elif line.startswith('KEYWORDS'): - line = 'KEYWORDS="~amd64 ~ppc ~x86 ~x86-fbsd"\n' - F.write(line) + if pn == 'powerline-vim': + with open(live_ebuild) as LEF: + with open(vcur, 'w') as F: + dropnext = False + for line in LEF: + if line.startswith('EGIT'): + # Drop all EGIT_… and the next empty line + dropnext = True + next_re = re.compile('^$') + continue + if dropnext: + assert(next_re.match(line)) + dropnext = False + continue + if line.startswith('# Note the lack of an assignment to ${S}'): + next_re = re.compile('^#') + dropnext = True + line = 'S="${WORKDIR}/${MY_P}"\n' + if line.startswith('inherit'): + line = line.replace(' git-r3', '') + line += '\n' + line += 'MY_PN="powerline-status"\n' + line += 'MY_P="${MY_PN}-${PV}"' + line += '\n' + elif line.startswith('HOMEPAGE'): + line += 'SRC_URI="mirror://pypi/p/${MY_PN}/${MY_P}.tar.gz"\n' + elif line.startswith('KEYWORDS'): + line = 'KEYWORDS="~amd64 ~ppc ~x86 ~x86-fbsd"\n' + F.write(line) + else: + os.symlink(live_ebuild_base, vcur) new_files.append(vcur) check_call(['ebuild', vcur, 'manifest']) new_files.append(os.path.join(pdir, 'Manifest')) From dbe7e16520e187090e2f8b8622c168d74bcf5561 Mon Sep 17 00:00:00 2001 From: Foo Date: Mon, 6 Jul 2015 21:13:14 +0300 Subject: [PATCH 02/39] Do not use tcsh from deps Tcsh was unmasked according to travis-ci/travis-ci#3882 and can now be installed by travis. --- .travis.yml | 2 +- tests/test.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 920141cf..3e40c64f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - libssl1.0.0 - zsh - # - tcsh + - tcsh # - mksh # - busybox # - rc diff --git a/tests/test.sh b/tests/test.sh index 6fe9ade7..0d462dc9 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -13,7 +13,6 @@ if test "$TRAVIS" = true ; then export PATH="$PWD/tests/bot-ci/deps/rc:$PATH" export PATH="$PWD/tests/bot-ci/deps/mksh:$PATH" export PATH="$PWD/tests/bot-ci/deps/busybox:$PATH" - export PATH="$PWD/tests/bot-ci/deps/tcsh:$PATH" export PATH="$PWD/tests/bot-ci/deps/socat:$PATH" if test "$PYTHON_IMPLEMENTATION" = "CPython" ; then From c184b2be12b1626d3f3cf8cf2bf6d5199346f2a3 Mon Sep 17 00:00:00 2001 From: Foo Date: Thu, 9 Jul 2015 22:54:49 +0300 Subject: [PATCH 03/39] Also do not use bot-ci mksh, busybox and socat dependencies All of them were whitelisted: - Mksh was whitelisted in travis-ci/travis-ci#3881. - Busybox was whitelisted in travis-ci/travis-ci#3880. - Socat was whitelisted in travis-ci/travis-ci#3883. --- .travis.yml | 6 +++--- tests/test.sh | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3e40c64f..01429651 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,10 @@ addons: - libssl1.0.0 - zsh - tcsh - # - mksh - # - busybox + - mksh + - busybox # - rc - # - socat + - socat - bc language: python install: tests/install.sh diff --git a/tests/test.sh b/tests/test.sh index 0d462dc9..e2e69dc0 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -11,9 +11,6 @@ FAILED=0 if test "$TRAVIS" = true ; then export PATH="$HOME/opt/fish/bin:${PATH}" export PATH="$PWD/tests/bot-ci/deps/rc:$PATH" - export PATH="$PWD/tests/bot-ci/deps/mksh:$PATH" - export PATH="$PWD/tests/bot-ci/deps/busybox:$PATH" - export PATH="$PWD/tests/bot-ci/deps/socat:$PATH" if test "$PYTHON_IMPLEMENTATION" = "CPython" ; then export PATH="$HOME/opt/zsh-${PYTHON_MM}${USE_UCS2_PYTHON:+-ucs2}/bin:${PATH}" From 26ea5f0f0042dc59b6ca62888156885aba093f03 Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 18 Jul 2015 16:55:04 +0300 Subject: [PATCH 04/39] Fix error message when inotify limits were hit --- powerline/lib/inotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerline/lib/inotify.py b/powerline/lib/inotify.py index 174d88f8..8b74a7f1 100644 --- a/powerline/lib/inotify.py +++ b/powerline/lib/inotify.py @@ -134,7 +134,7 @@ class INotify(object): eno = ctypes.get_errno() extra = '' if eno == errno.ENOSPC: - extra = 'You may need to increase the inotify limits on your system, via /proc/sys/inotify/max_user_*' + extra = 'You may need to increase the inotify limits on your system, via /proc/sys/fs/inotify/max_user_*' raise OSError(eno, self.os.strerror(eno) + str(extra)) def __del__(self): From 24dbf042a26036da17f5a996cd4232dfea699e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= Date: Sun, 19 Jul 2015 11:00:04 +0200 Subject: [PATCH 05/39] docs: allow outside of Makefile variable assignment This allow packagers to select the sphinx-build command version (python2 or python3) without changing the Makefile: $ SPHINXBUILD=sphinx-build2 SPHINXOPTS=... make man --- docs/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index 3b412210..c686ed80 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,8 +1,8 @@ # Makefile for Sphinx documentation -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = _build +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +PAPER ?= +BUILDDIR ?= _build # Internal variables PAPEROPT_a4 = -D latex_paper_size=a4 From 9ce7fa306388457e4f90f19945651610d01f8b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= Date: Sun, 19 Jul 2015 11:05:15 +0200 Subject: [PATCH 06/39] docs: fix manpage generation with python3 Python2 manpage generation seems unaffected. Warnings occur when generating with python3: .../docs/source/configuration/segments/vim.rst:27: WARNING: error while formatting arguments for powerline.segments.vim.plugin.tagbar.current_tag: decoding str is not supported --- docs/source/powerline_automan.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/powerline_automan.py b/docs/source/powerline_automan.py index b4e1a14f..1f79001a 100644 --- a/docs/source/powerline_automan.py +++ b/docs/source/powerline_automan.py @@ -7,6 +7,8 @@ import codecs from collections import namedtuple +from functools import reduce + from docutils.parsers.rst import Directive from docutils.parsers.rst.directives import unchanged_required from docutils import nodes From 9b71beb17f453b0b38e04fafcc26ee88499ea534 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 19 Jul 2015 14:40:39 +0300 Subject: [PATCH 07/39] Workaround tmux bug: additional space in display -p '#D' output Fixes #1412 --- powerline/bindings/tmux/powerline-base.conf | 4 ++-- powerline/bindings/tmux/powerline_tmux_1.7_plus.conf | 4 ++-- powerline/bindings/tmux/powerline_tmux_1.8_plus.conf | 2 +- powerline/renderers/tmux.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/powerline/bindings/tmux/powerline-base.conf b/powerline/bindings/tmux/powerline-base.conf index 5900f9b4..4b1f1d67 100644 --- a/powerline/bindings/tmux/powerline-base.conf +++ b/powerline/bindings/tmux/powerline-base.conf @@ -2,11 +2,11 @@ set -g status on set -g status-utf8 on set -g status-interval 2 set -g status-left-length 20 -set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id=`tmux display -p "#D"`)' +set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id=\"`tmux display -p "#D"`\")' set -g status-right-length 150 set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER_SPACES#I #[$_POWERLINE_WINDOW_DIVIDER_COLOR]$_POWERLINE_LEFT_SOFT_DIVIDER#[default]#W $_POWERLINE_LEFT_HARD_DIVIDER_SPACES" set -g window-status-current-format "#[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#[$_POWERLINE_WINDOW_CURRENT_COLOR]#I $_POWERLINE_LEFT_SOFT_DIVIDER#[$_POWERLINE_WINDOW_NAME_COLOR]#W #[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER" # Legacy status-left definition to be overwritten for tmux Versions 1.8+ -set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left -R pane_id=`tmux display -p '#D'`)" +set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left -R pane_id=\"`tmux display -p '#D'`\")" # vim: ft=tmux diff --git a/powerline/bindings/tmux/powerline_tmux_1.7_plus.conf b/powerline/bindings/tmux/powerline_tmux_1.7_plus.conf index 6562b6a7..8c60294f 100644 --- a/powerline/bindings/tmux/powerline_tmux_1.7_plus.conf +++ b/powerline/bindings/tmux/powerline_tmux_1.7_plus.conf @@ -1,3 +1,3 @@ -set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id=`tmux display -p "#D"` --width=`tmux display -p "#{client_width}"` -R width_adjust=`tmux show-options -g status-left-length | cut -d" " -f 2`)' -set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left --width=`tmux display -p '#{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=`tmux display -p '#D'`)" +set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id="`tmux display -p "#D"`" --width=`tmux display -p "#{client_width}"` -R width_adjust=`tmux show-options -g status-left-length | cut -d" " -f 2`)' +set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left --width=`tmux display -p '#{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=\"`tmux display -p '#D'`\")" # vim: ft=tmux diff --git a/powerline/bindings/tmux/powerline_tmux_1.8_plus.conf b/powerline/bindings/tmux/powerline_tmux_1.8_plus.conf index f8f8a517..95d85ff4 100644 --- a/powerline/bindings/tmux/powerline_tmux_1.8_plus.conf +++ b/powerline/bindings/tmux/powerline_tmux_1.8_plus.conf @@ -1,5 +1,5 @@ # powerline_tmux_1.8_plus.conf # tmux Version 1.8 introduces the 'client_prefix' format variable, applicable # for versions 1.8+ -set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]$_POWERLINE_LEFT_HARD_DIVIDER#(env \$POWERLINE_COMMAND \$POWERLINE_COMMAND_ARGS tmux left --width=`tmux display -p '#{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=`tmux display -p '#D'`)" +set -qg status-left "#{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_FG]#[bg=$_POWERLINE_SESSION_PREFIX_BG]#[$_POWERLINE_SESSION_PREFIX_ATTR],#[fg=$_POWERLINE_SESSION_FG]#[bg=$_POWERLINE_SESSION_BG]#[$_POWERLINE_SESSION_ATTR]} #S #{?client_prefix,#[fg=$_POWERLINE_SESSION_PREFIX_BG],#[fg=$_POWERLINE_SESSION_BG]}#[bg=$_POWERLINE_BACKGROUND_BG]#[nobold]$_POWERLINE_LEFT_HARD_DIVIDER#(env \$POWERLINE_COMMAND \$POWERLINE_COMMAND_ARGS tmux left --width=`tmux display -p '#{client_width}'` -R width_adjust=`tmux show-options -g status-right-length | cut -d' ' -f2` -R pane_id=\"`tmux display -p '#D'`\")" # vim: ft=tmux diff --git a/powerline/renderers/tmux.py b/powerline/renderers/tmux.py index 9034999a..33556409 100644 --- a/powerline/renderers/tmux.py +++ b/powerline/renderers/tmux.py @@ -63,7 +63,7 @@ class TmuxRenderer(Renderer): if segment_info: r.update(segment_info) if 'pane_id' in r: - varname = 'TMUX_PWD_' + r['pane_id'].lstrip('%') + varname = 'TMUX_PWD_' + r['pane_id'].lstrip('% ') if varname in r['environ']: r['getcwd'] = lambda: r['environ'][varname] r['mode'] = mode From 67dc10d1244f459163bf888f669d703fbd472a38 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 19 Jul 2015 15:03:28 +0300 Subject: [PATCH 08/39] My variant of Vim documentation has moved to bitbucket pages --- docs/source/troubleshooting.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index 007d9367..16be8a83 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -244,8 +244,8 @@ highlighting groups are usually cleared, including those defined by powerline. To workaround this issue powerline hooks ``Colorscheme`` event, but when you source vimrc with ``BufWritePost`` (or any other) event, but without ``nested`` this event is not launched. See also `autocmd-nested -`_ -Vim documentation. +`_ Vim +documentation. Powerline loses color after saving any file ------------------------------------------- From 22e9dfd885ae7a3da9eee27f1ae798001b0afca0 Mon Sep 17 00:00:00 2001 From: Foo Date: Mon, 20 Jul 2015 08:18:47 +0300 Subject: [PATCH 09/39] Do not use ?= for defining macros To define make macros one may use make arguments, so inheriting them from environment is not needed. I also do not see nmake supporting `?=` (not sure that anybody will use this though). --- docs/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index c686ed80..3b412210 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,8 +1,8 @@ # Makefile for Sphinx documentation -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -PAPER ?= -BUILDDIR ?= _build +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build # Internal variables PAPEROPT_a4 = -D latex_paper_size=a4 From f098ed2fe0a444f5ba790d9a2cc8332c01203517 Mon Sep 17 00:00:00 2001 From: Fumihiro Xue Date: Wed, 1 Jul 2015 19:59:52 +0800 Subject: [PATCH 10/39] Add ac-charging indication for battery segment --- powerline/config_files/themes/ascii.json | 4 +- powerline/config_files/themes/powerline.json | 4 +- .../themes/powerline_unicode7.json | 4 +- powerline/config_files/themes/unicode.json | 4 +- .../config_files/themes/unicode_terminus.json | 4 +- .../themes/unicode_terminus_condensed.json | 4 +- powerline/segments/common/bat.py | 81 ++++++++++++------- tests/test_segments.py | 50 ++++++++++-- 8 files changed, 113 insertions(+), 42 deletions(-) diff --git a/powerline/config_files/themes/ascii.json b/powerline/config_files/themes/ascii.json index 9ba09c31..9e876734 100644 --- a/powerline/config_files/themes/ascii.json +++ b/powerline/config_files/themes/ascii.json @@ -51,7 +51,9 @@ "powerline.segments.common.bat.battery": { "args": { "full_heart": "O", - "empty_heart": "O" + "empty_heart": "O", + "online": "C", + "offline": " " } }, "powerline.segments.common.sys.uptime": { diff --git a/powerline/config_files/themes/powerline.json b/powerline/config_files/themes/powerline.json index 2bbe7bfd..c33b5c1f 100644 --- a/powerline/config_files/themes/powerline.json +++ b/powerline/config_files/themes/powerline.json @@ -50,7 +50,9 @@ "powerline.segments.common.bat.battery": { "args": { "full_heart": "♥", - "empty_heart": "♥" + "empty_heart": "♥", + "online": "⚡︎", + "offline": " " } }, "powerline.segments.common.sys.uptime": { diff --git a/powerline/config_files/themes/powerline_unicode7.json b/powerline/config_files/themes/powerline_unicode7.json index 2b0b0184..bfa86fe0 100644 --- a/powerline/config_files/themes/powerline_unicode7.json +++ b/powerline/config_files/themes/powerline_unicode7.json @@ -50,7 +50,9 @@ "powerline.segments.common.bat.battery": { "args": { "full_heart": "💙", - "empty_heart": "💛" + "empty_heart": "💛", + "online": "⚡️", + "offline": " " } }, "powerline.segments.common.sys.uptime": { diff --git a/powerline/config_files/themes/unicode.json b/powerline/config_files/themes/unicode.json index f6d6f5e5..eadfc870 100644 --- a/powerline/config_files/themes/unicode.json +++ b/powerline/config_files/themes/unicode.json @@ -50,7 +50,9 @@ "powerline.segments.common.bat.battery": { "args": { "full_heart": "♥", - "empty_heart": "♥" + "empty_heart": "♥", + "online": "⚡︎", + "offline": " " } }, "powerline.segments.common.sys.uptime": { diff --git a/powerline/config_files/themes/unicode_terminus.json b/powerline/config_files/themes/unicode_terminus.json index 5b0a165b..8c1e045a 100644 --- a/powerline/config_files/themes/unicode_terminus.json +++ b/powerline/config_files/themes/unicode_terminus.json @@ -50,7 +50,9 @@ "powerline.segments.common.bat.battery": { "args": { "full_heart": "♥", - "empty_heart": "♥" + "empty_heart": "♥", + "online": "⚡︎", + "offline": " " } }, "powerline.segments.common.sys.uptime": { diff --git a/powerline/config_files/themes/unicode_terminus_condensed.json b/powerline/config_files/themes/unicode_terminus_condensed.json index a725a470..1c567dc7 100644 --- a/powerline/config_files/themes/unicode_terminus_condensed.json +++ b/powerline/config_files/themes/unicode_terminus_condensed.json @@ -51,7 +51,9 @@ "powerline.segments.common.bat.battery": { "args": { "full_heart": "♥", - "empty_heart": "♥" + "empty_heart": "♥", + "online": "⚡︎", + "offline": " " } }, "powerline.segments.common.sys.uptime": { diff --git a/powerline/segments/common/bat.py b/powerline/segments/common/bat.py index 732d8e11..332829f9 100644 --- a/powerline/segments/common/bat.py +++ b/powerline/segments/common/bat.py @@ -12,7 +12,7 @@ from powerline.lib.shell import run_cmd # segment is imported into powerline.segments.common module. -def _get_battery(pl): +def _fetch_battery_info(pl): try: import dbus except ImportError: @@ -55,23 +55,31 @@ def _get_battery(pl): dbus.Interface(dev, dbus_interface=devinterface).Get( devtype_name, 'Percentage' - ) + ), + dbus.Interface(dev, dbus_interface=devinterface).Get( + devtype_name, + 'State' + ) == 1 ) pl.debug('Not using DBUS+UPower as no batteries were found') if os.path.isdir('/sys/class/power_supply'): linux_bat_fmt = '/sys/class/power_supply/{0}/capacity' + linux_ac_fmt = '/sys/class/power_supply/{0}/online' for linux_bat in os.listdir('/sys/class/power_supply'): cap_path = linux_bat_fmt.format(linux_bat) + online_path = linux_ac_fmt.format(linux_bat) if linux_bat.startswith('BAT') and os.path.exists(cap_path): pl.debug('Using /sys/class/power_supply with battery {0}', linux_bat) - def _get_capacity(pl): + def _get_battery_status(pl): with open(cap_path, 'r') as f: - return int(float(f.readline().split()[0])) - - return _get_capacity - pl.debug('Not using /sys/class/power_supply as no batteries were found') + _capacity = int(float(f.readline().split()[0])) + with open(online_path, 'r') as f: + _ac_powered = f.readline() == 1 + return _capacity, _ac_powered + return _get_battery_status + pl.debug('Not using /sys/class/power_supply as no batteries were found') else: pl.debug('Not using /sys/class/power_supply: no directory') @@ -86,12 +94,12 @@ def _get_battery(pl): BATTERY_PERCENT_RE = re.compile(r'(\d+)%') - def _get_capacity(pl): + def _get_battery_status(pl): battery_summary = run_cmd(pl, ['pmset', '-g', 'batt']) battery_percent = BATTERY_PERCENT_RE.search(battery_summary).group(1) - return int(battery_percent) - - return _get_capacity + ac_charging = 'AC' in battery_summary + return int(battery_percent), ac_charging + return _get_battery_status else: pl.debug('Not using pmset: executable not found') @@ -110,11 +118,11 @@ def _get_battery(pl): for battery in wmi.InstancesOf('Win32_Battery'): pl.debug('Using win32com.client with Win32_Battery') - def _get_capacity(pl): + def _get_battery_status(pl): # http://msdn.microsoft.com/en-us/library/aa394074(v=vs.85).aspx - return battery.EstimatedChargeRemaining + return battery.EstimatedChargeRemaining, battery.BatteryStatus == 6 - return _get_capacity + return _get_battery_status pl.debug('Not using win32com.client as no batteries were found') from ctypes import Structure, c_byte, c_ulong, byref if sys.platform == 'cygwin': @@ -136,41 +144,41 @@ def _get_battery(pl): ('BatteryFullLifeTime', c_ulong) ] - def _get_capacity(pl): + def _get_battery_status(pl): powerclass = PowerClass() result = library_loader.kernel32.GetSystemPowerStatus(byref(powerclass)) # http://msdn.microsoft.com/en-us/library/windows/desktop/aa372693(v=vs.85).aspx if result: return None - return powerclass.BatteryLifePercent + return powerclass.BatteryLifePercent, powerclass.ACLineStatus == 1 - if _get_capacity() is None: + if _get_battery_status() is None: pl.debug('Not using GetSystemPowerStatus because it failed') else: pl.debug('Using GetSystemPowerStatus') - return _get_capacity + return _get_battery_status raise NotImplementedError -def _get_capacity(pl): - global _get_capacity +def _get_battery_status(pl): + global _get_battery_status - def _failing_get_capacity(pl): + def _failing_get_status(pl): raise NotImplementedError try: - _get_capacity = _get_battery(pl) + _get_battery_status = _fetch_battery_info(pl) except NotImplementedError: - _get_capacity = _failing_get_capacity + _get_battery_status = _failing_get_status except Exception as e: - pl.exception('Exception while obtaining battery capacity getter: {0}', str(e)) - _get_capacity = _failing_get_capacity - return _get_capacity(pl) + pl.exception('Exception while obtaining battery status: {0}', str(e)) + _get_battery_status = _failing_get_status + return _get_battery_status(pl) -def battery(pl, format='{capacity:3.0%}', steps=5, gamify=False, full_heart='O', empty_heart='O'): +def battery(pl, format='{ac_state} {capacity:3.0%}', steps=5, gamify=False, full_heart='O', empty_heart='O', online='C', offline=' '): '''Return battery charge status. :param str format: @@ -189,21 +197,32 @@ def battery(pl, format='{capacity:3.0%}', steps=5, gamify=False, full_heart='O', another gradient level and highlighting group, so it is OK for it to be the same as full_heart as long as necessary highlighting groups are defined. + :param str online: + If computer is connected to a power supply this symbol is prepended to the segment. + :param str offline: + If computer is NOT connected to a power supply this symbol is prepended to the segment. ``battery_gradient`` and ``battery`` groups are used in any case, first is preferred. - Highlight groups used: ``battery_full`` or ``battery_gradient`` (gradient) or ``battery``, ``battery_empty`` or ``battery_gradient`` (gradient) or ``battery``. + Highlight groups used: ``battery_full`` or ``battery_gradient`` (gradient) or ``battery``, ``battery_empty`` or ``battery_gradient`` (gradient) or ``battery``, ``battery_online`` or ``battery_ac_state`` or ``battery_gradient`` (gradient) or ``battery``, ``battery_offline`` or ``battery_ac_state`` or ``battery_gradient`` (gradient) or ``battery``. ''' try: - capacity = _get_capacity(pl) + capacity, ac_powered = _get_battery_status(pl) except NotImplementedError: - pl.info('Unable to get battery capacity.') + pl.info('Unable to get battery status.') return None + ret = [] if gamify: denom = int(steps) numer = int(denom * capacity / 100) + ret.append({ + 'contents': online if ac_powered else offline, + 'draw_inner_divider': False, + 'highlight_groups': ['battery_online' if ac_powered else 'battery_offline', 'battery_ac_state', 'battery_gradient', 'battery'], + 'gradient_level': 0, + }) ret.append({ 'contents': full_heart * numer, 'draw_inner_divider': False, @@ -220,7 +239,7 @@ def battery(pl, format='{capacity:3.0%}', steps=5, gamify=False, full_heart='O', }) else: ret.append({ - 'contents': format.format(capacity=(capacity / 100.0)), + 'contents': format.format(ac_state=(online if ac_powered else offline), capacity=(capacity / 100.0)), 'highlight_groups': ['battery_gradient', 'battery'], # Gradients are “least alert – most alert” by default, capacity has # the opposite semantics. diff --git a/tests/test_segments.py b/tests/test_segments.py index ab56810b..c01dd6d5 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -881,12 +881,12 @@ class TestBat(TestCommon): def test_battery(self): pl = Pl() - def _get_capacity(pl): - return 86 + def _get_battery_status(pl): + return 86, False - with replace_attr(self.module, '_get_capacity', _get_capacity): + with replace_attr(self.module, '_get_battery_status', _get_battery_status): self.assertEqual(self.module.battery(pl=pl), [{ - 'contents': '86%', + 'contents': ' 86%', 'highlight_groups': ['battery_gradient', 'battery'], 'gradient_level': 14, }]) @@ -896,11 +896,17 @@ class TestBat(TestCommon): 'gradient_level': 14, }]) self.assertEqual(self.module.battery(pl=pl, steps=7), [{ - 'contents': '86%', + 'contents': ' 86%', 'highlight_groups': ['battery_gradient', 'battery'], 'gradient_level': 14, }]) self.assertEqual(self.module.battery(pl=pl, gamify=True), [ + { + 'contents': ' ', + 'draw_inner_divider': False, + 'highlight_groups': ['battery_offline', 'battery_ac_state', 'battery_gradient', 'battery'], + 'gradient_level': 0 + }, { 'contents': 'OOOO', 'draw_inner_divider': False, @@ -915,6 +921,12 @@ class TestBat(TestCommon): } ]) self.assertEqual(self.module.battery(pl=pl, gamify=True, full_heart='+', empty_heart='-', steps='10'), [ + { + 'contents': ' ', + 'draw_inner_divider': False, + 'highlight_groups': ['battery_offline', 'battery_ac_state', 'battery_gradient', 'battery'], + 'gradient_level': 0 + }, { 'contents': '++++++++', 'draw_inner_divider': False, @@ -929,6 +941,34 @@ class TestBat(TestCommon): } ]) + def test_battery_with_ac_online(self): + pl = Pl() + + def _get_battery_status(pl): + return 86, True + + with replace_attr(self.module, '_get_battery_status', _get_battery_status): + self.assertEqual(self.module.battery(pl=pl, online='C', offline=' '), [ + { + 'contents': 'C 86%', + 'highlight_groups': ['battery_gradient', 'battery'], + 'gradient_level': 14, + }]) + + def test_battery_with_ac_offline(self): + pl = Pl() + + def _get_battery_status(pl): + return 86, False + + with replace_attr(self.module, '_get_battery_status', _get_battery_status): + self.assertEqual(self.module.battery(pl=pl, online='C', offline=' '), [ + { + 'contents': ' 86%', + 'highlight_groups': ['battery_gradient', 'battery'], + 'gradient_level': 14, + }]) + class TestVim(TestCase): def test_mode(self): From d02b8e9825b11090f5a91bf8d254cecc7147d1e6 Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 8 Aug 2015 01:10:57 +0300 Subject: [PATCH 11/39] Fix dbus+UPower battery support --- powerline/segments/common/bat.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/powerline/segments/common/bat.py b/powerline/segments/common/bat.py index 332829f9..c3fe838e 100644 --- a/powerline/segments/common/bat.py +++ b/powerline/segments/common/bat.py @@ -51,10 +51,12 @@ def _fetch_battery_info(pl): pl.debug('Not using DBUS+UPower with {0}: not a power supply', devpath) continue pl.debug('Using DBUS+UPower with {0}', devpath) - return lambda pl: float( - dbus.Interface(dev, dbus_interface=devinterface).Get( - devtype_name, - 'Percentage' + return lambda pl: ( + float( + dbus.Interface(dev, dbus_interface=devinterface).Get( + devtype_name, + 'Percentage' + ), ), dbus.Interface(dev, dbus_interface=devinterface).Get( devtype_name, From 63a8b492b32a4a9dca69dc9b00ab7585dbedddef Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 8 Aug 2015 01:15:05 +0300 Subject: [PATCH 12/39] Update battery segment docstring --- powerline/segments/common/bat.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/powerline/segments/common/bat.py b/powerline/segments/common/bat.py index c3fe838e..1f60c57c 100644 --- a/powerline/segments/common/bat.py +++ b/powerline/segments/common/bat.py @@ -184,14 +184,19 @@ def battery(pl, format='{ac_state} {capacity:3.0%}', steps=5, gamify=False, full '''Return battery charge status. :param str format: - Percent format in case gamify is False. + Percent format in case gamify is False. Format arguments: ``ac_state`` + which is equal to either ``online`` or ``offline`` string arguments and + ``capacity`` which is equal to current battery capacity in interval [0, + 100]. :param int steps: Number of discrete steps to show between 0% and 100% capacity if gamify is True. :param bool gamify: Measure in hearts (♥) instead of percentages. For full hearts ``battery_full`` highlighting group is preferred, for empty hearts there - is ``battery_empty``. + is ``battery_empty``. ``battery_online`` or ``battery_offline`` group + will be used for leading segment containing ``online`` or ``offline`` + argument contents. :param str full_heart: Heart displayed for “full” part of battery. :param str empty_heart: @@ -200,9 +205,9 @@ def battery(pl, format='{ac_state} {capacity:3.0%}', steps=5, gamify=False, full the same as full_heart as long as necessary highlighting groups are defined. :param str online: - If computer is connected to a power supply this symbol is prepended to the segment. + Symbol used if computer is connected to a power supply. :param str offline: - If computer is NOT connected to a power supply this symbol is prepended to the segment. + Symbol used if computer is not connected to a power supply. ``battery_gradient`` and ``battery`` groups are used in any case, first is preferred. From ab9c2bd84097e98b0501c06df62a9a1205b0c01e Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 8 Aug 2015 01:15:26 +0300 Subject: [PATCH 13/39] Remove outdated comment --- powerline/segments/common/bat.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/powerline/segments/common/bat.py b/powerline/segments/common/bat.py index 1f60c57c..26e8b0dc 100644 --- a/powerline/segments/common/bat.py +++ b/powerline/segments/common/bat.py @@ -8,10 +8,6 @@ import re from powerline.lib.shell import run_cmd -# XXX Warning: module name must not be equal to the segment name as long as this -# segment is imported into powerline.segments.common module. - - def _fetch_battery_info(pl): try: import dbus From fed3c70b817ad485874f6ac62a8a9d5db7f56cf0 Mon Sep 17 00:00:00 2001 From: Foo Date: Fri, 21 Aug 2015 18:13:26 +0300 Subject: [PATCH 14/39] Vim has moved to github, so tip and version tag got renamed --- tests/run_vim_tests.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/run_vim_tests.sh b/tests/run_vim_tests.sh index 33705b26..9d967bd9 100755 --- a/tests/run_vim_tests.sh +++ b/tests/run_vim_tests.sh @@ -4,8 +4,8 @@ FAILED=0 if test -z "$VIM" ; then if test -n "$USE_UCS2_PYTHON" ; then - NEW_VIM="$ROOT/tests/bot-ci/deps/vim/tip-$UCS2_PYTHON_VARIANT-ucs2-double/vim" - OLD_VIM="$ROOT/tests/bot-ci/deps/vim/v7-0-112-$UCS2_PYTHON_VARIANT-ucs2/vim" + NEW_VIM="$ROOT/tests/bot-ci/deps/vim/master-$UCS2_PYTHON_VARIANT-ucs2-double/vim" + OLD_VIM="$ROOT/tests/bot-ci/deps/vim/v7.0.112-$UCS2_PYTHON_VARIANT-ucs2/vim" opt_dir="$HOME/opt/cpython-ucs2-$UCS2_PYTHON_VARIANT" main_path="$opt_dir/lib/python$UCS2_PYTHON_VARIANT" site_path="$main_path/site-packages" @@ -18,8 +18,8 @@ if test -z "$VIM" ; then exit 0 fi if test -d "$ROOT/tests/bot-ci/deps" ; then - NEW_VIM="$ROOT/tests/bot-ci/deps/vim/tip-$PYTHON_MM/vim" - OLD_VIM="$ROOT/tests/bot-ci/deps/vim/v7-0-112-$PYTHON_MM/vim" + NEW_VIM="$ROOT/tests/bot-ci/deps/vim/master-$PYTHON_MM/vim" + OLD_VIM="$ROOT/tests/bot-ci/deps/vim/v7.0.112-$PYTHON_MM/vim" else NEW_VIM="vim" fi From 9f0665506b4390fc76cd1591bb3be1ae7f920ce9 Mon Sep 17 00:00:00 2001 From: Foo Date: Fri, 21 Aug 2015 18:39:52 +0300 Subject: [PATCH 15/39] =?UTF-8?q?Rename=20=E2=80=A6/test=5Fin=5Fvterm/test?= =?UTF-8?q?.sh=20to=20=E2=80=A6/test=5Fin=5Fvterm/test=5Ftmux.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/run_vterm_tests.sh | 2 +- tests/test_in_vterm/test_tmux.py | 2 +- tests/test_in_vterm/{test.sh => test_tmux.sh} | 24 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) rename tests/test_in_vterm/{test.sh => test_tmux.sh} (61%) diff --git a/tests/run_vterm_tests.sh b/tests/run_vterm_tests.sh index 312b817d..1368ba66 100755 --- a/tests/run_vterm_tests.sh +++ b/tests/run_vterm_tests.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e FAILED=0 -if ! sh tests/test_in_vterm/test.sh ; then +if ! sh tests/test_in_vterm/test_tmux.sh ; then echo "Failed vterm" FAILED=1 fi diff --git a/tests/test_in_vterm/test_tmux.py b/tests/test_in_vterm/test_tmux.py index 6454d69c..83705faa 100755 --- a/tests/test_in_vterm/test_tmux.py +++ b/tests/test_in_vterm/test_tmux.py @@ -18,7 +18,7 @@ from powerline import get_fallback_logger from tests.lib.terminal import ExpectProcess -VTERM_TEST_DIR = os.path.abspath('tests/vterm') +VTERM_TEST_DIR = os.path.abspath('tests/vterm_tmux') def cell_properties_key_to_shell_escape(cell_properties_key): diff --git a/tests/test_in_vterm/test.sh b/tests/test_in_vterm/test_tmux.sh similarity index 61% rename from tests/test_in_vterm/test.sh rename to tests/test_in_vterm/test_tmux.sh index f87201fe..a881485f 100755 --- a/tests/test_in_vterm/test.sh +++ b/tests/test_in_vterm/test_tmux.sh @@ -4,18 +4,18 @@ set +x FAILED=0 -rm -rf tests/vterm -mkdir tests/vterm -mkdir tests/vterm/path +rm -rf tests/vterm_tmux +mkdir tests/vterm_tmux +mkdir tests/vterm_tmux/path -ln -s "$(which "${PYTHON}")" tests/vterm/path/python -ln -s "$(which bash)" tests/vterm/path -ln -s "$(which env)" tests/vterm/path -ln -s "$(which cut)" tests/vterm/path -ln -s "$PWD/scripts/powerline-render" tests/vterm/path -ln -s "$PWD/scripts/powerline-config" tests/vterm/path +ln -s "$(which "${PYTHON}")" tests/vterm_tmux/path/python +ln -s "$(which bash)" tests/vterm_tmux/path +ln -s "$(which env)" tests/vterm_tmux/path +ln -s "$(which cut)" tests/vterm_tmux/path +ln -s "$PWD/scripts/powerline-render" tests/vterm_tmux/path +ln -s "$PWD/scripts/powerline-config" tests/vterm_tmux/path -cp -r tests/terminfo tests/vterm +cp -r tests/terminfo tests/vterm_tmux FAIL_SUMMARY="" @@ -28,7 +28,7 @@ test_tmux() { if ! which "${POWERLINE_TMUX_EXE}" ; then return 0 fi - ln -sf "$(which "${POWERLINE_TMUX_EXE}")" tests/vterm/path + ln -sf "$(which "${POWERLINE_TMUX_EXE}")" tests/vterm_tmux/path f=tests/test_in_vterm/test_tmux.py if ! "${PYTHON}" $f ; then echo "Failed vterm test $f" @@ -49,7 +49,7 @@ fi if test $FAILED -eq 0 ; then echo "$FAIL_SUMMARY" - rm -rf tests/vterm + rm -rf tests/vterm_tmux fi exit $FAILED From b7bca615afd8e56c7c7afe2822e72687743d891d Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 22 Aug 2015 17:18:35 +0300 Subject: [PATCH 16/39] Use tests/common.sh for reporting test failures --- tests/common.sh | 33 +++++++++++++++++++++++++ tests/run_daemon_tests.sh | 23 +++++++++-------- tests/run_lint_tests.sh | 11 ++++++--- tests/run_python_tests.sh | 12 ++++++--- tests/run_vim_tests.sh | 16 ++++++------ tests/run_vterm_tests.sh | 19 +++++++++------ tests/test.sh | 19 ++++++++++----- tests/test_in_vterm/test_tmux.sh | 17 ++++++------- tests/test_shells/test.sh | 42 +++++++++++--------------------- 9 files changed, 114 insertions(+), 78 deletions(-) create mode 100644 tests/common.sh diff --git a/tests/common.sh b/tests/common.sh new file mode 100644 index 00000000..0b555162 --- /dev/null +++ b/tests/common.sh @@ -0,0 +1,33 @@ +. tests/bot-ci/scripts/common/main.sh +set +x + +: ${PYTHON:=python} + +FAILED=0 + +FAIL_SUMMARY="" + +enter_suite() { + local suite_name="$1" + export POWERLINE_CURRENT_SUITE="${POWERLINE_CURRENT_SUITE}/$suite_name" +} + +exit_suite() { + if test $FAILED -ne 0 ; then + echo "Suite ${POWERLINE_CURRENT_SUITE} failed, summary:" + echo "${FAIL_SUMMARY}" + fi + export POWERLINE_CURRENT_SUITE="${POWERLINE_CURRENT_SUITE%/*}" + exit $FAILED +} + +fail() { + local test_name="$1" + local fail_char="$2" + local message="$3" + local full_msg="$fail_char $POWERLINE_CURRENT_SUITE|$test_name :: $message" + FAIL_SUMMARY="${FAIL_SUMMARY}${NL}${full_msg}" + echo "Failed: $full_msg" + echo "$full_msg" >> tests/failures + FAILED=1 +} diff --git a/tests/run_daemon_tests.sh b/tests/run_daemon_tests.sh index e42a3bc8..af68eacf 100755 --- a/tests/run_daemon_tests.sh +++ b/tests/run_daemon_tests.sh @@ -1,5 +1,8 @@ #!/bin/sh -FAILED=0 +. tests/common.sh + +enter_suite daemon + export ADDRESS="powerline-ipc-test-$$" echo "Powerline address: $ADDRESS" if $PYTHON scripts/powerline-daemon -s$ADDRESS ; then @@ -8,16 +11,14 @@ if $PYTHON scripts/powerline-daemon -s$ADDRESS ; then $PYTHON client/powerline.py --socket $ADDRESS -p/dev/null shell left | \ grep 'file not found' ) ; then - echo "-p/dev/null argument ignored or not treated properly" - FAILED=1 + fail "devnull" F "-p/dev/null argument ignored or not treated properly" fi if ( \ $PYTHON client/powerline.py --socket $ADDRESS \ -p$PWD/powerline/config_files shell left | \ grep 'file not found' ) ; then - echo "-p/dev/null argument remembered while it should not" - FAILED=1 + fail "nodevnull" F "-p/dev/null argument remembered while it should not" fi if ! ( \ cd tests && \ @@ -25,17 +26,15 @@ if $PYTHON scripts/powerline-daemon -s$ADDRESS ; then -p$PWD/../powerline/config_files shell left | \ grep 'tests' ) ; then - echo "Output lacks string “tests”" - FAILED=1 + fail "segment" F "Output lacks string “tests”" fi else - echo "Daemon exited with status $?" - FAILED=1 + fail "exitcode" E "Daemon exited with status $?" fi if $PYTHON scripts/powerline-daemon -s$ADDRESS -k ; then : else - echo "powerline-daemon -k failed with exit code $?" - FAILED=1 + fail "-k" F "powerline-daemon -k failed with exit code $?" fi -exit $FAILED + +exit_suite diff --git a/tests/run_lint_tests.sh b/tests/run_lint_tests.sh index 09157910..585e7a03 100755 --- a/tests/run_lint_tests.sh +++ b/tests/run_lint_tests.sh @@ -1,7 +1,10 @@ #!/bin/sh -FAILED=0 +. tests/common.sh + +enter_suite lint + if ! ${PYTHON} scripts/powerline-lint -p powerline/config_files ; then - echo "Failed powerline-lint" - FAILED=1 + fail "test" F "Running powerline-lint failed" fi -exit $FAILED + +exit_suite diff --git a/tests/run_python_tests.sh b/tests/run_python_tests.sh index 62eac30a..f5524142 100755 --- a/tests/run_python_tests.sh +++ b/tests/run_python_tests.sh @@ -1,9 +1,13 @@ #!/bin/sh -FAILED=0 +. tests/common.sh + +enter_suite python + for file in tests/test_*.py ; do + test_name="${file##*/test_}" if ! ${PYTHON} $file --verbose --catch ; then - echo "Failed test(s) from $file" - FAILED=1 + fail "${test_name%.py}" F "Failed test(s) from $file" fi done -exit $FAILED + +exit_suite diff --git a/tests/run_vim_tests.sh b/tests/run_vim_tests.sh index 9d967bd9..c32831db 100755 --- a/tests/run_vim_tests.sh +++ b/tests/run_vim_tests.sh @@ -1,6 +1,7 @@ #!/bin/sh -. tests/bot-ci/scripts/common/main.sh -FAILED=0 +. tests/common.sh + +enter_suite vim if test -z "$VIM" ; then if test -n "$USE_UCS2_PYTHON" ; then @@ -42,28 +43,29 @@ export POWERLINE_THEME_OVERRIDES='default.segments.left=[]' test_script() { local vim="$1" local script="$2" + local test_name_prefix="$3" echo "Running script $script with $vim" if ! test -e "$vim" ; then return 0 fi if ! "$vim" -u NONE -S $script || test -f message.fail ; then - echo "Failed script $script run with $VIM" >&2 + local test_name="$test_name_prefix-${script##*/}" + fail "${test_name%.vim}" F "Failed script $script run with $VIM" cat message.fail >&2 rm message.fail - FAILED=1 fi } for script in tests/test_*.vim ; do if test "${script%.old.vim}" = "${script}" ; then - test_script "$NEW_VIM" "$script" + test_script "$NEW_VIM" "$script" new fi done if test -e "$OLD_VIM" ; then for script in tests/test_*.old.vim ; do - test_script "$OLD_VIM" "$script" + test_script "$OLD_VIM" "$script" old done fi -exit $FAILED +exit_suite diff --git a/tests/run_vterm_tests.sh b/tests/run_vterm_tests.sh index 1368ba66..c918ba32 100755 --- a/tests/run_vterm_tests.sh +++ b/tests/run_vterm_tests.sh @@ -1,8 +1,13 @@ #!/bin/sh -set -e -FAILED=0 -if ! sh tests/test_in_vterm/test_tmux.sh ; then - echo "Failed vterm" - FAILED=1 -fi -exit $FAILED +. tests/common.sh + +enter_suite vterm + +for t in tests/test_in_vterm/test_*.sh ; do + test_name="${t##*/test_}" + if ! sh "$t" ; then + fail "${test_name%.sh}" F "Failed running $t" + fi +done + +exit_suite diff --git a/tests/test.sh b/tests/test.sh index e2e69dc0..68bd9310 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,13 +1,13 @@ #!/bin/bash -. tests/bot-ci/scripts/common/main.sh +. tests/common.sh + +enter_suite root : ${USER:=`id -un`} : ${HOME:=`getent passwd $USER | cut -d: -f6`} export USER HOME -FAILED=0 - if test "$TRAVIS" = true ; then export PATH="$HOME/opt/fish/bin:${PATH}" export PATH="$PWD/tests/bot-ci/deps/rc:$PATH" @@ -34,9 +34,16 @@ fi export PYTHON="${PYTHON:=python}" export PYTHONPATH="${PYTHONPATH}${PYTHONPATH:+:}`realpath .`" for script in tests/run_*_tests.sh ; do + test_name="${script##*/run_}" if ! sh $script ; then - echo "Failed $script" - FAILED=1 + fail "${test_name%_tests.sh}" F "Failed $script" fi done -exit $FAILED + +if test -e tests/failures ; then + echo "Some tests failed. Summary:" + cat tests/failures + rm tests/failures +fi + +exit_suite diff --git a/tests/test_in_vterm/test_tmux.sh b/tests/test_in_vterm/test_tmux.sh index a881485f..c62ce530 100755 --- a/tests/test_in_vterm/test_tmux.sh +++ b/tests/test_in_vterm/test_tmux.sh @@ -1,8 +1,7 @@ #!/bin/sh -. tests/bot-ci/scripts/common/main.sh -set +x +. tests/common.sh -FAILED=0 +enter_suite tmux rm -rf tests/vterm_tmux mkdir tests/vterm_tmux @@ -17,8 +16,6 @@ ln -s "$PWD/scripts/powerline-config" tests/vterm_tmux/path cp -r tests/terminfo tests/vterm_tmux -FAIL_SUMMARY="" - test_tmux() { if test "$PYTHON_IMPLEMENTATION" = PyPy; then # FIXME PyPy3 segfaults for some reason, PyPy does it as well, but @@ -31,9 +28,8 @@ test_tmux() { ln -sf "$(which "${POWERLINE_TMUX_EXE}")" tests/vterm_tmux/path f=tests/test_in_vterm/test_tmux.py if ! "${PYTHON}" $f ; then - echo "Failed vterm test $f" - FAILED=1 - FAIL_SUMMARY="$FAIL_SUMMARY${NL}F $POWERLINE_TMUX_EXE $f" + local test_name="$("$POWERLINE_TMUX_EXE" -V 2>&1 | cut -d' ' -f2)" + fail "$test_name" F "Failed vterm test $f" fi } @@ -48,8 +44,9 @@ else fi if test $FAILED -eq 0 ; then - echo "$FAIL_SUMMARY" rm -rf tests/vterm_tmux +else + echo "$FAIL_SUMMARY" fi -exit $FAILED +exit_suite diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 0663a6fa..8abc8532 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -1,10 +1,8 @@ #!/bin/sh -. tests/bot-ci/scripts/common/main.sh -set +x +. tests/common.sh + +enter_suite shells -: ${PYTHON:=python} -FAIL_SUMMARY="" -FAILED=0 if test "x$1" = "x--fast" ; then FAST=1 shift @@ -285,9 +283,7 @@ check_test_client() { esac expected_mime_type="${expected_mime_type%/*}" if test "$expected_mime_type" != "$actual_mime_type" ; then - echo "Expected $executable to have MIME type $expected_mime_type, but got $actual_mime_type" - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}M ${executable}" + fail "MIME-$executable" "M" "Expected $executable to have MIME type $expected_mime_type, but got $actual_mime_type" fi } @@ -382,8 +378,7 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te fi echo ">>> $(readlink "tests/shell/path/$SH")" if ! run_test $TEST_TYPE $TEST_CLIENT $TEST_COMMAND ; then - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T ${TEST_TYPE} ${TEST_CLIENT} ${TEST_COMMAND}" + fail "$SH-$TEST_TYPE-$TEST_CLIENT:test" F "Failed checking $TEST_COMMAND" fi done done @@ -395,8 +390,7 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te echo "Daemon log:" echo '============================================================' cat tests/shell/daemon_log - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}L ${TEST_TYPE} ${TEST_CLIENT} ${TEST_COMMAND}" + fail "$SH-$TEST_TYPE-$TEST_CLIENT:log" E "Non-empty daemon log for ${TEST_COMMAND}" fi fi done @@ -406,9 +400,7 @@ if $PYTHON scripts/powerline-daemon -s$ADDRESS > tests/shell/daemon_log_2 2>&1 ; sleep 1 $PYTHON scripts/powerline-daemon -s$ADDRESS -k else - echo "Daemon exited with status $?" - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}D" + fail "daemon:run" F "Daemon exited with status $?" fi if ! test -z "$(cat tests/shell/daemon_log_2)" ; then @@ -416,8 +408,7 @@ if ! test -z "$(cat tests/shell/daemon_log_2)" ; then echo "Daemon log (2nd):" echo '============================================================' cat tests/shell/daemon_log_2 - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}L" + fail "daemon:log" E "Daemon run with non-empty log" fi if ( test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xzsh" ) \ @@ -425,8 +416,7 @@ if ( test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xzsh" ) \ && zsh tests/test_shells/zsh_test_script.zsh 2>/dev/null; then echo "> zpython" if ! run_test zpython zpython zsh -f -i ; then - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T zpython zsh -f -i" + fail "zsh-zpython:test" F "Failed checking zsh -f -i" fi fi @@ -435,8 +425,7 @@ if test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xpdb" ; then if test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xsubclass" ; then echo "> pdb subclass" if ! run_test subclass python $PDB_PYTHON "$PWD/tests/test_shells/pdb-main.py" ; then - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON $PWD/tests/test_shells/pdb-main.py" + fail "pdb-subclass:test" F "Failed checking $PDB_PYTHON $PWD/tests/test_shells/pdb-main.py" fi fi if test "x${ONLY_TEST_TYPE}" = "x" || test "x${ONLY_TEST_TYPE}" = "xmodule" ; then @@ -446,8 +435,7 @@ if test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xpdb" ; then MODULE="powerline.bindings.pdb.__main__" fi if ! run_test module python $PDB_PYTHON -m$MODULE "$PWD/tests/test_shells/pdb-script.py" ; then - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T pdb $PDB_PYTHON -m$MODULE $PWD/tests/test_shells/pdb-script" + fail "pdb-module:test" F "Failed checking $PDB_PYTHON -m$MODULE $PWD/tests/test_shells/pdb-script" fi fi fi @@ -460,8 +448,7 @@ if test "x${ONLY_SHELL}" = "x" || test "x${ONLY_SHELL}" = "xipython" ; then export POWERLINE_THEME_OVERRIDES='in.segments.left=[]' echo "> ipython" if ! run_test ipython ipython ${IPYTHON_PYTHON} -mIPython ; then - FAILED=1 - FAIL_SUMMARY="${FAIL_SUMMARY}${NL}T ipython" + fail "ipython:test" F "Failed checking ${IPYTHON_PYTHON} -mIPython" fi unset POWERLINE_THEME_OVERRIDES unset POWERLINE_CONFIG_OVERRIDES @@ -470,7 +457,6 @@ fi if test $FAILED -eq 0 ; then rm -r tests/shell -else - echo "${FAIL_SUMMARY}" fi -exit $FAILED + +exit_suite From 959693fa9707e3aff27baf20475c4e4221eb571b Mon Sep 17 00:00:00 2001 From: Foo Date: Sat, 22 Aug 2015 17:44:57 +0300 Subject: [PATCH 17/39] Temporary fix for failing zsh tests --- tests/test_shells/postproc.py | 6 ++- tests/test_shells/zsh.daemon.ok | 86 +++++++++++++++---------------- tests/test_shells/zsh.nodaemon.ok | 86 +++++++++++++++---------------- 3 files changed, 91 insertions(+), 87 deletions(-) diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index 0e7f0923..9b2a19a3 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -30,6 +30,7 @@ user = os.environ['USER'] REFS_RE = re.compile(r'^\[\d+ refs\]\n') IPYPY_DEANSI_RE = re.compile(r'\033(?:\[(?:\?\d+[lh]|[^a-zA-Z]+[a-ln-zA-Z])|[=>])') +ZSH_HL_RE = re.compile(r'\033\[\?\d+[hl]') start_str = 'cd tests/shell/3rd' if shell == 'pdb': @@ -55,7 +56,10 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: line = line.replace(user, 'USER') if pid is not None: line = line.replace(pid, 'PID') - if shell == 'fish': + if shell == 'zsh': + line = line.replace('\033[0m\033[23m\033[24m\033[J', '') + line = ZSH_HL_RE.subn('', line)[0] + elif shell == 'fish': res = '' try: while line.index('\033[0;'): diff --git a/tests/test_shells/zsh.daemon.ok b/tests/test_shells/zsh.daemon.ok index daf415dc..ae8682e4 100644 --- a/tests/test_shells/zsh.daemon.ok +++ b/tests/test_shells/zsh.daemon.ok @@ -1,52 +1,52 @@ -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="/home/USER/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="/home/USER/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh [1] PID -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s [1] + terminated bgscript.sh -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bindkey -v ; set_theme default - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   COMMND   HOSTNAME  USER  ⋯  tests  shell  3rd   - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  echo abc +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bindkey -v ; set_theme default + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   COMMND   HOSTNAME  USER  ⋯  tests  shell  3rd   + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  echo abc abc - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  false - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.hostname.display false - INSERT  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.user.display false - INSERT  ⋯  tests  shell  3rd  select abc in def ghi jkl - select                            do - select                             echo $abc - select                             break - select                            done + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  false + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.hostname.display false + INSERT  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.user.display false + INSERT  ⋯  tests  shell  3rd  select abc in def ghi jkl + select                            do + select                             echo $abc + select                             break + select                            done 1) def 2) ghi 3) jkl -                   Select variant  1 +                   Select variant  1 def - INSERT  ⋯  tests  shell  3rd  cd . - INSERT  ⋯  tests  shell  3rd  cd . - INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_LEFT" - INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo - foo   - INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR - INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_FULL" -                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  cd . + INSERT  ⋯  tests  shell  3rd  cd . + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_LEFT"  INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo -                                                                                                                                                                                                                                                                                                      foo  + foo    INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR -                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_FULL" +                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo +                                                                                                                                                                                                                                                                                                      foo  + INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR +                                                                                                                                                                                                                                                                                                             INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above - INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd . - INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC - INSERT $ABC~foo  3rd $ABCtrue + INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd . + INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC + INSERT $ABC~foo  3rd $ABCtrue diff --git a/tests/test_shells/zsh.nodaemon.ok b/tests/test_shells/zsh.nodaemon.ok index 6a813f93..ce35d952 100644 --- a/tests/test_shells/zsh.nodaemon.ok +++ b/tests/test_shells/zsh.nodaemon.ok @@ -1,52 +1,52 @@ -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="/home/USER/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="/home/USER/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh [1] PID -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s [1] + terminated bgscript.sh -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bindkey -v ; set_theme default - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   COMMND   HOSTNAME  USER  ⋯  tests  shell  3rd   - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  echo abc +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bindkey -v ; set_theme default + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   COMMND   HOSTNAME  USER  ⋯  tests  shell  3rd   + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd   + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  echo abc abc - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  false - INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.hostname.display false - INSERT  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.user.display false - INSERT  ⋯  tests  shell  3rd  select abc in def ghi jkl - select  do - select   echo $abc - select   break - select  done + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  false + INSERT   HOSTNAME  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.hostname.display false + INSERT  USER  ⋯  tests  shell  3rd  set_theme_option default.segment_data.user.display false + INSERT  ⋯  tests  shell  3rd  select abc in def ghi jkl + select  do + select   echo $abc + select   break + select  done 1) def 2) ghi 3) jkl - Select variant  1 + Select variant  1 def - INSERT  ⋯  tests  shell  3rd  cd . - INSERT  ⋯  tests  shell  3rd  cd . - INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_LEFT" - INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo - foo   - INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR - INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_FULL" -                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  cd . + INSERT  ⋯  tests  shell  3rd  cd . + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_LEFT"  INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo -                                                                                                                                                                                                                                                                                                      foo  + foo    INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR -                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_FULL" +                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo +                                                                                                                                                                                                                                                                                                      foo  + INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR +                                                                                                                                                                                                                                                                                                             INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above - INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd . - INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC - INSERT $ABC~foo  3rd $ABCtrue + INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd . + INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC + INSERT $ABC~foo  3rd $ABCtrue From 918dd957cf8efc66a849fa0cf29e46992bde2d9b Mon Sep 17 00:00:00 2001 From: S0lll0s Date: Fri, 21 Aug 2015 17:50:27 +0200 Subject: [PATCH 18/39] Add 'output' option to segments.i3wm.workspaces --- powerline/segments/i3wm.py | 10 ++++++++-- tests/test_segments.py | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/powerline/segments/i3wm.py b/powerline/segments/i3wm.py index f0c16427..a5a82774 100644 --- a/powerline/segments/i3wm.py +++ b/powerline/segments/i3wm.py @@ -19,7 +19,7 @@ def calcgrp(w): return group -def workspaces(pl, only_show=None, strip=0): +def workspaces(pl, only_show=None, output=None, strip=0): '''Return list of used workspaces :param list only_show: @@ -27,6 +27,9 @@ def workspaces(pl, only_show=None, strip=0): ``"urgent"`` and ``"focused"``. If omitted or ``null`` all workspaces are shown. + :param str output: + If specified, only workspaces on this output are shown. + :param int strip: Specifies how many characters from the front of each workspace name should be stripped (e.g. to remove workspace numbers). Defaults to zero. @@ -45,7 +48,10 @@ def workspaces(pl, only_show=None, strip=0): return [{ 'contents': w['name'][min(len(w['name']), strip):], 'highlight_groups': calcgrp(w) - } for w in conn.get_workspaces() if not only_show or any((w[typ] for typ in only_show))] + } for w in conn.get_workspaces() + if (not only_show or any(w[typ] for typ in only_show)) + and (not output or w['output'] == output) + ] @requires_segment_info diff --git a/tests/test_segments.py b/tests/test_segments.py index c01dd6d5..b3c77029 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -819,10 +819,10 @@ class TestI3WM(TestCase): def test_workspaces(self): pl = Pl() with replace_attr(i3wm, 'conn', Args(get_workspaces=lambda: iter([ - {'name': '1: w1', 'focused': False, 'urgent': False, 'visible': False}, - {'name': '2: w2', 'focused': False, 'urgent': False, 'visible': True}, - {'name': '3: w3', 'focused': False, 'urgent': True, 'visible': True}, - {'name': '4: w4', 'focused': True, 'urgent': True, 'visible': True}, + {'name': '1: w1', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': False}, + {'name': '2: w2', 'output': 'LVDS1', 'focused': False, 'urgent': False, 'visible': True}, + {'name': '3: w3', 'output': 'HDMI1', 'focused': False, 'urgent': True, 'visible': True}, + {'name': '4: w4', 'output': 'DVI01', 'focused': True, 'urgent': True, 'visible': True}, ]))): self.assertEqual(i3wm.workspaces(pl=pl), [ {'contents': '1: w1', 'highlight_groups': ['workspace']}, @@ -850,6 +850,15 @@ class TestI3WM(TestCase): {'contents': 'w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']}, {'contents': 'w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']}, ]) + self.assertEqual(i3wm.workspaces(pl=pl, only_show=['focused', 'urgent'], output='DVI01'), [ + {'contents': '4: w4', 'highlight_groups': ['w_focused', 'w_urgent', 'w_visible', 'workspace']}, + ]) + self.assertEqual(i3wm.workspaces(pl=pl, only_show=['visible'], output='HDMI1'), [ + {'contents': '3: w3', 'highlight_groups': ['w_urgent', 'w_visible', 'workspace']}, + ]) + self.assertEqual(i3wm.workspaces(pl=pl, only_show=['visible'], strip=3, output='LVDS1'), [ + {'contents': 'w2', 'highlight_groups': ['w_visible', 'workspace']}, + ]) def test_mode(self): pl = Pl() From c687ea943fa8d925889d74228902b3ad31a7f2b6 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 26 Aug 2015 16:02:42 +0100 Subject: [PATCH 19/39] Adding zoom indicator to window status formats. --- powerline/bindings/tmux/powerline-base.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerline/bindings/tmux/powerline-base.conf b/powerline/bindings/tmux/powerline-base.conf index 4b1f1d67..a17f0c41 100644 --- a/powerline/bindings/tmux/powerline-base.conf +++ b/powerline/bindings/tmux/powerline-base.conf @@ -4,8 +4,8 @@ set -g status-interval 2 set -g status-left-length 20 set -g status-right '#(env "$POWERLINE_COMMAND" $POWERLINE_COMMAND_ARGS tmux right -R pane_id=\"`tmux display -p "#D"`\")' set -g status-right-length 150 -set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER_SPACES#I #[$_POWERLINE_WINDOW_DIVIDER_COLOR]$_POWERLINE_LEFT_SOFT_DIVIDER#[default]#W $_POWERLINE_LEFT_HARD_DIVIDER_SPACES" -set -g window-status-current-format "#[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#[$_POWERLINE_WINDOW_CURRENT_COLOR]#I $_POWERLINE_LEFT_SOFT_DIVIDER#[$_POWERLINE_WINDOW_NAME_COLOR]#W #[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER" +set -g window-status-format "#[$_POWERLINE_WINDOW_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER_SPACES#I#F #[$_POWERLINE_WINDOW_DIVIDER_COLOR]$_POWERLINE_LEFT_SOFT_DIVIDER#[default]#W $_POWERLINE_LEFT_HARD_DIVIDER_SPACES" +set -g window-status-current-format "#[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#[$_POWERLINE_WINDOW_CURRENT_COLOR]#I#F $_POWERLINE_LEFT_SOFT_DIVIDER#[$_POWERLINE_WINDOW_NAME_COLOR]#W #[$_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER" # Legacy status-left definition to be overwritten for tmux Versions 1.8+ set -g status-left "#[$_POWERLINE_SESSION_COLOR] #S #[$_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR]$_POWERLINE_LEFT_HARD_DIVIDER#(env \"\$POWERLINE_COMMAND\" tmux left -R pane_id=\"`tmux display -p '#D'`\")" From eeaaf3930fd1ab05f413393baf78e2ad210fc275 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 27 Aug 2015 09:05:13 +0100 Subject: [PATCH 20/39] updating tmux tests to expect window_flags in window status format --- tests/test_in_vterm/test_tmux.py | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_in_vterm/test_tmux.py b/tests/test_in_vterm/test_tmux.py index 83705faa..950f9171 100755 --- a/tests/test_in_vterm/test_tmux.py +++ b/tests/test_in_vterm/test_tmux.py @@ -193,57 +193,57 @@ def main(attempts=3): (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), - (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), + (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), - (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), + (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1- '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), - (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), + (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), - (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 127), + (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 124), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ), expected_result_new=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), - (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), + (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), - (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), + (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1- '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), - (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), + (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), - (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 127), + (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 124), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ), expected_result_2_0=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), - (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), + (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), - (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), + (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1- '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), - (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), + (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), - (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 128), + (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 125), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), )) @@ -265,10 +265,10 @@ def main(attempts=3): (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' <'), - (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'sh '), + (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'h '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), - (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), + (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), @@ -278,10 +278,10 @@ def main(attempts=3): (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' <'), - (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'sh '), + (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'h '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), - (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), + (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), @@ -291,10 +291,10 @@ def main(attempts=3): (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), '<'), - (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), + (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'ash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), - (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), + (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), From a272c6abb5fcf12c3ab93ee507fde68ac0f40c27 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 30 Aug 2015 01:21:49 +0300 Subject: [PATCH 21/39] Use net_io_counters by default also in _get_interfaces Fixes #1435 --- powerline/segments/common/net.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/powerline/segments/common/net.py b/powerline/segments/common/net.py index 46243c66..0af5762d 100644 --- a/powerline/segments/common/net.py +++ b/powerline/segments/common/net.py @@ -150,7 +150,10 @@ try: return if_io.bytes_recv, if_io.bytes_sent def _get_interfaces(): - io_counters = psutil.network_io_counters(pernic=True) + try: + io_counters = psutil.net_io_counters(pernic=True) + except AttributeError: + io_counters = psutil.network_io_counters(pernic=True) for interface, data in io_counters.items(): if data: yield interface, data.bytes_recv, data.bytes_sent From b8e09b3e42407f7b5c5be7510c65beb5db00c9b4 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 30 Aug 2015 13:21:01 +0300 Subject: [PATCH 22/39] Fix support for passworded connections in mpd+python-mpd* player seg Fixes #1437 --- powerline/segments/common/players.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/powerline/segments/common/players.py b/powerline/segments/common/players.py index 1e03af93..8ae6cb1a 100644 --- a/powerline/segments/common/players.py +++ b/powerline/segments/common/players.py @@ -167,14 +167,16 @@ Requires cmus-remote command be acessible from $PATH. class MpdPlayerSegment(PlayerSegment): - def get_player_status(self, pl, host='localhost', port=6600): + def get_player_status(self, pl, host='localhost', password=None, port=6600): try: import mpd except ImportError: + if password: + host = password + '@' + host now_playing = run_cmd(pl, [ 'mpc', 'current', '-f', '%album%\n%artist%\n%title%\n%time%', - '-h', str(host), + '-h', host, '-p', str(port) ], strip=False) if not now_playing: @@ -189,6 +191,8 @@ class MpdPlayerSegment(PlayerSegment): else: client = mpd.MPDClient() client.connect(host, port) + if password: + client.password(password) now_playing = client.currentsong() if not now_playing: return @@ -220,6 +224,8 @@ package) or alternatively the ``mpc`` command to be acessible from $PATH. {0} :param str host: Host on which mpd runs. +:param str password: + Password used for connecting to daemon. :param int port: Port which should be connected to. ''').format(_common_args.format('mpd'))) From 105cf6666f51017d59521250698697f5ff60f1a4 Mon Sep 17 00:00:00 2001 From: Sean Fisk Date: Fri, 4 Sep 2015 16:12:20 -0400 Subject: [PATCH 23/39] Detect internal_ip interface from default gateway Add the option to specify `interface='default_gateway'` to the `internal_ip` segment, which displays the IP address of the interface connected to the default gateway. --- powerline/segments/common/net.py | 14 +++++++++++++- tests/test_segments.py | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/powerline/segments/common/net.py b/powerline/segments/common/net.py index 0af5762d..85bf737b 100644 --- a/powerline/segments/common/net.py +++ b/powerline/segments/common/net.py @@ -101,15 +101,22 @@ else: return 0 def internal_ip(pl, interface='auto', ipv=4): + family = netifaces.AF_INET6 if ipv == 6 else netifaces.AF_INET if interface == 'auto': try: interface = next(iter(sorted(netifaces.interfaces(), key=_interface_key, reverse=True))) except StopIteration: pl.info('No network interfaces found') return None + elif interface == 'default_gateway': + try: + interface = netifaces.gateways()['default'][family][1] + except KeyError: + pl.info('No default gateway found for IPv{0}', ipv) + return None addrs = netifaces.ifaddresses(interface) try: - return addrs[netifaces.AF_INET6 if ipv == 6 else netifaces.AF_INET][0]['addr'] + return addrs[family][0]['addr'] except (KeyError, IndexError): return None @@ -130,6 +137,11 @@ Requires ``netifaces`` module to work properly. #. ``teredo`` followed by number or the end of string. #. Any other interface that is not ``lo*``. #. ``lo`` followed by number or the end of string. + + Use ``default_gateway`` to detect the interface based on the machine's + `default gateway `_ (i.e., + the router to which it is connected). + :param int ipv: 4 or 6 for ipv4 and ipv6 respectively, depending on which IP address you need exactly. diff --git a/tests/test_segments.py b/tests/test_segments.py index b3c77029..58292909 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -397,6 +397,29 @@ class TestNet(TestCommon): interfaces[:] = () self.assertEqual(self.module.internal_ip(pl=pl, ipv=6), None) + gateways = { + 'default': { + netifaces.AF_INET: ('192.168.100.1', 'enp2s0'), + netifaces.AF_INET6: ('feff::5446:5eff:fe5a:0001', 'enp2s0') + } + } + + with replace_module_module( + self.module, 'netifaces', + interfaces=(lambda: interfaces), + ifaddresses=(lambda interface: addr[interface]), + gateways=(lambda: gateways), + AF_INET=netifaces.AF_INET, + AF_INET6=netifaces.AF_INET6, + ): + # default gateway has specified address family + self.assertEqual(self.module.internal_ip(pl=pl, interface='default_gateway', ipv=4), '192.168.100.200') + self.assertEqual(self.module.internal_ip(pl=pl, interface='default_gateway', ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0') + # default gateway doesn't have specified address family + gateways['default'] = {} + self.assertEqual(self.module.internal_ip(pl=pl, interface='default_gateway', ipv=4), None) + self.assertEqual(self.module.internal_ip(pl=pl, interface='default_gateway', ipv=6), None) + def test_network_load(self): def gb(interface): return None From 2c1213116ed68fff15169a61d94852c97840dd3c Mon Sep 17 00:00:00 2001 From: Sean Fisk Date: Sat, 5 Sep 2015 18:02:11 -0400 Subject: [PATCH 24/39] Log when IP address family not found for interface --- powerline/segments/common/net.py | 1 + 1 file changed, 1 insertion(+) diff --git a/powerline/segments/common/net.py b/powerline/segments/common/net.py index 85bf737b..eb5b4bcf 100644 --- a/powerline/segments/common/net.py +++ b/powerline/segments/common/net.py @@ -118,6 +118,7 @@ else: try: return addrs[family][0]['addr'] except (KeyError, IndexError): + pl.info("No IPv{0} address found for interface {1}", ipv, interface) return None From 7e379a8a2f5e055212c64f2718c3b8a0fc4ced67 Mon Sep 17 00:00:00 2001 From: Juraj Fiala Date: Sun, 13 Sep 2015 16:53:26 +0200 Subject: [PATCH 25/39] Added a systemd service, fixes #1447. --- powerline/dist/systemd/powerline-daemon.service | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 powerline/dist/systemd/powerline-daemon.service diff --git a/powerline/dist/systemd/powerline-daemon.service b/powerline/dist/systemd/powerline-daemon.service new file mode 100644 index 00000000..96b685dd --- /dev/null +++ b/powerline/dist/systemd/powerline-daemon.service @@ -0,0 +1,10 @@ +[Unit] +Description=powerline-daemon - Daemon that improves powerline performance +Documentation=man:powerline-daemon(1) +Documentation=https://powerline.readthedocs.org/en/latest/ + +[Service] +ExecStart=/usr/bin/powerline-daemon --foreground + +[Install] +WantedBy=default.target From 56aa31a66dd1e6b9b42e8ab29bd92e212d9c68a3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 13 Sep 2015 22:05:23 -0400 Subject: [PATCH 26/39] Show conda environment in virtualenv segment. Either conda or virtualenv checks can be disabled using the new ignore_venv or ignore_conda options to this segment. --- powerline/segments/common/env.py | 17 ++++++++++++++--- tests/test_segments.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/powerline/segments/common/env.py b/powerline/segments/common/env.py index 0ba7be5f..74f2d73b 100644 --- a/powerline/segments/common/env.py +++ b/powerline/segments/common/env.py @@ -19,9 +19,20 @@ def environment(pl, segment_info, variable=None): @requires_segment_info -def virtualenv(pl, segment_info): - '''Return the name of the current Python virtualenv.''' - return os.path.basename(segment_info['environ'].get('VIRTUAL_ENV', '')) or None +def virtualenv(pl, segment_info, ignore_venv=False, ignore_conda=False): + '''Return the name of the current Python or conda virtualenv. + + :param bool ignore_venv: + Whether to ignore virtual environments. Default is False. + :param bool ignore_conda: + Whether to ignore conda environments. Default is False. + ''' + return ( + (not ignore_venv and + os.path.basename(segment_info['environ'].get('VIRTUAL_ENV', ''))) or + (not ignore_conda and + segment_info['environ'].get('CONDA_DEFAULT_ENV', '')) or + None) @requires_segment_info diff --git a/tests/test_segments.py b/tests/test_segments.py index 58292909..9dbd14c2 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -625,8 +625,39 @@ class TestEnv(TestCommon): pl = Pl() with replace_env('VIRTUAL_ENV', '/abc/def/ghi') as segment_info: self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info), 'ghi') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_conda=True), 'ghi') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True, ignore_conda=True), None) + segment_info['environ'].pop('VIRTUAL_ENV') self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_conda=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True, ignore_conda=True), None) + + with replace_env('CONDA_DEFAULT_ENV', 'foo') as segment_info: + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info), 'foo') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_conda=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True), 'foo') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True, ignore_conda=True), None) + + segment_info['environ'].pop('CONDA_DEFAULT_ENV') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_conda=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True, ignore_conda=True), None) + + with replace_env('CONDA_DEFAULT_ENV', 'foo', environ={'VIRTUAL_ENV': '/sbc/def/ghi'}) as segment_info: + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info), 'ghi') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_conda=True), 'ghi') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True), 'foo') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True, ignore_conda=True), None) + + segment_info['environ'].pop('CONDA_DEFAULT_ENV') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info), 'ghi') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_conda=True), 'ghi') + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True), None) + self.assertEqual(self.module.virtualenv(pl=pl, segment_info=segment_info, ignore_venv=True, ignore_conda=True), None) def test_environment(self): pl = Pl() From 783b0f7f8478f9151d3cb533faedd8c53be378ac Mon Sep 17 00:00:00 2001 From: Nikolai Aleksandrovich Pavlov Date: Tue, 29 Sep 2015 13:50:40 +0300 Subject: [PATCH 27/39] Do not state that patched font does not work for rxvt-unicode Fixes #1455 --- docs/source/installation.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index b4682d45..be786480 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -113,8 +113,7 @@ install a patched font. Patched fonts ------------- -This method is the fallback method and works for every terminal, with the -exception of :ref:`rxvt-unicode `. +This method is the fallback method and works for every terminal. Download the font from `powerline-fonts`_. If preferred font can’t be found in the `powerline-fonts`_ repo, then patching the preferred font is needed instead. From 811498d21b666af50a9086d23a21efaf81bbe993 Mon Sep 17 00:00:00 2001 From: S0lll0s Date: Mon, 5 Oct 2015 20:56:07 +0200 Subject: [PATCH 28/39] Include i3wm segments in Configuration docs Close #1457 --- docs/source/configuration/segments/i3wm.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/source/configuration/segments/i3wm.rst diff --git a/docs/source/configuration/segments/i3wm.rst b/docs/source/configuration/segments/i3wm.rst new file mode 100644 index 00000000..d1033742 --- /dev/null +++ b/docs/source/configuration/segments/i3wm.rst @@ -0,0 +1,6 @@ +************* +i3wm segments +************* + +.. automodule:: powerline.segments.i3wm + :members: From 69d3bdf3285180af2e4159e7fc30b08e8f46b645 Mon Sep 17 00:00:00 2001 From: Nikolai Aleksandrovich Pavlov Date: Tue, 6 Oct 2015 00:27:08 +0300 Subject: [PATCH 29/39] Fix typo (missing letter) in installation/osx.rst Closes #1463 --- docs/source/installation/osx.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/installation/osx.rst b/docs/source/installation/osx.rst index 99e19494..5a85e692 100644 --- a/docs/source/installation/osx.rst +++ b/docs/source/installation/osx.rst @@ -22,7 +22,7 @@ Python package to be installed. ``coreutils`` may be installed using ``brew install coreutils``. -2. Install Powerline using one of the following commans: +2. Install Powerline using one of the following commands: .. code-block:: sh From c6a6041b0df0e19e6dd77e39a1a2fdd30d2ba627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5ken=20Lid?= Date: Sun, 4 Oct 2015 22:03:06 +0200 Subject: [PATCH 30/39] Allow unicode characters in time segment in Python-2 --- powerline/segments/common/time.py | 7 ++++++- tests/test_segments.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/powerline/segments/common/time.py b/powerline/segments/common/time.py index 84518c77..1e2207b3 100644 --- a/powerline/segments/common/time.py +++ b/powerline/segments/common/time.py @@ -16,8 +16,13 @@ def date(pl, format='%Y-%m-%d', istime=False): Highlight groups used: ``time`` or ``date``. ''' + try: + contents = datetime.now().strftime(format) + except UnicodeEncodeError: + contents = datetime.now().strftime(format.encode('utf-8')).decode('utf-8') + return [{ - 'contents': datetime.now().strftime(format), + 'contents': contents, 'highlight_groups': (['time'] if istime else []) + ['date'], 'divider_highlight_group': 'time:divider' if istime else None, }] diff --git a/tests/test_segments.py b/tests/test_segments.py index 58292909..3e24b927 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -709,6 +709,7 @@ class TestTime(TestCommon): with replace_attr(self.module, 'datetime', Args(now=lambda: Args(strftime=lambda fmt: fmt))): self.assertEqual(self.module.date(pl=pl), [{'contents': '%Y-%m-%d', 'highlight_groups': ['date'], 'divider_highlight_group': None}]) self.assertEqual(self.module.date(pl=pl, format='%H:%M', istime=True), [{'contents': '%H:%M', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}]) + self.assertEqual(self.module.date(pl=pl, format='\u231a', istime=True), [{'contents': '\u231a', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}]) def test_fuzzy_time(self): time = Args(hour=0, minute=45) From 20ceaac885d8b12f8d5972c2f5021416d8239a80 Mon Sep 17 00:00:00 2001 From: Foo Date: Tue, 6 Oct 2015 01:39:11 +0300 Subject: [PATCH 31/39] Allow the whole CPython-2.6 UCS2 section to fail --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 01429651..6be388b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,5 +34,10 @@ matrix: env: >- USE_UCS2_PYTHON=1 UCS2_PYTHON_VARIANT="2.7" + allow_failures: + - python: "2.6" + env: >- + USE_UCS2_PYTHON=1 + UCS2_PYTHON_VARIANT="2.6" # vim: et From 76be911b81f4102f75e933d3953ed75537bcafe2 Mon Sep 17 00:00:00 2001 From: Foo Date: Tue, 6 Oct 2015 01:46:25 +0300 Subject: [PATCH 32/39] Skip date test on PyPy3 See https://bitbucket.org/pypy/pypy/issues/2161/pypy3-strftime-does-not-accept-unicode --- tests/test_segments.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_segments.py b/tests/test_segments.py index 3e24b927..724ba5bd 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -7,6 +7,7 @@ import os from functools import partial from collections import namedtuple from time import sleep +from platform import python_implementation from powerline.segments import shell, tmux, pdb, i3wm from powerline.lib.vcs import get_fallback_create_watcher @@ -709,7 +710,12 @@ class TestTime(TestCommon): with replace_attr(self.module, 'datetime', Args(now=lambda: Args(strftime=lambda fmt: fmt))): self.assertEqual(self.module.date(pl=pl), [{'contents': '%Y-%m-%d', 'highlight_groups': ['date'], 'divider_highlight_group': None}]) self.assertEqual(self.module.date(pl=pl, format='%H:%M', istime=True), [{'contents': '%H:%M', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}]) - self.assertEqual(self.module.date(pl=pl, format='\u231a', istime=True), [{'contents': '\u231a', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}]) + unicode_date = self.module.date(pl=pl, format='\u231a', istime=True) + expected_unicode_date = [{'contents': '\u231a', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}] + if python_implementation() == 'PyPy' and sys.version_info >= (3,): + if unicode_date != expected_unicode_date: + raise SkipTest('Dates do not match, see https://bitbucket.org/pypy/pypy/issues/2161/pypy3-strftime-does-not-accept-unicode') + self.assertEqual(unicode_date, expected_unicode_date) def test_fuzzy_time(self): time = Args(hour=0, minute=45) From 9247567ae9eef702d757f27a738ebec55f6a511a Mon Sep 17 00:00:00 2001 From: S0lll0s Date: Thu, 8 Oct 2015 11:52:29 +0200 Subject: [PATCH 33/39] Add i3 to the tagline --- README.rst | 2 +- docs/source/overview.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index c30679e1..4a9f3140 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Powerline **Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, -Awesome and Qtile.** +Awesome, i3 and Qtile.** * `Support forum`_ (powerline-support@googlegroups.com) * `Development discussion`_ (powerline-dev@googlegroups.com) diff --git a/docs/source/overview.rst b/docs/source/overview.rst index 73804ea5..e943b044 100644 --- a/docs/source/overview.rst +++ b/docs/source/overview.rst @@ -4,7 +4,7 @@ Overview **Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, -Awesome and Qtile.** +Awesome, i3 and Qtile.** Features -------- From e6d484a32954dd73bcdf7c8f0592d28501c4f94c Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Fri, 10 Jul 2015 11:15:03 +0200 Subject: [PATCH 34/39] Added troubleshooting for Urxvt & Unicode --- docs/source/troubleshooting.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index 16be8a83..542ee9b0 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -189,6 +189,25 @@ If your locale encoding is not unicode (any encoding that starts with “utf” should set up your system to use unicode locale or forget about powerline fancy characters. +Urxvt unicode3 and frills +------------------------- + +Make sure that, whatever urxvt package you're installing, both the `unicode3` +and `frills` features are enabled at compile time. Run +``urxvt --help 2>&1 | grep options:`` to get a list of enabled options. +This should contain at least `frills`, `unicode3` and optionally `iso14755` +if you want to input Unicode characters as well. + +Compiler flags example: + + --enable-frills \ + --enable-unicode3 + +As long as your terminal emulator is compiled without unicode rendering, +no amount of configuration will make it display unicode characters. +They're being considered 'unnecessary features', but they add negligible +overhead to the size of the installed package (~100KB). + Vim issues ========== From c4b4097b0cc3cbba598dcfae69352f357490ff01 Mon Sep 17 00:00:00 2001 From: Foo Date: Mon, 19 Oct 2015 21:56:46 +0300 Subject: [PATCH 35/39] Transform pane_id to unicode before using Tmux-2.1 appears not to output leading `%` when using `tmux display -p '#D'`. This change changes type of the `pane_id` argument: leading `%` turns it into a literal string, number in front makes it be parsed as a JSON number. Fixes #1470 --- docs/source/develop/segments.rst | 11 ++++++++++- powerline/commands/main.py | 10 +++++++++- powerline/renderers/tmux.py | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/source/develop/segments.rst b/docs/source/develop/segments.rst index 8d752229..d96bb1cb 100644 --- a/docs/source/develop/segments.rst +++ b/docs/source/develop/segments.rst @@ -467,7 +467,8 @@ Shell ``client_id`` Identifier unique to one shell instance. Is used to record instance - state by powerline daemon. + state by powerline daemon. In tmux this is the same as :ref:`pane_id + `. It is not guaranteed that existing client ID will not be retaken when old shell with this ID quit: usually process PID is used as @@ -481,6 +482,14 @@ Shell Local theme that will be used by shell. One should not rely on the existence of this key. + .. _dev-seginfo-shell-renarg-pane_id: + + ``pane_id`` + Identifier unique to each tmux pane. Is always an integer, optional. + Obtained by using ``tmux display -p '#D'``, then all leading spaces + and per cent signs are stripped and the result is converted into an + integer. + Other keys, if any, are specific to segments. Ipython diff --git a/powerline/commands/main.py b/powerline/commands/main.py index da228edf..a5b27ef7 100644 --- a/powerline/commands/main.py +++ b/powerline/commands/main.py @@ -10,7 +10,7 @@ from itertools import chain from powerline.lib.overrides import parsedotval, parse_override_var from powerline.lib.dict import mergeargs from powerline.lib.encoding import get_preferred_arguments_encoding -from powerline.lib.unicode import u +from powerline.lib.unicode import u, unicode if sys.version_info < (3,): @@ -49,6 +49,14 @@ def finish_args(environ, args): )) if args.renderer_arg: args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True) + if 'pane_id' in args.renderer_arg: + if isinstance(args.renderer_arg['pane_id'], (bytes, unicode)): + try: + args.renderer_arg['pane_id'] = int(args.renderer_arg['pane_id'].lstrip(' %')) + except ValueError: + pass + if 'client_id' not in args.renderer_arg: + args.renderer_arg['client_id'] = args.renderer_arg['pane_id'] args.config_path = ( [path for path in environ.get('POWERLINE_CONFIG_PATHS', '').split(':') if path] + (args.config_path or []) diff --git a/powerline/renderers/tmux.py b/powerline/renderers/tmux.py index 33556409..840bbdda 100644 --- a/powerline/renderers/tmux.py +++ b/powerline/renderers/tmux.py @@ -63,7 +63,7 @@ class TmuxRenderer(Renderer): if segment_info: r.update(segment_info) if 'pane_id' in r: - varname = 'TMUX_PWD_' + r['pane_id'].lstrip('% ') + varname = 'TMUX_PWD_' + str(r['pane_id']) if varname in r['environ']: r['getcwd'] = lambda: r['environ'][varname] r['mode'] = mode From 688e50796749739296642b15e66ca733bb802d6b Mon Sep 17 00:00:00 2001 From: Foo Date: Mon, 19 Oct 2015 22:46:20 +0300 Subject: [PATCH 36/39] Install old virtualenvwrapper for 2.6 UCS2 Python --- tests/install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/install.sh b/tests/install.sh index 6c1bbbd0..d9fb48af 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -29,7 +29,11 @@ checkout_cached_dir git://github.com/powerline/deps tests/bot-ci/deps mkdir -p "$HOME/opt" if test -n "$USE_UCS2_PYTHON" ; then - pip install virtualenvwrapper + if test "$UCS2_PYTHON_VARIANT" = "2.6" ; then + pip install 'virtualenvwrapper==4.6.0' + else + pip install virtualenvwrapper + fi set +e . virtualenvwrapper.sh set -e From 0233909189d1c145c1c403b1578fc1ea130d91d7 Mon Sep 17 00:00:00 2001 From: Foo Date: Mon, 19 Oct 2015 23:29:34 +0300 Subject: [PATCH 37/39] Do not allow failures any more --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6be388b4..01429651 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,10 +34,5 @@ matrix: env: >- USE_UCS2_PYTHON=1 UCS2_PYTHON_VARIANT="2.7" - allow_failures: - - python: "2.6" - env: >- - USE_UCS2_PYTHON=1 - UCS2_PYTHON_VARIANT="2.6" # vim: et From e0a62f9cf7a61608a592e6449a690ae2286272a7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 7 Aug 2015 10:43:10 -0500 Subject: [PATCH 38/39] Add hide_domain argument to common.env.user segment If true, this argument hides `@` and the following characters from the user name. Fixes #1420 Closes #1426 --- powerline/segments/common/env.py | 9 ++++++++- tests/test_segments.py | 16 +++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/powerline/segments/common/env.py b/powerline/segments/common/env.py index 0ba7be5f..115514d0 100644 --- a/powerline/segments/common/env.py +++ b/powerline/segments/common/env.py @@ -148,11 +148,13 @@ username = False _geteuid = getattr(os, 'geteuid', lambda: 1) -def user(pl, hide_user=None): +def user(pl, hide_user=None, hide_domain=False): '''Return the current user. :param str hide_user: Omit showing segment for users with names equal to this string. + :param bool hide_domain: + Drop domain component if it exists in a username (delimited by '@'). Highlights the user with the ``superuser`` if the effective user ID is 0. @@ -166,6 +168,11 @@ def user(pl, hide_user=None): return None if username == hide_user: return None + if hide_domain: + try: + username = username[:username.index('@')] + except ValueError: + pass euid = _geteuid() return [{ 'contents': username, diff --git a/tests/test_segments.py b/tests/test_segments.py index 724ba5bd..48683b31 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -496,15 +496,15 @@ class TestEnv(TestCommon): pass def username(self): - return 'def' + return 'def@DOMAIN.COM' if hasattr(self.module, 'psutil') and not callable(self.module.psutil.Process.username): username = property(username) struct_passwd = namedtuple('struct_passwd', ('pw_name',)) new_psutil = new_module('psutil', Process=Process) - new_pwd = new_module('pwd', getpwuid=lambda uid: struct_passwd(pw_name='def')) - new_getpass = new_module('getpass', getuser=lambda: 'def') + new_pwd = new_module('pwd', getpwuid=lambda uid: struct_passwd(pw_name='def@DOMAIN.COM')) + new_getpass = new_module('getpass', getuser=lambda: 'def@DOMAIN.COM') pl = Pl() with replace_attr(self.module, 'pwd', new_pwd): with replace_attr(self.module, 'getpass', new_getpass): @@ -512,12 +512,18 @@ class TestEnv(TestCommon): with replace_attr(self.module, 'psutil', new_psutil): with replace_attr(self.module, '_geteuid', lambda: 5): self.assertEqual(self.module.user(pl=pl), [ - {'contents': 'def', 'highlight_groups': ['user']} + {'contents': 'def@DOMAIN.COM', 'highlight_groups': ['user']} ]) self.assertEqual(self.module.user(pl=pl, hide_user='abc'), [ + {'contents': 'def@DOMAIN.COM', 'highlight_groups': ['user']} + ]) + self.assertEqual(self.module.user(pl=pl, hide_domain=False), [ + {'contents': 'def@DOMAIN.COM', 'highlight_groups': ['user']} + ]) + self.assertEqual(self.module.user(pl=pl, hide_user='def@DOMAIN.COM'), None) + self.assertEqual(self.module.user(pl=pl, hide_domain=True), [ {'contents': 'def', 'highlight_groups': ['user']} ]) - self.assertEqual(self.module.user(pl=pl, hide_user='def'), None) with replace_attr(self.module, '_geteuid', lambda: 0): self.assertEqual(self.module.user(pl=pl), [ {'contents': 'def', 'highlight_groups': ['superuser', 'user']} From 312301b3f4ee1a8f3286cdb7137184d25305526c Mon Sep 17 00:00:00 2001 From: Foo Date: Tue, 20 Oct 2015 12:54:26 +0300 Subject: [PATCH 39/39] Update base version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 23d10562..ab55238c 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ else: def get_version(): - base_version = '2.2' + base_version = '2.3' base_version += '.dev9999' try: return base_version + '+git.' + str(subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip())