[meld] Remove all map and filter usage



commit 417600337fc6b60e49218ce13ebeb172c3aeb18f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Oct 27 08:02:16 2012 +1000

    Remove all map and filter usage

 meld/dirdiff.py  |   22 ++++++++++++----------
 meld/filediff.py |    6 ++++--
 meld/misc.py     |   18 ++++++++++--------
 meld/vc/_null.py |   10 ++++------
 meld/vc/cvs.py   |    9 +++++----
 meld/vcview.py   |    5 ++---
 6 files changed, 37 insertions(+), 33 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index f360196..40b3040 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -1,5 +1,5 @@
 ### Copyright (C) 2002-2006 Stephen Kennedy <stevek gnome org>
-### Copyright (C) 2009-2011 Kai Willadsen <kai willadsen gmail com>
+### Copyright (C) 2009-2012 Kai Willadsen <kai willadsen gmail com>
 
 ### 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
@@ -438,19 +438,19 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
         if not hasattr(self, "do_to_others_lock"):
             self.do_to_others_lock = 1
             try:
-                for o in filter(lambda x:x!=master, objects[:self.num_panes]):
-                    method = getattr(o,methodname)
+                for o in [x for x in objects[:self.num_panes] if x != master]:
+                    method = getattr(o, methodname)
                     method(*args)
             finally:
                 delattr(self, "do_to_others_lock")
 
     def _sync_vscroll(self, adjustment):
-        adjs = map(lambda x: x.get_vadjustment(), self.scrolledwindow)
-        self._do_to_others( adjustment, adjs, "set_value", (adjustment.value,) )
+        adjs = [sw.get_vadjustment() for sw in self.scrolledwindow]
+        self._do_to_others(adjustment, adjs, "set_value", (adjustment.value,))
 
     def _sync_hscroll(self, adjustment):
-        adjs = map(lambda x: x.get_hadjustment(), self.scrolledwindow)
-        self._do_to_others( adjustment, adjs, "set_value", (adjustment.value,) )
+        adjs = [sw.get_hadjustment() for sw in self.scrolledwindow]
+        self._do_to_others(adjustment, adjs, "set_value", (adjustment.value,))
 
     def _get_focused_pane(self):
         focus = [ t.is_focus() for t in self.treeview ]
