Add support for omitting VALUE

This will remove error reported in #853, but not its cause
This commit is contained in:
ZyX 2014-05-04 12:58:09 +04:00
parent 5d03fdebe1
commit be2fe98a21
5 changed files with 20 additions and 4 deletions

View File

@ -472,11 +472,17 @@ Powerline script has a number of options controlling powerline behavior. Here
example: ``{"K1": V1, "K2": V2}``) is recursively merged with the contents
of the file.
If ``VALUE`` is omitted then corresponding key will be removed from the
configuration (if it was present).
``-t THEME_NAME.KEY.NESTED_KEY=VALUE`` or ``--theme_option=THEME_NAME.KEY.NESTED_KEY=VALUE``
Overrides options from :file:`powerline/themes/{ext}/{THEME_NAME}.json`.
``KEY.NESTED_KEY=VALUE`` is processed like described above, ``{ext}`` is the
first argument to powerline script. May be passed multiple times.
If ``VALUE`` is omitted then corresponding key will be removed from the
configuration (if it was present).
``-p PATH`` or ``--config_path=PATH``
Sets directory where configuration should be read from. If present, no
default locations are searched for configuration. No expansions are

View File

@ -3,6 +3,9 @@ from functools import wraps
import json
REMOVE_THIS_KEY = object()
def wraps_saveargs(wrapped):
def dec(wrapper):
r = wraps(wrapped)(wrapper)
@ -17,6 +20,8 @@ def mergedicts(d1, d2):
for k in d2:
if k in d1 and type(d1[k]) is dict and type(d2[k]) is dict:
mergedicts(d1[k], d2[k])
elif d2[k] is REMOVE_THIS_KEY:
d1.pop(k, None)
else:
d1[k] = d2[k]
@ -45,7 +50,9 @@ def keyvaluesplit(s):
idx = s.index('=')
o = s[:idx]
rest = s[idx + 1:]
if rest[0] in '"{[0193456789' or rest in ('null', 'true', 'false'):
if not rest:
val = REMOVE_THIS_KEY
elif rest[0] in '"{[0193456789' or rest in ('null', 'true', 'false'):
val = json.loads(s[idx + 1:])
else:
val = rest

View File

@ -7,8 +7,7 @@ from powerline.lib import mergedicts, parsedotval
def mergeargs(argvalue):
if not argvalue:
return None
argvalue = iter(argvalue)
r = dict([next(argvalue)])
r = {}
for subval in argvalue:
mergedicts(r, dict([subval]))
return r

View File

@ -94,6 +94,8 @@ class TestParser(TestCase):
'renderer_arg': {'smth': {'abc': 'def'}},
}),
(['shell', '-R', 'arg=true'], {'ext': ['shell'], 'renderer_arg': {'arg': True}}),
(['shell', '-R', 'arg=true', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}),
(['shell', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}),
(['shell', '-t', 'default.segment_info={"hostname": {}}'], {
'ext': ['shell'],
'theme_option': {

View File

@ -1,7 +1,7 @@
# vim:fileencoding=utf-8:noet
from __future__ import division
from powerline.lib import mergedicts, add_divider_highlight_group
from powerline.lib import mergedicts, add_divider_highlight_group, REMOVE_THIS_KEY
from powerline.lib.humanize_bytes import humanize_bytes
from powerline.lib.vcs import guess
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment
@ -354,6 +354,8 @@ class TestLib(TestCase):
self.assertEqual(d, {'abc': {'def': {'ghi': 'jkl'}}})
mergedicts(d, {'abc': {'mno': 'pqr'}})
self.assertEqual(d, {'abc': {'def': {'ghi': 'jkl'}, 'mno': 'pqr'}})
mergedicts(d, {'abc': {'def': REMOVE_THIS_KEY}})
self.assertEqual(d, {'abc': {'mno': 'pqr'}})
def test_add_divider_highlight_group(self):
def decorated_function_name(**kwargs):