From a47a48639467b0fdf4a0897f521475a59a646b44 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 6 Jan 2015 22:47:35 +0300 Subject: [PATCH] Make `powerline-config` also accept overrides from env variables Ref #1201 --- powerline/bindings/config.py | 14 ++++++++++++-- powerline/commands/main.py | 16 ++++++++++++++++ powerline/tmux.py | 16 ---------------- 3 files changed, 28 insertions(+), 18 deletions(-) delete mode 100644 powerline/tmux.py diff --git a/powerline/bindings/config.py b/powerline/bindings/config.py index 11a4b2d8..92051dd6 100644 --- a/powerline/bindings/config.py +++ b/powerline/bindings/config.py @@ -8,11 +8,12 @@ import sys from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY from powerline.lib.config import ConfigLoader from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config -from powerline.tmux import TmuxPowerline +from powerline.shell import ShellPowerline from powerline.lib.shell import which from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, set_tmux_environment, get_tmux_version from powerline.lib.encoding import get_preferred_output_encoding from powerline.renderers.tmux import attrs_to_tmux_attrs +from powerline.commands.main import finish_args CONFIG_FILE_NAME = re.compile(r'powerline_tmux_(?P\d+)\.(?P\d+)(?P[a-z]+)?(?:_(?Pplus|minus))?\.conf') @@ -77,10 +78,19 @@ def source_tmux_files(pl, args): run_tmux_command('refresh-client') +class EmptyArgs(object): + def __init__(self, ext, config_path): + self.ext = ext + self.config_path = None + + def __getattr__(self, attr): + return None + + def init_environment(pl, args): '''Initialize tmux environment from tmux configuration ''' - powerline = TmuxPowerline(args.config_path) + powerline = ShellPowerline(finish_args(EmptyArgs('tmux', args.config_path))) # TODO Move configuration files loading out of Powerline object and use it # directly powerline.update_renderer() diff --git a/powerline/commands/main.py b/powerline/commands/main.py index c97a6ffb..1bcb7fdd 100644 --- a/powerline/commands/main.py +++ b/powerline/commands/main.py @@ -23,6 +23,21 @@ else: def finish_args(environ, args): + '''Do some final transformations + + Transforms ``*_override`` arguments into dictionaries, adding overrides from + environment variables. Transforms ``renderer_arg`` argument into dictionary + as well, but only if it is true. + + :param dict environ: + Environment from which additional overrides should be taken from. + :param args: + Arguments object returned by + :py:meth:`argparse.ArgumentParser.parse_args`. Will be modified + in-place. + + :return: Object received as second (``args``) argument. + ''' args.config_override = mergeargs(chain( (parsedotval(v) for v in args.config_override or ()), parse_override_var(environ.get('POWERLINE_CONFIG_OVERRIDES', '')), @@ -33,6 +48,7 @@ def finish_args(environ, args): )) if args.renderer_arg: args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True) + return args def get_argparser(ArgumentParser=argparse.ArgumentParser): diff --git a/powerline/tmux.py b/powerline/tmux.py deleted file mode 100644 index 15f42127..00000000 --- a/powerline/tmux.py +++ /dev/null @@ -1,16 +0,0 @@ -# vim:fileencoding=utf-8:noet -from __future__ import (unicode_literals, division, absolute_import, print_function) - -from powerline import Powerline - - -class TmuxPowerline(Powerline): - def init(self, config_paths): - self.paths = config_paths - return super(TmuxPowerline, self).init('tmux') - - def get_config_paths(self): - if self.paths: - return self.paths - else: - return super(TmuxPowerline, self).get_config_paths()