summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-04-18 18:50:26 +0300
committerLars Wirzenius <liw@liw.fi>2015-04-18 18:50:26 +0300
commit3785fdf3eb71c2f190bb01fb0826184b905d8b37 (patch)
tree59121b9bbb3016a5c3e2f5369baaaf0c96426ac6
parent9a2778a7282033226fd8615b19752539569240e5 (diff)
downloadttystatus-3785fdf3eb71c2f190bb01fb0826184b905d8b37.tar.gz
Fix problems found by pep8
-rw-r--r--ttystatus/__init__.py6
-rw-r--r--ttystatus/bytesize.py15
-rw-r--r--ttystatus/bytesize_tests.py21
-rw-r--r--ttystatus/bytespeed.py25
-rw-r--r--ttystatus/bytespeed_tests.py27
-rw-r--r--ttystatus/counter.py10
-rw-r--r--ttystatus/counter_tests.py17
-rw-r--r--ttystatus/elapsed.py14
-rw-r--r--ttystatus/elapsed_tests.py7
-rw-r--r--ttystatus/fmt.py19
-rw-r--r--ttystatus/fmt_tests.py7
-rw-r--r--ttystatus/index.py13
-rw-r--r--ttystatus/index_tests.py15
-rw-r--r--ttystatus/integer.py11
-rw-r--r--ttystatus/integer_tests.py11
-rw-r--r--ttystatus/literal.py8
-rw-r--r--ttystatus/literal_tests.py6
-rw-r--r--ttystatus/messager.py55
-rw-r--r--ttystatus/messager_tests.py23
-rw-r--r--ttystatus/pathname.py15
-rw-r--r--ttystatus/pathname_tests.py9
-rw-r--r--ttystatus/percent.py12
-rw-r--r--ttystatus/percent_tests.py13
-rw-r--r--ttystatus/progressbar.py10
-rw-r--r--ttystatus/progressbar_tests.py23
-rw-r--r--ttystatus/remtime.py22
-rw-r--r--ttystatus/remtime_tests.py23
-rw-r--r--ttystatus/status.py45
-rw-r--r--ttystatus/status_tests.py45
-rw-r--r--ttystatus/string.py10
-rw-r--r--ttystatus/string_tests.py10
-rw-r--r--ttystatus/widget.py27
32 files changed, 276 insertions, 298 deletions
diff --git a/ttystatus/__init__.py b/ttystatus/__init__.py
index 956f06c..307e7a9 100644
--- a/ttystatus/__init__.py
+++ b/ttystatus/__init__.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/ttystatus/bytesize.py b/ttystatus/bytesize.py
index 13ee68b..bd29225 100644
--- a/ttystatus/bytesize.py
+++ b/ttystatus/bytesize.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,14 +22,14 @@ class ByteSize(ttystatus.Widget):
'''Display data size in bytes, KiB, etc.'''
static_width = False
-
+
def __init__(self, name):
self.name = name
self._bytes = 0
def update(self, ts):
self._bytes = ts[self.name]
-
+
def render(self, width):
units = (
(1024**4, 2, 'TiB'),
@@ -37,11 +37,10 @@ class ByteSize(ttystatus.Widget):
(1024**2, 2, 'MiB'),
(1024**1, 1, 'KiB'),
)
-
+
for factor, decimals, unit in units:
if self._bytes >= factor:
return '%.*f %s' % (decimals,
- float(self._bytes) / float(factor),
+ float(self._bytes) / float(factor),
unit)
return '%d B' % self._bytes
-
diff --git a/ttystatus/bytesize_tests.py b/ttystatus/bytesize_tests.py
index 15a0ff5..7f50248 100644
--- a/ttystatus/bytesize_tests.py
+++ b/ttystatus/bytesize_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -31,30 +31,29 @@ class ByteSizeTests(unittest.TestCase):
self.assertEqual(self.w.render(0), '0 B')
def test_formats_zero_bytes_correctly(self):
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.assertEqual(self.w.render(0), '0 B')
def test_formats_one_bytes_correctly(self):
- self.w.update({ 'foo': 1 })
+ self.w.update({'foo': 1})
self.assertEqual(self.w.render(0), '1 B')
def test_formats_1023_bytes_correctly(self):
- self.w.update({ 'foo': 1023 })
+ self.w.update({'foo': 1023})
self.assertEqual(self.w.render(0), '1023 B')
def test_formats_1024_bytes_correctly(self):
- self.w.update({ 'foo': 1024 })
+ self.w.update({'foo': 1024})
self.assertEqual(self.w.render(0), '1.0 KiB')
def test_formats_1_MiB_bytes_correctly(self):
- self.w.update({ 'foo': 1024**2 })
+ self.w.update({'foo': 1024**2})
self.assertEqual(self.w.render(0), '1.00 MiB')
def test_formats_1_GiB_bytes_correctly(self):
- self.w.update({ 'foo': 1024**3 })
+ self.w.update({'foo': 1024**3})
self.assertEqual(self.w.render(0), '1.00 GiB')
def test_formats_1_TiB_bytes_correctly(self):
- self.w.update({ 'foo': 1024**4 })
+ self.w.update({'foo': 1024**4})
self.assertEqual(self.w.render(0), '1.00 TiB')
-
diff --git a/ttystatus/bytespeed.py b/ttystatus/bytespeed.py
index 1e619f2..784cdcf 100644
--- a/ttystatus/bytespeed.py
+++ b/ttystatus/bytespeed.py
@@ -1,15 +1,15 @@
# Copyright 2010, 2012 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -24,16 +24,16 @@ class ByteSpeed(ttystatus.Widget):
'''Display data size in bytes, KiB, etc.'''
static_width = False
-
+
def __init__(self, name, duration=None):
self.name = name
self._duration = None if duration is None else float(duration)
self._data_points = []
-
- def now(self): # pragma: no cover
+
+ def now(self): # pragma: no cover
'''Wrapper around time.time for unit tests to overrride.'''
return time.time()
-
+
def render(self, width):
units = (
(1024**4, 2, 'TiB/s'),
@@ -41,23 +41,23 @@ class ByteSpeed(ttystatus.Widget):
(1024**2, 2, 'MiB/s'),
(1024**1, 1, 'KiB/s'),
)
-
+
if len(self._data_points) < 2:
return '0 B/s'
-
+
oldest_bytes, started = self._data_points[0]
latest_bytes, dummy = self._data_points[-1]
bytes = latest_bytes - oldest_bytes
duration = self.now() - started
speed = bytes / duration
-
+
for factor, decimals, unit in units:
if speed >= factor:
return '%.*f %s' % (decimals,
- float(speed) / float(factor),
+ float(speed) / float(factor),
unit)
return '%.0f B/s' % speed
-
+
def update(self, master):
bytes = master[self.name]
now = self.now()
@@ -69,4 +69,3 @@ class ByteSpeed(ttystatus.Widget):
cutoff = now - self._duration
while self._data_points[0][1] < cutoff:
del self._data_points[0]
-
diff --git a/ttystatus/bytespeed_tests.py b/ttystatus/bytespeed_tests.py
index 437e32b..4ac58d5 100644
--- a/ttystatus/bytespeed_tests.py
+++ b/ttystatus/bytespeed_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -32,36 +32,36 @@ class ByteSpeedTests(unittest.TestCase):
def test_formats_zero_bytes_correctly(self):
self.w.now = lambda: 1
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.w.now = lambda: 2
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.assertEqual(self.w.render(0), '0 B/s')
def test_formats_one_byte_per_second_correctly(self):
self.w.now = lambda: 1
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.w.now = lambda: 2
- self.w.update({ 'foo': 1 })
+ self.w.update({'foo': 1})
self.assertEqual(self.w.render(0), '1 B/s')
def test_formats_ten_bytes_per_second_correctly(self):
self.w.now = lambda: 1
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.w.now = lambda: 11
- self.w.update({ 'foo': 100 })
+ self.w.update({'foo': 100})
self.assertEqual(self.w.render(0), '10 B/s')
def test_formats_ten_tibs_per_second_correctly(self):
self.w.now = lambda: 1
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.w.now = lambda: 2
- self.w.update({ 'foo': 10 * 1024**4 })
+ self.w.update({'foo': 10 * 1024**4})
self.assertEqual(self.w.render(0), '10.00 TiB/s')
def test_keeps_only_two_data_points_with_infinite_duration(self):
for when in range(100):
self.w.now = lambda: when
- self.w.update({ 'foo': 0 })
+ self.w.update({'foo': 0})
self.assertEqual(self.w.render(0), '0 B/s')
def test_shows_current_speed_when_requested(self):
@@ -75,6 +75,5 @@ class ByteSpeedTests(unittest.TestCase):
w = ttystatus.ByteSpeed('foo', duration=5)
for when, bytes in items:
w.now = lambda: when
- w.update({ 'foo': bytes })
+ w.update({'foo': bytes})
self.assertEqual(w.render(0), '0 B/s')
-
diff --git a/ttystatus/counter.py b/ttystatus/counter.py
index d37ed90..7241c7d 100644
--- a/ttystatus/counter.py
+++ b/ttystatus/counter.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -20,7 +20,7 @@ import ttystatus
class Counter(ttystatus.Widget):
'''Display a count of how many times a value has changed.'''
-
+
static_width = False
def __init__(self, name):
@@ -30,7 +30,7 @@ class Counter(ttystatus.Widget):
def render(self, width):
return str(self.count)
-
+
def update(self, master):
if master[self.name] != self.prev:
self.prev = master[self.name]
diff --git a/ttystatus/counter_tests.py b/ttystatus/counter_tests.py
index cadadea..ab9d637 100644
--- a/ttystatus/counter_tests.py
+++ b/ttystatus/counter_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -31,16 +31,15 @@ class CounterTests(unittest.TestCase):
self.assertEqual(self.w.render(0), '0')
def test_counts_one_change(self):
- self.w.update({ 'foo': 'a' })
+ self.w.update({'foo': 'a'})
self.assertEqual(self.w.render(0), '1')
def test_counts_two_changes(self):
- self.w.update({ 'foo': 'a' })
- self.w.update({ 'foo': 'b' })
+ self.w.update({'foo': 'a'})
+ self.w.update({'foo': 'b'})
self.assertEqual(self.w.render(0), '2')
def test_does_not_count_if_value_does_not_change(self):
- self.w.update({ 'foo': 'a' })
- self.w.update({ 'foo': 'a' })
+ self.w.update({'foo': 'a'})
+ self.w.update({'foo': 'a'})
self.assertEqual(self.w.render(0), '1')
-
diff --git a/ttystatus/elapsed.py b/ttystatus/elapsed.py
index cb75722..ebfbb99 100644
--- a/ttystatus/elapsed.py
+++ b/ttystatus/elapsed.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,12 +22,12 @@ import ttystatus
class ElapsedTime(ttystatus.Widget):
'''Display elapsed time since widget was first updated.'''
-
+
def __init__(self):
self.started = None
self.secs = 0
-
- def get_time(self): # pragma: no cover
+
+ def get_time(self): # pragma: no cover
'''Wrapper around time.time() for unit tests to override.'''
return time.time()
@@ -38,7 +38,7 @@ class ElapsedTime(ttystatus.Widget):
mins = secs / 60
secs %= 60
return '%02dh%02dm%02ds' % (hours, mins, secs)
-
+
def update(self, master):
if self.started is None:
self.started = self.get_time()
diff --git a/ttystatus/elapsed_tests.py b/ttystatus/elapsed_tests.py
index b87d57c..d9ec5be 100644
--- a/ttystatus/elapsed_tests.py
+++ b/ttystatus/elapsed_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -41,4 +41,3 @@ class ElapsedtimeTests(unittest.TestCase):
self.w.get_time = lambda: 60*60 + 60 + 1
self.w.update({})
self.assertEqual(self.w.render(0), '01h01m01s')
-
diff --git a/ttystatus/fmt.py b/ttystatus/fmt.py
index bc0bbe8..5f21646 100644
--- a/ttystatus/fmt.py
+++ b/ttystatus/fmt.py
@@ -1,15 +1,15 @@
# Copyright 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,24 +29,24 @@ def _find_widgets():
return subclasses
widgets = _find_widgets()
-
-
+
+
def parse(fmt):
'''Parse format string.'''
-
+
names = [x.__name__ for x in widgets]
namespat = '|'.join(names)
argspat = r'[0-9a-zA-Z,_-]*'
pat = r'%%(?P<class>%s)\((?P<args>%s)\)' % (namespat, argspat)
pat = re.compile(pat)
-
+
result = []
prefix = ''
while fmt:
m = pat.match(fmt)
if m:
if prefix:
- result.append(ttystatus.Literal(prefix))
+ result.append(ttystatus.Literal(prefix))
prefix = ''
klass = getattr(ttystatus, m.group('class'))
argnames = m.group('args').split(',')
@@ -61,6 +61,5 @@ def parse(fmt):
fmt = fmt[1:]
if prefix:
- result.append(ttystatus.Literal(prefix))
+ result.append(ttystatus.Literal(prefix))
return result
-
diff --git a/ttystatus/fmt_tests.py b/ttystatus/fmt_tests.py
index 310f131..4582d00 100644
--- a/ttystatus/fmt_tests.py
+++ b/ttystatus/fmt_tests.py
@@ -1,15 +1,15 @@
# Copyright 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -68,4 +68,3 @@ class FormatTests(unittest.TestCase):
self.assertEqual(x[2].render(0), ': ')
self.assertEqual(type(x[3]), ttystatus.ElapsedTime)
-
diff --git a/ttystatus/index.py b/ttystatus/index.py
index 0158037..95008b1 100644
--- a/ttystatus/index.py
+++ b/ttystatus/index.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -20,7 +20,7 @@ import ttystatus
class Index(ttystatus.Widget):
'''Display the position of a value in a list of values.'''
-
+
static_width = False
def __init__(self, name, listname):
@@ -28,15 +28,14 @@ class Index(ttystatus.Widget):
self.listname = listname
self.value = None
self.listvalue = []
-
+
def render(self, render):
try:
index = self.listvalue.index(self.value) + 1
except ValueError:
index = 0
return '%d/%d' % (index, len(self.listvalue))
-
+
def update(self, master):
self.value = master[self.name]
self.listvalue = master[self.listname]
-
diff --git a/ttystatus/index_tests.py b/ttystatus/index_tests.py
index ccc4d4c..808e2cb 100644
--- a/ttystatus/index_tests.py
+++ b/ttystatus/index_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,12 +29,11 @@ class IndexTests(unittest.TestCase):
def test_is_zero_initially(self):
self.assertEqual(self.w.render(0), '0/0')
-
+
def test_gets_index_right(self):
- self.w.update({ 'foo': 'x', 'foos': ['a', 'x', 'b'] })
+ self.w.update({'foo': 'x', 'foos': ['a', 'x', 'b']})
self.assertEqual(self.w.render(0), '2/3')
-
+
def test_handles_value_not_in_list(self):
- self.w.update({ 'foo': 'xxx', 'foos': ['a', 'x', 'b'] })
+ self.w.update({'foo': 'xxx', 'foos': ['a', 'x', 'b']})
self.assertEqual(self.w.render(0), '0/3')
-
diff --git a/ttystatus/integer.py b/ttystatus/integer.py
index 7995bee..5f7c995 100644
--- a/ttystatus/integer.py
+++ b/ttystatus/integer.py
@@ -1,15 +1,15 @@
# Copyright 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -20,7 +20,7 @@ import ttystatus
class Integer(ttystatus.Widget):
'''Display a value as an integer.'''
-
+
static_width = False
def __init__(self, key):
@@ -32,7 +32,6 @@ class Integer(ttystatus.Widget):
return str(int(self.value))
except (TypeError, ValueError):
return '#'
-
+
def update(self, master):
self.value = master[self._key]
-
diff --git a/ttystatus/integer_tests.py b/ttystatus/integer_tests.py
index e064621..1f91ef2 100644
--- a/ttystatus/integer_tests.py
+++ b/ttystatus/integer_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,12 +29,11 @@ class IntegerTests(unittest.TestCase):
def test_is_error_initially(self):
self.assertEqual(self.w.render(0), '#')
-
+
def test_updates(self):
self.w.update({'foo': 123})
self.assertEqual(self.w.render(0), '123')
-
+
def test_becomes_error_symbol_if_value_is_not_integer(self):
self.w.update({'foo': 'bar'})
self.assertEqual(self.w.render(0), '#')
-
diff --git a/ttystatus/literal.py b/ttystatus/literal.py
index cdeb4d7..cce8553 100644
--- a/ttystatus/literal.py
+++ b/ttystatus/literal.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -20,7 +20,7 @@ import ttystatus
class Literal(ttystatus.Widget):
'''Display a literal string.'''
-
+
def __init__(self, string):
self.value = string
diff --git a/ttystatus/literal_tests.py b/ttystatus/literal_tests.py
index b1e4537..666494d 100644
--- a/ttystatus/literal_tests.py
+++ b/ttystatus/literal_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/ttystatus/messager.py b/ttystatus/messager.py
index 3914013..d1f3312 100644
--- a/ttystatus/messager.py
+++ b/ttystatus/messager.py
@@ -1,15 +1,15 @@
# Copyright 2010, 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -24,7 +24,7 @@ import time
class Messager(object):
'''Write messages to the terminal.'''
-
+
def __init__(self, output=None, period=None, open_tty=None,
fake_width=False):
self._enabled = True
@@ -36,30 +36,30 @@ class Messager(object):
except IOError:
self.output = None
self._period = 1.0 if period is None else period
- self._last_msg = '' # What did we write last?
- self._last_time = 0 # When did we write last?
- self._cached_msg = '' # Last message from user, to write() method.
+ self._last_msg = '' # What did we write last?
+ self._last_time = 0 # When did we write last?
+ self._cached_msg = '' # Last message from user, to write() method.
self._fake_width = fake_width
- self.set_width(self._get_terminal_width()) # Width of terminal
+ self.set_width(self._get_terminal_width()) # Width of terminal
- def _open_tty(self): # pragma: no cover
+ def _open_tty(self): # pragma: no cover
return open('/dev/tty', 'w')
-
+
def set_width(self, actual_width):
self.width = actual_width - 1
-
+
def _now(self):
'''Return current time.'''
# This is a wrapper around time.time(), for testing.
return time.time()
-
- def _get_terminal_width(self): # pragma: no cover
+
+ def _get_terminal_width(self): # pragma: no cover
'''Return width of terminal in characters.
If this fails, assume 80.
-
+
Borrowed and adapted from bzrlib.
-
+
'''
default_width = 80
@@ -80,7 +80,7 @@ class Messager(object):
return default_width
raise
- def update_width(self): # pragma: no cover
+ def update_width(self): # pragma: no cover
new_width = self._get_terminal_width()
if new_width != self.width:
# Clear the terminal from old stuff, using the old width.
@@ -91,12 +91,12 @@ class Messager(object):
def _raw_write(self, string):
'''Write raw data if output is terminal.'''
-
+
if self._enabled and self.output and self.output.isatty():
try:
self.output.write(string)
self.output.flush()
- except IOError: # pragma: no cover
+ except IOError: # pragma: no cover
self._enabled = False
def _overwrite(self, string):
@@ -109,7 +109,7 @@ class Messager(object):
def time_to_write(self):
'''Is it time to write now?'''
return self._now() - self._last_time >= self._period
-
+
def write(self, string):
'''Write raw data, always.'''
self.update_width()
@@ -117,22 +117,22 @@ class Messager(object):
self._overwrite(string)
self._last_time = self._now()
self._cached_msg = string
-
+
def clear(self):
'''Remove current message from terminal.'''
self._overwrite('')
-
+
def notify(self, string, f, force=False):
'''Show a notification message string to the user.
-
+
Notifications are meant for error messages and other things
that do not belong in, say, progress bars. Whatever is currently
on the terminal is wiped, then the notification message is shown,
a new line is started, and the old message is restored.
-
+
Notifications are written even when the output is not going
to a terminal.
-
+
'''
if self._enabled or force:
@@ -145,18 +145,17 @@ class Messager(object):
# We ignore these. No point in crashing if terminal is bad.
pass
self._overwrite(old)
-
+
def finish(self):
'''Finalize output.'''
if self._last_msg or self._cached_msg:
self._overwrite(self._cached_msg)
self._raw_write('\n')
-
+
def disable(self):
'''Disable all output.'''
self._enabled = False
-
+
def enable(self):
'''Enable output to happen.'''
self._enabled = True
-
diff --git a/ttystatus/messager_tests.py b/ttystatus/messager_tests.py
index 40084d7..ea94969 100644
--- a/ttystatus/messager_tests.py
+++ b/ttystatus/messager_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010, 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -34,21 +34,21 @@ class MessagerTests(unittest.TestCase):
def fast_time(self):
return self.messager._last_time + self.messager._period
-
+
def test_sets_output(self):
self.assertEqual(self.messager.output, self.output)
-
+
def test_handles_no_tty(self):
def notty():
raise IOError()
m = ttystatus.Messager(open_tty=notty)
self.assertEqual(m.output, None)
-
+
def test_raw_writes_nothing_if_output_is_not_a_terminal(self):
self.messager.output = StringIO.StringIO()
self.messager._raw_write('foo')
self.assertEqual(self.messager.output.getvalue(), '')
-
+
def test_raw_writes_something_if_output_is_not_a_terminal(self):
self.messager._raw_write('foo')
self.assertEqual(self.output.getvalue(), 'foo')
@@ -61,10 +61,10 @@ class MessagerTests(unittest.TestCase):
self.assertFalse(self.messager.time_to_write())
def test_knows_it_is_time_to_write_after_a_period(self):
- self.messager._last_time = (self.messager._now() -
+ self.messager._last_time = (self.messager._now() -
self.messager._period*2)
self.assert_(self.messager.time_to_write())
-
+
def test_cached_write_writes_first_thing(self):
self.messager.write('foo')
self.assertEqual(self.output.getvalue(), 'foo')
@@ -100,10 +100,10 @@ class MessagerTests(unittest.TestCase):
self.messager.write('foo')
self.messager.finish()
self.assertEqual(self.output.getvalue(), 'foo\r \rfoo\n')
-
+
def test_has_width(self):
self.assertEqual(self.messager.width, 79)
-
+
def test_write_truncates_at_one_less_than_width(self):
self.messager.set_width(4)
self.messager.write('foobar')
@@ -119,4 +119,3 @@ class MessagerTests(unittest.TestCase):
self.messager.enable()
self.messager.write('foo')
self.assertEqual(self.output.getvalue(), 'foo')
-
diff --git a/ttystatus/pathname.py b/ttystatus/pathname.py
index 0fbdbd7..59a38e7 100644
--- a/ttystatus/pathname.py
+++ b/ttystatus/pathname.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -20,20 +20,19 @@ import ttystatus
class Pathname(ttystatus.Widget):
'''Display a pathname.
-
+
If it won't fit completely, truncate from the beginning of the string.
-
+
'''
static_width = False
-
+
def __init__(self, key):
self._key = key
self.pathname = ''
def render(self, width):
return self.pathname[-width:]
-
+
def update(self, master):
self.pathname = master.get(self._key, '')
-
diff --git a/ttystatus/pathname_tests.py b/ttystatus/pathname_tests.py
index 70d6c1e..e9bd87e 100644
--- a/ttystatus/pathname_tests.py
+++ b/ttystatus/pathname_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,7 +29,7 @@ class PathnameTests(unittest.TestCase):
def test_is_empty_initially(self):
self.assertEqual(self.w.render(10), '')
-
+
def test_updates(self):
self.w.update({'foo': 'bar'})
self.assertEqual(self.w.render(10), 'bar')
@@ -41,4 +41,3 @@ class PathnameTests(unittest.TestCase):
def test_truncates_from_beginning(self):
self.w.update({'foo': '/this/is/a/path'})
self.assertEqual(self.w.render(6), 'a/path')
-
diff --git a/ttystatus/percent.py b/ttystatus/percent.py
index 1a60c23..ebe4e61 100644
--- a/ttystatus/percent.py
+++ b/ttystatus/percent.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,14 +22,14 @@ class PercentDone(ttystatus.Widget):
'''Display percent of task done.'''
static_width = False
-
+
def __init__(self, done_name, total_name, decimals=0):
self.done_name = done_name
self.total_name = total_name
self.decimals = decimals
self.done = 0
self.total = 1
-
+
def render(self, render):
try:
done = float(self.done)
@@ -40,7 +40,7 @@ class PercentDone(ttystatus.Widget):
if total < 0.001:
total = 1
return '%.*f %%' % (self.decimals, 100.0 * done / total)
-
+
def update(self, master):
self.done = master[self.done_name]
self.total = master[self.total_name]
diff --git a/ttystatus/percent_tests.py b/ttystatus/percent_tests.py
index 9ffe0b9..be6e448 100644
--- a/ttystatus/percent_tests.py
+++ b/ttystatus/percent_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -31,14 +31,13 @@ class PercentDoneTests(unittest.TestCase):
self.assertEqual(self.w.render(0), '0.0 %')
def test_sets_value(self):
- self.w.update({ 'done': 50, 'total': 100 })
+ self.w.update({'done': 50, 'total': 100})
self.assertEqual(self.w.render(0), '50.0 %')
def test_handles_empty_strings_as_values(self):
- self.w.update({ 'done': '', 'total': '' })
+ self.w.update({'done': '', 'total': ''})
self.assertEqual(self.w.render(0), '0.0 %')
def test_handles_zero_total(self):
- self.w.update({ 'done': 0, 'total': 0 })
+ self.w.update({'done': 0, 'total': 0})
self.assertEqual(self.w.render(0), '0.0 %')
-
diff --git a/ttystatus/progressbar.py b/ttystatus/progressbar.py
index cd0f1a3..5c5663f 100644
--- a/ttystatus/progressbar.py
+++ b/ttystatus/progressbar.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,7 +22,7 @@ class ProgressBar(ttystatus.Widget):
'''Display a progress bar.'''
static_width = False
-
+
def __init__(self, done_name, total_name):
self.done_name = done_name
self.total_name = total_name
@@ -43,7 +43,7 @@ class ProgressBar(ttystatus.Widget):
n_stars = int(round(fraction * width))
n_dashes = int(width - n_stars)
return ('#' * n_stars) + ('-' * n_dashes)
-
+
def update(self, master):
self.done = master[self.done_name]
self.total = master[self.total_name]
diff --git a/ttystatus/progressbar_tests.py b/ttystatus/progressbar_tests.py
index a5dd425..e0f9f85 100644
--- a/ttystatus/progressbar_tests.py
+++ b/ttystatus/progressbar_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -32,34 +32,33 @@ class ProgressBarTests(unittest.TestCase):
self.assertEqual(self.w.render(self.width), '-' * 10)
def test_shows_zero_percent_for_empty_string_total(self):
- self.w.update({ 'done': 1, 'total': '' })
+ self.w.update({'done': 1, 'total': ''})
self.assertEqual(self.w.render(self.width), '-' * 10)
def test_shows_zero_percent_for_zero_total(self):
- self.w.update({ 'done': 1, 'total': 0 })
+ self.w.update({'done': 1, 'total': 0})
self.assertEqual(self.w.render(self.width), '-' * 10)
def test_shows_zero_percent_correctly(self):
- self.w.update({ 'done': 0, 'total': 100 })
+ self.w.update({'done': 0, 'total': 100})
self.assertEqual(self.w.render(self.width), '-' * 10)
def test_shows_one_percent_correctly(self):
- self.w.update({ 'done': 1, 'total': 100 })
+ self.w.update({'done': 1, 'total': 100})
self.assertEqual(self.w.render(self.width), '-' * 10)
def test_shows_ten_percent_correctly(self):
- self.w.update({ 'done': 10, 'total': 100 })
+ self.w.update({'done': 10, 'total': 100})
self.assertEqual(self.w.render(self.width), '#' + '-' * 9)
def test_shows_ninety_percent_correctly(self):
- self.w.update({ 'done': 90, 'total': 100 })
+ self.w.update({'done': 90, 'total': 100})
self.assertEqual(self.w.render(self.width), '#' * 9 + '-')
def test_shows_ninety_ine_percent_correctly(self):
- self.w.update({ 'done': 99, 'total': 100 })
+ self.w.update({'done': 99, 'total': 100})
self.assertEqual(self.w.render(self.width), '#' * 10)
def test_shows_one_hundred_percent_correctly(self):
- self.w.update({ 'done': 100, 'total': 100 })
+ self.w.update({'done': 100, 'total': 100})
self.assertEqual(self.w.render(self.width), '#' * 10)
-
diff --git a/ttystatus/remtime.py b/ttystatus/remtime.py
index cbf55bd..831f08b 100644
--- a/ttystatus/remtime.py
+++ b/ttystatus/remtime.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,7 +22,7 @@ import ttystatus
class RemainingTime(ttystatus.Widget):
'''Display an estimate of the remaining time.'''
-
+
def __init__(self, done_name, total_name):
self.done_name = done_name
self.total_name = total_name
@@ -30,17 +30,17 @@ class RemainingTime(ttystatus.Widget):
self.default = '--h--m--s'
self.done = 0
self.total = 1
-
- def get_time(self): # pragma: no cover
+
+ def get_time(self): # pragma: no cover
'''Return current time.
-
+
This is just a wrapper around time.time() so that it is easier
to override during unit tests.
-
+
'''
-
+
return time.time()
-
+
def render(self, render):
if self.started is None:
self.started = self.get_time()
@@ -56,7 +56,7 @@ class RemainingTime(ttystatus.Widget):
secs %= 60
return '%02dh%02dm%02ds' % (hours, mins, secs)
return self.default
-
+
def update(self, master):
self.done = master[self.done_name]
self.total = master[self.total_name]
diff --git a/ttystatus/remtime_tests.py b/ttystatus/remtime_tests.py
index 90afd42..edd5da3 100644
--- a/ttystatus/remtime_tests.py
+++ b/ttystatus/remtime_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -33,26 +33,25 @@ class RemainingTimeTests(unittest.TestCase):
def test_estimates_and_formats_correctly(self):
self.assertEqual(self.w.render(0), '--h--m--s')
- self.w.update({ 'done': 0, 'total': 100 })
+ self.w.update({'done': 0, 'total': 100})
self.w.get_time = lambda: 5.0
- self.w.update({ 'done': 5, 'total': 100 })
+ self.w.update({'done': 5, 'total': 100})
self.assertEqual(self.w.render(0), '00h01m35s')
self.w.get_time = lambda: 10.0
- self.w.update({ 'done': 5, 'total': 100 })
+ self.w.update({'done': 5, 'total': 100})
self.assertEqual(self.w.render(0), '00h03m10s')
self.w.get_time = lambda: 20.0
- self.w.update({ 'done': 80, 'total': 100 })
+ self.w.update({'done': 80, 'total': 100})
self.assertEqual(self.w.render(0), '00h00m05s')
def test_handles_zero_speed(self):
- self.w.update({ 'done': 0, 'total': 100 })
+ self.w.update({'done': 0, 'total': 100})
self.w.get_time = lambda: 5.0
- self.w.update({ 'done': 0, 'total': 100 })
+ self.w.update({'done': 0, 'total': 100})
self.assertEqual(self.w.render(0), '--h--m--s')
def test_handles_empty_strings_for_done_and_total(self):
- self.w.update({ 'done': '', 'total': '' })
+ self.w.update({'done': '', 'total': ''})
self.w.get_time = lambda: 5.0
- self.w.update({ 'done': '', 'total': '' })
+ self.w.update({'done': '', 'total': ''})
self.assertEqual(self.w.render(0), '--h--m--s')
-
diff --git a/ttystatus/status.py b/ttystatus/status.py
index 1c3e19d..085e91f 100644
--- a/ttystatus/status.py
+++ b/ttystatus/status.py
@@ -1,15 +1,15 @@
# Copyright 2010, 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,36 +22,36 @@ import ttystatus
class TerminalStatus(object):
'''Show status and progress information on a terminal.
-
+
All output is provided via widgets of various kinds. Many widgets
format data that TerminalStatus stores. TerminalStatus provides a
dict interface for setting and retrieving data items. Unlike a real
dict, getting a value for a key that has not been set does not
result in a KeyError exception, but in the empty string being
returned.
-
+
'''
-
+
def __init__(self, output=None, period=None, messager=None):
self._m = messager or ttystatus.Messager(output=output, period=period)
self.clear()
-
+
def add(self, widget):
'''Add a new widget to the status display.'''
self._widgets.append(widget)
def format(self, format_string):
'''Add new widgets based on format string.
-
+
The format string is taken literally, except that ``%%`` is a
literal percent character, and ``%Foo(a,b,c)`` is a widget
of type ``Foo`` with parameters a, b, and c. For example:
``format("hello, %String(name)")``.
-
+
'''
for widget in ttystatus.fmt.parse(format_string):
self.add(widget)
-
+
def clear(self):
'''Remove all widgets.'''
self._widgets = []
@@ -61,11 +61,11 @@ class TerminalStatus(object):
def __getitem__(self, key):
'''Return value for key, or the empty string.'''
return self._values.get(key, '')
-
+
def get(self, key, default=None):
'''Like dict.get.'''
return self._values.get(key, default)
-
+
def __setitem__(self, key, value):
'''Set value for key.'''
self._values[key] = value
@@ -73,19 +73,19 @@ class TerminalStatus(object):
w.update(self)
if self._m.time_to_write():
self._write()
-
+
def flush(self):
'''Force an update of current state to the screen.
-
+
This happens even if it is not yet time to output the screen.
-
+
'''
-
+
self._write()
def _render(self):
'''Render current state of all widgets.'''
-
+
remaining = self._m.width
texts = [None] * len(self._widgets)
@@ -94,7 +94,7 @@ class TerminalStatus(object):
if w.static_width:
texts[i] = w.render(0)
remaining -= len(texts[i])
-
+
for i, w in enumerate(self._widgets):
if not w.static_width:
texts[i] = w.render(remaining)
@@ -109,7 +109,7 @@ class TerminalStatus(object):
def increase(self, key, delta):
'''Increase value for a key by a given amount.'''
self[key] = (self[key] or 0) + delta
-
+
def notify(self, msg):
'''Show a message.'''
self._m.notify(msg, sys.stdout)
@@ -117,17 +117,16 @@ class TerminalStatus(object):
def error(self, msg):
'''Write an error message.'''
self._m.notify(msg, sys.stderr, force=True)
-
+
def finish(self):
'''Finish status display.'''
self._write()
self._m.finish()
-
+
def disable(self):
'''Disable all output.'''
self._m.disable()
-
+
def enable(self):
'''Enable output if it has been disabled.'''
self._m.enable()
-
diff --git a/ttystatus/status_tests.py b/ttystatus/status_tests.py
index 6c24a6c..d9d8bd8 100644
--- a/ttystatus/status_tests.py
+++ b/ttystatus/status_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010, 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -23,7 +23,7 @@ import ttystatus
class DummyMessager(object):
width = 80
-
+
def __init__(self):
self.written = StringIO.StringIO()
self.enabled = True
@@ -33,19 +33,19 @@ class DummyMessager(object):
def time_to_write(self):
return True
-
+
def write(self, string):
self.written.write(string)
-
+
def notify(self, string, f, force=False):
pass
-
+
def finish(self):
pass
-
+
def enable(self):
self.enabled = True
-
+
def disable(self):
self.enabled = False
@@ -54,43 +54,43 @@ class TerminalStatusTests(unittest.TestCase):
def setUp(self):
self.ts = ttystatus.TerminalStatus(messager=DummyMessager())
-
+
def test_has_no_widgets(self):
self.assertEqual(self.ts._widgets, [])
-
+
def test_adds_widget(self):
w = ttystatus.Literal('foo')
self.ts.add(w)
self.assertEqual(self.ts._widgets, [w])
-
+
def test_adds_widgets_from_format_string(self):
self.ts.format('hello, %String(name)')
self.assertEqual(len(self.ts._widgets), 2)
self.assertEqual(type(self.ts._widgets[0]), ttystatus.Literal)
self.assertEqual(type(self.ts._widgets[1]), ttystatus.String)
-
+
def test_removes_all_widgets(self):
self.ts.add(ttystatus.Literal('foo'))
self.ts.clear()
self.assertEqual(self.ts._widgets, [])
-
+
def test_returns_empty_string_for_unknown_value(self):
self.assertEqual(self.ts['foo'], '')
-
+
def test_sets_value(self):
self.ts['foo'] = 'bar'
self.assertEqual(self.ts['foo'], 'bar')
-
+
def test_gets_value(self):
self.ts['foo'] = 'bar'
self.assertEqual(self.ts.get('foo'), 'bar')
-
+
def test_gets_default_value_for_nonexistent_key(self):
self.assertEqual(self.ts.get('foo', 'bar'), 'bar')
-
+
def test_gets_None_for_nonexistent_key_without_default_value(self):
self.assertEqual(self.ts.get('foo'), None)
-
+
def test_updates_widgets_when_value_is_set(self):
w = ttystatus.String('foo')
self.ts.add(w)
@@ -103,13 +103,13 @@ class TerminalStatusTests(unittest.TestCase):
self.assertEqual(self.ts['foo'], 10)
self.ts.increase('foo', 10)
self.assertEqual(self.ts['foo'], 20)
-
+
def test_has_notify_method(self):
self.assertEqual(self.ts.notify('foo'), None)
-
+
def test_has_error_method(self):
self.assertEqual(self.ts.error('foo'), None)
-
+
def test_has_finish_method(self):
self.assertEqual(self.ts.finish(), None)
@@ -165,4 +165,3 @@ class TerminalStatusTests(unittest.TestCase):
self.ts._m.width = 9
text = self.ts._render()
self.assertEqual(text, 'foo---bar')
-
diff --git a/ttystatus/string.py b/ttystatus/string.py
index 92fbf88..dec79b4 100644
--- a/ttystatus/string.py
+++ b/ttystatus/string.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,13 +22,13 @@ class String(ttystatus.Widget):
'''Display a value as a string.'''
static_width = False
-
+
def __init__(self, key):
self._key = key
self.value = ''
def render(self, render):
return str(self.value)
-
+
def update(self, master):
self.value = master[self._key]
diff --git a/ttystatus/string_tests.py b/ttystatus/string_tests.py
index faa266b..432e8f5 100644
--- a/ttystatus/string_tests.py
+++ b/ttystatus/string_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,11 +29,11 @@ class StringTests(unittest.TestCase):
def test_is_empty_initially(self):
self.assertEqual(self.s.render(0), '')
-
+
def test_updates(self):
self.s.update({'foo': 'bar'})
self.assertEqual(self.s.render(0), 'bar')
-
+
def test_handles_non_string_value(self):
self.s.update({'foo': 123})
self.assertEqual(self.s.render(0), '123')
diff --git a/ttystatus/widget.py b/ttystatus/widget.py
index 9d14683..e0fc536 100644
--- a/ttystatus/widget.py
+++ b/ttystatus/widget.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -17,18 +17,18 @@
class Widget(object):
'''Base class for ttystatus widgets.
-
+
Widgets display stuff on screen. The value may depend on data provided
by the user (at creation time), or may be computed from one or more
values in the TerminalStatus object to which the widget object belongs.
-
+
There are two steps:
-
+
* the widget `update` method is called by TerminalStatus whenever
any of the values change
* the widget `render` method is called by TerminalStatus when it is
time to display things
-
+
Widgets may have a static size, or their size may vary. The
``static_width`` property reveals this. This affects rendering:
static sized widgets are rendered at their one static size; variable
@@ -38,12 +38,12 @@ class Widget(object):
widgets are rendered as small as possible in this case.
'''
-
+
static_width = True
-
+
def __str__(self):
raise NotImplementedError()
-
+
def render(self, width):
'''Format the current value.
@@ -51,14 +51,13 @@ class Widget(object):
all of it. If it's not possible for the widget to render itself
small enough to fit into the given width, it may return a larger
string, but the caller will probably truncate it.
-
+
This will be called only when the value actually needs to be
formatted.
-
+
'''
-
+
return ''
def update(self, terminal_status):
'''React to changes in values stored in a TerminalStatus.'''
-