Commits

Iñigo Serna committed 4fde165

Fixed bugs: grep with temp files in dir fails, find with files or dirs with spaces.

* lfm/utils.py (do_find): fix bug: show wrong matches if results contain
directories or files with spaces

* lfm/utils.py (do_findgrep): fix bug: pass "-type f" to find as
".#filename" are temporary emacs files/links that break search

* lfm/actions.py (do_show_fs_info): clean code

Comments (0)

Files changed (5)

 
 *~
 *.pyc
-TAGS
+TAGS*
 MANIFEST
+Sun May  8 16:26:55 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/utils.py (do_find): fix bug: show wrong matches if results contain
+	directories or files with spaces
+
+Sun May  8 16:02:24 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/utils.py (do_findgrep): fix bug: pass "-type f" to find as
+	".#filename" are temporary emacs files/links that break search
+
+Sun May  8 15:49:48 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/actions.py (do_show_fs_info): clean code
+
 Sun May  8 01:52:14 2011  Iñigo Serna  <inigoserna@gmail.com>
 
 	* README (summary): added inigo.katxi.org as home page
 ============================================================================
-Last update:	Time-stamp: <2011-05-08 01:55:00 inigo>
+Last update:	Time-stamp: <2011-05-08 16:40:52 inigo>
 ============================================================================
 
 - update sites: katxi, terra, googlecode, freshmeat, cheeseshop, bitbucket
 
 Bugs:
 =====
-- show filesystem: ellipsize_middle if len(fs_name) > 22
-- find files: if results contain dir_with_spaces
+
 
 General:
 ========
   + enhancements:
 1   - un/compress: .tar
 1   - catch exception in main
+1   - look to use key in sort/ed comp python v2.5+
 1   - test and improve PowerCLI
 1   - don't like much how recursive chmod/chown/chgrp currently works
       . split in 2 different features chmod and chown/chgrp ?
 2   - diff and sync dirs: use filecmp.dircmp or rsync
 1 + documentation:
     - document .lfmrc contents
-    - be sure release date is correct in all files
+    - be sure version and release date is correct in all files
     - update NEWS, clean TODO
 
 Low Priority (maybe some day):
-  + remove do_something_on_file => use powercli
-  + more than 10 bookmarks => letters
-  + filter files (f.e. "*py" to only view python files)
-  + emacs-like M-x to run internal commands
-  + global copy/cut/paste between tabs or panes
-  + exclude files (f.e. *.o) in grep
-    - ".#filename" are temporary emacs files/links
-    - grep --exclude=XXX => NON-POSIX, GNU extension
-  + find/grep: checkboxes for ignorecase and regex flags
-  + crypt files
-  + new vfs: .rpm, .cpio, .deb, .jar, .xpi, .egg
-  + i18n
-  + pyview: tab 4/8 chars
-  + show directory under cursor in the other panel: mc: Alt+O
-  + keybindings customization
-  + background processes: copy/move
-  + use mimetypes module
-  + use pyinotify module
-  + plugin system
+  + enhancements:
+    . more than 10 bookmarks => use letters
+    . find/grep
+      - exclude files (f.e. *.o) in findgrep
+        grep --exclude=XXX => NON-POSIX, GNU extension
+      - checkboxes for ignorecase and regex flags
+    . remove do_something_on_file => use powercli
+  + new features:
+    . filter files (f.e. "*py" to only view python files)
+    . emacs-like M-x to run internal commands
+    . global copy/cut/paste between tabs or panes
+    . crypt files
+    . new vfs: .rpm, .cpio, .deb, .jar, .xpi, .egg
+    . show directory under cursor in the other panel: mc: Alt+O
+    . keybindings customization
+    . background processes: copy/move
+  + other:
+    . use mimetypes module
+    . use pyinotify module
+    . plugin system
 
 Very Low Priority (never):
-  + remote vfs: ssh, ftp, smb, webdav => Read FAQ entry about fuse integration
+  + remote vfs: ssh, ftp, smb, webdav => read FAQ entry about fuse integration
   + advanced file rename tool => use PowerCLI
+  + i18n => curses ui programming is very hard when dealing with different languages
+            because strings length could change so it's imposible to design a nice
+            and working interface for every language
   + sessions
   + mouse support
   + UI to configure preferences
   . convoluted issue with link to directory in corner cases
   . rename/backup ".." crashes
   . we should not compress ".."
