From f547e8b85f13ff6448286796bfc3293312072576 Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 14 Mar 2013 22:38:40 +0400 Subject: [PATCH] Some fixes for flake8 --- powerline/__init__.py | 11 ++++++----- powerline/lib/url.py | 2 +- powerline/renderer.py | 12 ++++++------ powerline/segments/common.py | 34 ++++++---------------------------- powerline/segments/vim.py | 2 +- tests/test_segments.py | 2 +- tests/vim.py | 1 + 7 files changed, 22 insertions(+), 42 deletions(-) diff --git a/powerline/__init__.py b/powerline/__init__.py index e684c44c..1a3ac823 100644 --- a/powerline/__init__.py +++ b/powerline/__init__.py @@ -70,11 +70,12 @@ class Powerline(object): except ImportError as e: sys.stderr.write('Error while importing renderer module: {0}\n'.format(e)) sys.exit(1) - options = {'term_truecolor': common_config.get('term_truecolor', False), - 'ambiwidth': common_config.get('ambiwidth', 1), - 'tmux_escape': common_config.get('additional_escapes') == 'tmux', - 'screen_escape': common_config.get('additional_escapes') == 'screen', - } + options = { + 'term_truecolor': common_config.get('term_truecolor', False), + 'ambiwidth': common_config.get('ambiwidth', 1), + 'tmux_escape': common_config.get('additional_escapes') == 'tmux', + 'screen_escape': common_config.get('additional_escapes') == 'screen', + } self.renderer = Renderer(theme_config, local_themes, theme_kwargs, colorscheme, **options) @staticmethod diff --git a/powerline/lib/url.py b/powerline/lib/url.py index 9d86da1f..6e599349 100644 --- a/powerline/lib/url.py +++ b/powerline/lib/url.py @@ -5,7 +5,7 @@ try: from urllib.request import urlopen from urllib.parse import urlencode as urllib_urlencode # NOQA except ImportError: - from urllib2 import urlopen, HTTPError + from urllib2 import urlopen, HTTPError # NOQA from urllib import urlencode as urllib_urlencode # NOQA diff --git a/powerline/renderer.py b/powerline/renderer.py index a9c3a175..6f517012 100644 --- a/powerline/renderer.py +++ b/powerline/renderer.py @@ -26,12 +26,12 @@ class Renderer(object): self.theme_kwargs = theme_kwargs self.colorscheme = colorscheme self.width_data = { - 'N': 1, # Neutral - 'Na': 1, # Narrow - 'A': getattr(self, 'ambiwidth', 1), # Ambigious - 'H': 1, # Half-width - 'W': 2, # Wide - 'F': 2, # Fullwidth + 'N': 1, # Neutral + 'Na': 1, # Narrow + 'A': getattr(self, 'ambiwidth', 1), # Ambigious + 'H': 1, # Half-width + 'W': 2, # Wide + 'F': 2, # Fullwidth } def strwidth(self, string): diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 61ea332c..72a3931e 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -13,7 +13,7 @@ from powerline.lib.vcs import guess from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment from powerline.lib.time import monotonic from powerline.lib.humanize_bytes import humanize_bytes -from collections import namedtuple, defaultdict +from collections import namedtuple def hostname(only_if_ssh=False): @@ -460,7 +460,7 @@ except ImportError: except IOError: return None - def _get_user(): + def _get_user(): # NOQA return os.environ.get('USER', None) def cpu_load_percent(**kwargs): # NOQA @@ -506,12 +506,12 @@ if os.path.exists('/proc/uptime'): return int(float(f.readline().split()[0])) elif 'psutil' in globals(): from time import time - def _get_uptime(): + def _get_uptime(): # NOQA # 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. return int(time() - psutil.BOOT_TIME) else: - def _get_uptime(): + def _get_uptime(): # NOQA raise NotImplementedError @@ -534,29 +534,7 @@ def uptime(format='{days:02d}d {hours:02d}h {minutes:02d}m'): return format.format(days=int(days), hours=hours, minutes=minutes) -try: - import psutil - - - def get_bytes(interface): - io_counters = psutil.network_io_counters(pernic=True) - if_io = io_counters.get(interface) - if not if_io: - return None - return if_io.bytes_recv, if_io.bytes_sent -except ImportError: - def get_bytes(interface): - try: - with open('/sys/class/net/{interface}/statistics/rx_bytes'.format(interface=interface), 'rb') as file_obj: - rx = int(file_obj.read()) - with open('/sys/class/net/{interface}/statistics/tx_bytes'.format(interface=interface), 'rb') as file_obj: - tx = int(file_obj.read()) - return (rx, tx) - except IOError: - return None - - -class _NetworkLoadSegment(KwThreadedSegment): +class NetworkLoadSegment(KwThreadedSegment): '''Return the network load. Uses the ``psutil`` module if available for multi-platform compatibility, @@ -614,7 +592,7 @@ class _NetworkLoadSegment(KwThreadedSegment): }] -network_load = _NetworkLoadSegment() +network_load = NetworkLoadSegment() def virtualenv(): diff --git a/powerline/segments/vim.py b/powerline/segments/vim.py index 30a1c248..fedee2f8 100644 --- a/powerline/segments/vim.py +++ b/powerline/segments/vim.py @@ -13,7 +13,7 @@ from powerline.theme import requires_segment_info from powerline.lib import add_divider_highlight_group from powerline.lib.vcs import guess from powerline.lib.humanize_bytes import humanize_bytes -from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment +from powerline.lib.threaded import KwThreadedSegment from functools import wraps from collections import defaultdict diff --git a/tests/test_segments.py b/tests/test_segments.py index 592ff3bd..8b407b78 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -4,7 +4,7 @@ from powerline.segments import shell, common import tests.vim as vim_module import sys import os -from tests.lib import Args, urllib_read, replace_module, replace_module_attr, new_module, replace_module_module, replace_env +from tests.lib import Args, urllib_read, replace_module_attr, new_module, replace_module_module, replace_env from tests import TestCase diff --git a/tests/vim.py b/tests/vim.py index 08e57276..6ba67e4a 100644 --- a/tests/vim.py +++ b/tests/vim.py @@ -149,6 +149,7 @@ def _emul_exists(varname): return varname[2:] in _g raise NotImplementedError + @_logged def _emul_line2byte(line): buflines = _buf_lines[_buffer()]