summaryrefslogtreecommitdiff
path: root/shellutils.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-09-15 14:50:50 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-09-15 14:50:50 +0200
commit9e777836d0b6f51c0728ebe73e8b8d993ba16911 (patch)
treeb88aaebbf5bbccfbd4aa0f7a4eb7215cb198aa83 /shellutils.py
parent55b6e28c45a4aa6c9a29f63495fceb52d9a5a817 (diff)
downloadlogilab-common-9e777836d0b6f51c0728ebe73e8b8d993ba16911.tar.gz
[py3k] remove "os.path.walk" occurencies by using "os.path"
Diffstat (limited to 'shellutils.py')
-rw-r--r--shellutils.py30
1 files changed, 10 insertions, 20 deletions
diff --git a/shellutils.py b/shellutils.py
index 4c6e8a8..7180b5e 100644
--- a/shellutils.py
+++ b/shellutils.py
@@ -29,9 +29,9 @@ import tempfile
import time
import fnmatch
import errno
-from os.path import exists, isdir, islink, basename, join, walk
+from os.path import exists, isdir, islink, basename, join
-from logilab.common import STD_BLACKLIST
+from logilab.common import STD_BLACKLIST, _handle_blacklist
try:
from logilab.common.proc import ProcInfo, NoSuchProcess
except ImportError:
@@ -168,22 +168,14 @@ def find(directory, exts, exclude=False, blacklist=STD_BLACKLIST):
if filename.endswith(ext):
return True
return False
- def func(files, directory, fnames):
- """walk handler"""
- # remove files/directories in the black list
- for norecurs in blacklist:
- try:
- fnames.remove(norecurs)
- except ValueError:
- continue
- for filename in fnames:
- src = join(directory, filename)
- if isdir(src):
- continue
- if match(filename, exts):
- files.append(src)
files = []
- walk(directory, func, files)
+ for dirpath, dirnames, filenames in os.walk(directory):
+ _handle_blacklist(blacklist, dirnames, filenames)
+ # don't append files if the directory is blacklisted
+ dirname = basename(dirpath)
+ if dirname in blacklist:
+ continue
+ files.extend([join(dirpath, f) for f in filenames if match(f, exts)])
return files
@@ -210,11 +202,9 @@ def globfind(directory, pattern, blacklist=STD_BLACKLIST):
iterator over the list of all matching files
"""
for curdir, dirnames, filenames in os.walk(directory):
+ _handle_blacklist(blacklist, dirnames, filenames)
for fname in fnmatch.filter(filenames, pattern):
yield join(curdir, fname)
- for skipped in blacklist:
- if skipped in dirnames:
- dirnames.remove(skipped)
def unzip(archive, destdir):
import zipfile