+  . findgrep: pass "-type f" to find  as ".#filename" are temporary emacs files/links
+    that break search
+  . find: show wrong matches if results contain directories or files with spaces
 - DOCS:
   . README FAQ: added information about fuse ssh, ftp and webdav
   . mention python v2.5+
     app.regenerate()
 
 def toggle_manage_otherpane(tab):
-#     app.prefs.options['manage_otherpane'] = 1 if app.prefs.options['manage_otherpane'] == 0 else 0
+#     app.prefs.options['manage_otherpane'] = 1 if app.prefs.options['manage_otherpane'] == 0 else 0 # python v2.5+
     if app.prefs.options['manage_otherpane'] == 0:
         app.prefs.options['manage_otherpane'] = 1
     else:
 # do show filesystems info
 def do_show_fs_info():
     try:
-        fs = get_shell_output('df -h')
+        buf = get_shell_output('df -h')
     except (IOError, os.error), (errno, strerror):
         messages.error('Cannot show filesystems info\n%s (%s)' % (strerror, errno))
         return
-    if fs is None or fs == '':
+    if buf is None or buf == '':
         messages.error('Cannot show filesystems info\n%s (%s)' % ('Can\'t run "df" command', 0))
         return
-    fs = fs.split('\n')
-    buf = []
-    buf.append((fs[0].strip(), 6))
-    buf.append(('-'*len(fs[0]), 6))
-    for l in fs[1:]:
-        buf.append((l.strip(), 2))
-    pyview.InternalView('Show filesystems info', buf).run()
+    hdr = buf.split('\n')[0].strip()
+    fs = [l.strip() for l in buf.strip().split('\n')[1:]]
+    lst = [(hdr, 6), ('-'*len(hdr), 6)]
+    for l in fs:
+        lst.append((l, 2))
+    pyview.InternalView('Show filesystems info', lst).run()
 
 
 # find and grep
     pat_re = pat_re.replace('[', '\\[').replace(']', '\\]')
     ign = app.prefs.options['grep_ignorecase'] and 'i' or ''
     rex = app.prefs.options['grep_regex'] and 'E' or ''
-    # 1. find . -iname "*.py" -exec grep -EHni PATTERN {} \;
+    # 1. find . -type f -iname "*.py" -exec grep -EHni PATTERN {} \;
     # the slowest, 10x
-    # 2. find . -iname "*py" -print0 | xargs --null grep -EHni PATTERN
+    # 2. find . -type f -iname "*py" -print0 | xargs --null grep -EHni PATTERN
     # maybe the best choice
-    cmd = '%s "%s" -iname "%s" -print0 | %s --null %s -%sHn%s \"%s\"' % \
+    cmd = '%s "%s" -type f -iname "%s" -print0 | %s --null %s -%sHn%s \"%s\"' % \
           (sysprogs['find'], path, files, sysprogs['xargs'], sysprogs['grep'], rex, ign, pat_re)
-    # 3. grep -EHni PATTERN `find . -iname "*.py"`
+    # 3. grep -EHni PATTERN `find . -type f -iname "*.py"`
     # don't like `
     # 4. grep -REHni PATTERN --include "*.py" .
     # the fastest, but non-POSIX, because of: -R, --include
-    cmd = '%s -R%sHn%s \"%s\" --include "%s" "%s"' % \
-          (sysprogs['grep'], rex, ign, pat_re, files, path)
+    # cmd = '%s -R%sHn%s \"%s\" --include "%s" "%s"' % \
+    #       (sysprogs['grep'], rex, ign, pat_re, files, path)
     st, ret = ProcessFunc('Searching',
                           'Searching for \"%s\" in \"%s\" files' % (pattern, files),
                           run_shell, encode(cmd), path, True).run()
     if st < 0: # (-100, -1) => error
         return st, ret
     elif st == 0:
-        ret = ret.split('\n')
+        ret = [f.strip() for f in ret.split('\n') if f.strip() != '']
     matches = []
     if len(ret) > 0:
         # filename:linenumber:matching
     if st < 0: # (-100, -1) => error
         return st, ret
     elif st == 0:
-        ret = ret.split()
+        ret = [f.strip() for f in ret.split('\n') if f.strip() != '']
     matches = []
     if len(ret) > 0:
-        matches = []
         for filename in ret:
             filename = decode(filename).strip().replace(path, '')
             if filename is not None and filename != '':