532ff78cc975 — Alain Leufroy 5.3 3 years ago
filter modified file: use regexp

When the user wants to filter modified file in the diff pane, he/she can provide a regexp.
1 files changed, 10 insertions(+), 2 deletions(-)

M lairucrem/controler.py
M lairucrem/controler.py +10 -2
@@ 5,8 5,10 @@ 
 # Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
 """Controller that manage data and connect widgets."""
 import asyncio
+import re
 from collections import defaultdict
 from functools import partial
+from pathlib import Path
 
 import urwid
 

          
@@ 364,7 366,7 @@ class diffstatwalker(_patchdetailwalker)
         else:
             return None
         if self.filename:
-            cmd.append(self.filename)
+            cmd += filter_files(self.filename)
         return cmd
 
     def _parse_line(self, line):

          
@@ 408,7 410,7 @@ class diffwalker(_patchdetailwalker):
         else:
             return None
         if self.filename:
-            cmd.append(self.filename)
+            cmd += filter_files(self.filename)
         return cmd
 
     def _parse_line(self, line):

          
@@ 799,3 801,9 @@ class maincontroler(ensurable):
 
     def enable_commands(self):
         self._graph.connect_commands()
+
+
+def filter_files(expression):
+    regexp = re.compile(expression)
+    paths = tuple(str(p) for p in Path('.').glob('**/*'))
+    return (p for p in paths if regexp.match(p))