[tor-commits] [arm/master] Taking advantage of str_tools.join()

atagar at torproject.org atagar at torproject.org
Sun Sep 21 01:48:08 UTC 2014


commit 2045a1bcdd98a9e9d793b582d2cb5f1b6c905426
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Sep 17 10:17:48 2014 -0700

    Taking advantage of str_tools.join()
    
    Couple bits we can nicely simplify with stem's new join() method.
---
 arm/graphing/bandwidth_stats.py |   33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py
index 80c105b..57dd047 100644
--- a/arm/graphing/bandwidth_stats.py
+++ b/arm/graphing/bandwidth_stats.py
@@ -220,18 +220,12 @@ class BandwidthStats(graph_panel.GraphStats):
         panel.addstr(labeling_line + 2, 12, 'Connection Closed...')
 
   def get_title(self, width):
-    stats = list(self._title_stats)
+    stats_label = str_tools.join(self._title_stats, ', ', width - 13)
 
-    while True:
-      if not stats:
-        return 'Bandwidth:'
-      else:
-        label = 'Bandwidth (%s):' % ', '.join(stats)
-
-        if len(label) > width:
-          del stats[-1]
-        else:
-          return label
+    if stats_label:
+      return 'Bandwidth (%s):' % stats_label
+    else:
+      return 'Bandwidth:'
 
   def primary_header(self, width):
     return self.get_header_label(width, True)
@@ -253,19 +247,12 @@ class BandwidthStats(graph_panel.GraphStats):
 
     stats[0] = '%-14s' % ('%s/sec' % str_tools.size_label((self.last_primary if is_primary else self.last_secondary) * 1024, 1, False, CONFIG['features.graph.bw.transferInBytes']))
 
-    # drops label's components if there's not enough space
-
-    labeling = graph_type + ' (' + ''.join(stats).strip() + '):'
-
-    while len(labeling) >= width:
-      if len(stats) > 1:
-        del stats[-1]
-        labeling = graph_type + ' (' + ''.join(stats).strip() + '):'
-      else:
-        labeling = graph_type + ':'
-        break
+    stats_label = str_tools.join(stats, '', width - len(graph_type) - 4)
 
-    return labeling
+    if stats_label:
+      return '%s (%s):' % (graph_type, stats_label)
+    else
+      return graph_type + ':'
 
   def get_color(self, is_primary):
     return DL_COLOR if is_primary else UL_COLOR





More information about the tor-commits mailing list