[meld] dirdiff, misc: Move all_same helper into misc and refactor



commit a4025003aa4ad094a13b433dd5f0cea8bad9dd98
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Feb 8 09:22:30 2015 +1000

    dirdiff, misc: Move all_same helper into misc and refactor

 meld/dirdiff.py |    5 +----
 meld/misc.py    |   16 ++++------------
 2 files changed, 5 insertions(+), 16 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 23a30d8..4f30c77 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -44,6 +44,7 @@ from collections import namedtuple
 from decimal import Decimal
 
 from meld.conf import _
+from meld.misc import all_same
 from meld.settings import bind_settings, meldsettings, settings
 
 
@@ -88,10 +89,6 @@ Same, SameFiltered, DodgySame, DodgyDifferent, Different, FileError = \
 CHUNK_SIZE = 4096
 
 
-def all_same(lst):
-    return not lst or lst.count(lst[0]) == len(lst)
-
-
 def remove_blank_lines(text):
     splits = text.splitlines()
     lines = text.splitlines(True)
diff --git a/meld/misc.py b/meld/misc.py
index 28ac575..c784934 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -145,17 +145,9 @@ def gdk_to_cairo_color(color):
     return (color.red / 65535., color.green / 65535., color.blue / 65535.)
 
 
-def all_equal(alist):
-    """Return true if all members of the list are equal to the first.
-
-    An empty list is considered to have all elements equal.
-    """
-    if len(alist):
-        first = alist[0]
-        for n in alist[1:]:
-            if n != first:
-                return 0
-    return 1
+def all_same(lst):
+    """Return True if all elements of the list are equal"""
+    return not lst or lst.count(lst[0]) == len(lst)
 
 
 def shorten_names(*names):
@@ -173,7 +165,7 @@ def shorten_names(*names):
     except IndexError:
         pass
     else:
-        if all_equal(basenames):
+        if all_same(basenames):
             def firstpart(alist):
                 if len(alist) > 1:
                     return "[%s] " % alist[0]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]