Merge remote-tracking branch 'zyx-i/pl-argument' into develop

This commit is contained in:
Kim Silkebækken 2013-03-24 17:11:29 +01:00
commit 68e29a7eba
12 changed files with 20 additions and 13 deletions

View File

@ -1,13 +1,13 @@
from sphinx.ext import autodoc from sphinx.ext import autodoc
from sphinx.util.inspect import getargspec from sphinx.util.inspect import getargspec
from inspect import ArgSpec, getargspec, formatargspec from inspect import ArgSpec, formatargspec
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment
from itertools import count from itertools import count
try: try:
from __builtin__ import unicode from __builtin__ import unicode
except ImportError: except ImportError:
unicode = lambda s, enc: s unicode = lambda s, enc: s # NOQA
def formatvalue(val): def formatvalue(val):

View File

@ -38,7 +38,7 @@ class PowerlineState(object):
def _log(self, attr, msg, *args, **kwargs): def _log(self, attr, msg, *args, **kwargs):
prefix = kwargs.get('prefix') or self.prefix prefix = kwargs.get('prefix') or self.prefix
msg = ((prefix + ':') if prefix else '') + msg.format(*args, **kwargs) msg = ((prefix + ':') if prefix else '') + msg.format(*args, **kwargs)
key = attr+':'+prefix key = attr + ':' + prefix
if msg != self.last_msgs.get(key): if msg != self.last_msgs.get(key):
getattr(self.logger, attr)(msg) getattr(self.logger, attr)(msg)
self.last_msgs[key] = msg self.last_msgs[key] = msg
@ -144,6 +144,7 @@ class Powerline(object):
level = getattr(logging, common_config.get('log_level', 'WARNING')) level = getattr(logging, common_config.get('log_level', 'WARNING'))
handler = self.get_log_handler(common_config) handler = self.get_log_handler(common_config)
handler.setLevel(level) handler.setLevel(level)
handler.setFormatter(formatter)
logger = logging.getLogger('powerline') logger = logging.getLogger('powerline')
logger.setLevel(level) logger.setLevel(level)

View File

@ -1,6 +1,6 @@
# vim:fileencoding=utf-8:noet # vim:fileencoding=utf-8:noet
from powerline.ipython import IpythonPowerline from powerline.ipython import IpythonPowerline
from IPython.Prompts import BasePrompt, Prompt1 from IPython.Prompts import BasePrompt
from IPython.ipapi import get as get_ipython from IPython.ipapi import get as get_ipython
from IPython.ipapi import TryNext from IPython.ipapi import TryNext
@ -88,6 +88,7 @@ class PowerlinePrompt1(PowerlinePrompt):
return RewriteResult(self.powerline.renderer.render(matcher_info='rewrite', width=self.prompt_text_len, segment_info=self.powerline_segment_info) return RewriteResult(self.powerline.renderer.render(matcher_info='rewrite', width=self.prompt_text_len, segment_info=self.powerline_segment_info)
+ (' ' * self.nrspaces)) + (' ' * self.nrspaces))
class PowerlinePromptOut(PowerlinePrompt): class PowerlinePromptOut(PowerlinePrompt):
powerline_prompt_type = 'out' powerline_prompt_type = 'out'

View File

@ -56,6 +56,7 @@ if sys.version_info < (3,) or not hasattr(vim, 'bindeval'):
getbufvar = vim_get_func('getbufvar') getbufvar = vim_get_func('getbufvar')
else: else:
_getbufvar = vim_get_func('getbufvar') _getbufvar = vim_get_func('getbufvar')
def getbufvar(*args): def getbufvar(*args):
r = _getbufvar(*args) r = _getbufvar(*args)
if type(r) is bytes: if type(r) is bytes:

View File

@ -27,7 +27,7 @@ class ScannerError(MarkedError):
try: try:
from __builtin__ import unicode from __builtin__ import unicode
except ImportError: except ImportError:
unicode = str unicode = str # NOQA
class SimpleKey: class SimpleKey:

View File

@ -61,7 +61,7 @@ class VimRenderer(Renderer):
# renderer # renderer
return vim.strwidth(string.encode('utf-8')) return vim.strwidth(string.encode('utf-8'))
else: else:
@staticmethod @staticmethod # NOQA
def strwidth(string): def strwidth(string):
return vim.strwidth(string) return vim.strwidth(string)

View File