@@ -687,7 +687,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
            If it is a file we launch a diff.
            If it is a folder we recursively open diffs for each non equal file.
         """
-        paths = filter(os.path.exists, self.model.value_paths(it))
+        paths = [p for p in self.model.value_paths(it) if os.path.exists(p)]
         self.emit("create-diff", paths)
 
     def launch_comparisons_on_selected(self):
@@ -1156,11 +1156,13 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
             toshow =  self.scrolledwindow[:n] + self.fileentry[:n]
             toshow += self.linkmap[:n-1] + self.diffmap[:n]
             toshow += self.vbox[:n] + self.msgarea_mgr[:n]
-            map( lambda x: x.show(), toshow )
+            for widget in toshow:
+                widget.show()
             tohide =  self.scrolledwindow[n:] + self.fileentry[n:]
             tohide += self.linkmap[n-1:] + self.diffmap[n:]
             tohide += self.vbox[n:] + self.msgarea_mgr[n:]
-            map( lambda x: x.hide(), tohide )
+            for widget in tohide:
+                widget.hide()
             if self.num_panes != 0: # not first time through
                 self.num_panes = n
                 self.on_fileentry_activate(None)
diff --git a/meld/filediff.py b/meld/filediff.py
index 4e2c61f..2bc0e6a 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1566,12 +1566,14 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             toshow =  self.scrolledwindow[:n] + self.fileentry[:n]
             toshow += self.vbox[:n] + self.msgarea_mgr[:n]
             toshow += self.linkmap[:n-1] + self.diffmap[:n]
-            map( lambda x: x.show(), toshow )
+            for widget in toshow:
+                widget.show()
 
             tohide =  self.statusimage + self.scrolledwindow[n:] + self.fileentry[n:]
             tohide += self.vbox[n:] + self.msgarea_mgr[n:]
             tohide += self.linkmap[n-1:] + self.diffmap[n:]
-            map( lambda x: x.hide(), tohide )
+            for widget in tohide:
+                widget.hide()
 
             right_attach = 2 * n
             if self.findbar.widget in self.table:
diff --git a/meld/misc.py b/meld/misc.py
index 237f9ec..ab0855f 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -1,5 +1,6 @@
 ### Copyright (C) 2002-2006 Stephen Kennedy <stevek gnome org>
 ### Copyright (C) 2009 Vincent Legoll <vincent legoll gmail com>
+### Copyright (C) 2012 Kai Willadsen <kai willadsen gmail com>
 
 ### 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
@@ -154,14 +155,15 @@ def all_equal(alist):
 def shorten_names(*names):
     """Remove redunant parts of a list of names (e.g. /tmp/foo{1,2} -> foo{1,2}
     """
-    prefix = os.path.commonprefix( names )
+    # TODO: Update for different path separators
+    prefix = os.path.commonprefix(names)
     prefixslash = prefix.rfind("/") + 1
-    
-    names = map(lambda x: x[prefixslash:], names) # remove common prefix
-    paths = map(lambda x: x.split("/"), names) # split on /
+
+    names = [n[prefixslash:] for n in names]
+    paths = [n.split("/") for n in names]
 
     try:
-        basenames = map(lambda x: x[-1], paths)
+        basenames = [p[-1] for p in paths]
     except IndexError:
         pass
     else:
@@ -171,11 +173,11 @@ def shorten_names(*names):
                     return "[%s] " % alist[0]
                 else:
                     return ""
-            roots = map(firstpart, paths)
+            roots = [firstpart(p) for p in paths]
             base = basenames[0].strip()
-            return [ r+base for r in roots ]
+            return [r + base for r in roots]
     # no common path. empty names get changed to "[None]"
-    return map(lambda x: x or _("[None]"), basenames)
+    return [name or _("[None]") for name in basenames]
 
 def read_pipe_iter(command, errorstream, yield_interval=0.1, workdir=None):
     """Read the output of a shell command iteratively.
diff --git a/meld/vc/_null.py b/meld/vc/_null.py
index cfad1b6..9fefdaa 100644
--- a/meld/vc/_null.py
+++ b/meld/vc/_null.py
@@ -23,6 +23,7 @@
 
 from . import _vc
 
+
 class Vc(_vc.Vc):
 
     CMD = "true"
@@ -46,9 +47,6 @@ class Vc(_vc.Vc):
 
     def lookup_files(self, dirs, files):
         "files is array of (name, path). assume all files in same dir"
-        if len(files) == 0 and len(dirs) == 0:
-            return [],[]
-
-        d = map(lambda x: _vc.Dir(x[1],x[0], _vc.STATE_NONE), dirs)
-        f = map(lambda x: _vc.File(x[1],x[0], _vc.STATE_NONE, None), files)
-        return d,f
+        d = [_vc.Dir(x[1], x[0], _vc.STATE_NONE) for x in dirs]
+        f = [_vc.File(x[1], x[0], _vc.STATE_NONE, None) for x in files]
+        return d, f
diff --git a/meld/vc/cvs.py b/meld/vc/cvs.py
index 7bbbe6d..d3f2df3 100644
--- a/meld/vc/cvs.py
+++ b/meld/vc/cvs.py
@@ -29,6 +29,7 @@ import time
 from meld import misc
 from . import _vc
 
+
 class Vc(_vc.Vc):
     CMD = "cvs"
     # CVSNT is a drop-in replacement for CVS; if found, it is used instead
@@ -68,9 +69,9 @@ class Vc(_vc.Vc):
             # poor mans universal newline
             entries = entries.replace("\r","\n").replace("\n\n","\n")
         except IOError as e: # no cvs dir
-            d = map(lambda x: _vc.Dir(x[1],x[0], _vc.STATE_NONE), dirs)
-            f = map(lambda x: _vc.File(x[1],x[0], _vc.STATE_NONE, None), files)
-            return d,f
+            d = [_vc.Dir(x[1], x[0], _vc.STATE_NONE) for x in dirs]
+            f = [_vc.File(x[1], x[0], _vc.STATE_NONE, None) for x in files]
+            return d, f
 
         try:
             logentries = open(os.path.join(directory, self.VC_DIR, "Entries.Log")).read()
@@ -143,7 +144,7 @@ class Vc(_vc.Vc):
                                 state = _vc.STATE_MODIFIED
                 retfiles.append( _vc.File(path, name, state, rev, tag, options) )
         # known
-        cvsfiles = map(lambda x: x[1], matches)
+        cvsfiles = [x[1] for x in matches]
         # ignored
         try:
             ignored = open(os.path.join(os.environ["HOME"], ".cvsignore")).read().split()
diff --git a/meld/vcview.py b/meld/vcview.py
index 2169cd9..639342d 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -351,9 +351,8 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
                 it = self.model.get_iter_root()
                 root = name
             yield _("[%s] Scanning %s") % (self.label_text, root[prefixlen:])
-            #import time; time.sleep(1.0)
-            
-            entries = filter(showable, self.vc.listdir(root))
+
+            entries = [f for f in self.vc.listdir(root) if showable(f)]
             differences = 0
             for e in entries:
                 differences |= (e.state != tree.STATE_NORMAL)



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