@ -389,7 +389,7 @@ class WeatherSegment(ThreadedSegment):
try: try:
icon_names = weather_conditions_codes[condition_code] icon_names = weather_conditions_codes[condition_code]
except IndexError as e: except IndexError:
if condition_code == 3200: if condition_code == 3200:
icon_names = ('not_available',) icon_names = ('not_available',)
self.warn('Weather is not available for location {0}', self.location) self.warn('Weather is not available for location {0}', self.location)
@ -561,7 +561,7 @@ except ImportError:
tx = int(file_obj.read()) tx = int(file_obj.read())
return (rx, tx) return (rx, tx)
def _get_interfaces(): def _get_interfaces(): # NOQA
for interface in os.listdir('/sys/class/net'): for interface in os.listdir('/sys/class/net'):
x = _get_bytes(interface) x = _get_bytes(interface)
if x is not None: if x is not None:
@ -613,6 +613,7 @@ if os.path.exists('/proc/uptime'):
return int(float(f.readline().split()[0])) return int(float(f.readline().split()[0]))
elif 'psutil' in globals(): elif 'psutil' in globals():
from time import time from time import time
def _get_uptime(): # NOQA def _get_uptime(): # NOQA
# psutil.BOOT_TIME is not subject to clock adjustments, but time() is. # psutil.BOOT_TIME is not subject to clock adjustments, but time() is.
# Thus it is a fallback to /proc/uptime reading and not the reverse. # Thus it is a fallback to /proc/uptime reading and not the reverse.

View File

@ -2,6 +2,7 @@
from powerline.theme import requires_segment_info from powerline.theme import requires_segment_info
@requires_segment_info @requires_segment_info
def prompt_count(pl, segment_info): def prompt_count(pl, segment_info):
return str(segment_info.prompt_count) return str(segment_info.prompt_count)

View File

@ -1,7 +1,6 @@
# vim:fileencoding=utf-8:noet # vim:fileencoding=utf-8:noet
import imp import imp
import sys import sys
import os
class Pl(object): class Pl(object):
@ -21,9 +20,8 @@ class Pl(object):
return self._cwd return self._cwd
for meth in ('error', 'warn', 'debug'): for meth in ('error', 'warn', 'debug'):
exec ('''def {0}(self, msg, *args, **kwargs): exec (('def {0}(self, msg, *args, **kwargs):\n'
self.{0}s.append((kwargs.get('prefix') or self.prefix, msg, args, kwargs)) ' self.{0}s.append((kwargs.get("prefix") or self.prefix, msg, args, kwargs))\n').format(meth))
''').format(meth)
class Args(object): class Args(object):

View File

@ -196,6 +196,7 @@ class TestCommon(TestCase):
return None return None
f = [gb] f = [gb]
def _get_bytes(interface): def _get_bytes(interface):
return f[0](interface) return f[0](interface)
@ -237,9 +238,11 @@ class TestCommon(TestCase):
{'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_group': ['network_load_recv_gradient', 'network_load_gradient', 'network_load_recv', 'network_load'], 'gradient_level': 100}, {'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_group': ['network_load_recv_gradient', 'network_load_gradient', 'network_load_recv', 'network_load'], 'gradient_level': 100},
{'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_group': ['network_load_sent', 'network_load']}, {'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_group': ['network_load_sent', 'network_load']},
]) ])
class ApproxEqual(object): class ApproxEqual(object):
def __eq__(self, i): def __eq__(self, i):
return abs(i - 50.0) < 1 return abs(i - 50.0) < 1
self.assertEqual(common.network_load(pl=pl, recv_format='r {value}', sent_format='s {value}', sent_max=4800), [ self.assertEqual(common.network_load(pl=pl, recv_format='r {value}', sent_format='s {value}', sent_max=4800), [
{'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_group': ['network_load_recv', 'network_load']}, {'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_group': ['network_load_recv', 'network_load']},
{'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_group': ['network_load_sent_gradient', 'network_load_gradient', 'network_load_sent', 'network_load'], 'gradient_level': ApproxEqual()}, {'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_group': ['network_load_sent_gradient', 'network_load_gradient', 'network_load_sent', 'network_load'], 'gradient_level': ApproxEqual()},

View File

@ -45,6 +45,7 @@ def _construct_result(r):
def _str_func(func): def _str_func(func):
from functools import wraps from functools import wraps
@wraps(func) @wraps(func)
def f(*args, **kwargs): def f(*args, **kwargs):
return _construct_result(func(*args, **kwargs)) return _construct_result(func(*args, **kwargs))

View File

@ -7,7 +7,7 @@ from itertools import groupby
try: try:
from __builtin__ import unicode from __builtin__ import unicode
except ImportError: except ImportError:
unicode = str unicode = str # NOQA
if len(sys.argv) == 1 or sys.argv[1] == '--help': if len(sys.argv) == 1 or sys.argv[1] == '--help':