diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2010-09-24 16:12:21 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2010-09-24 16:12:21 +0200 |
commit | c429f20605314f304551c6b40e0146415b7ae0b8 (patch) | |
tree | dc016208d4d325932a94d014220c4ed2525a1709 /shellutils.py | |
parent | 1ca37b55f874d3df6f97a006c8690b985a86c00b (diff) | |
parent | 8e51e99c31e01f7db033f1bb19b8910059547089 (diff) | |
download | logilab-common-c429f20605314f304551c6b40e0146415b7ae0b8.tar.gz |
backport stable into default
Diffstat (limited to 'shellutils.py')
-rw-r--r-- | shellutils.py | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/shellutils.py b/shellutils.py index 8e3cc3e..deaafb5 100644 --- a/shellutils.py +++ b/shellutils.py @@ -29,9 +29,12 @@ 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, _handle_blacklist +from logilab.common.compat import raw_input +from logilab.common.compat import str_to_bytes -from logilab.common import STD_BLACKLIST try: from logilab.common.proc import ProcInfo, NoSuchProcess except ImportError: @@ -168,22 +171,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 +205,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 @@ -255,7 +248,7 @@ def acquire_lock(lock_file, max_try=10, delay=10, max_delay=3600): while count: try: fd = os.open(lock_file, os.O_EXCL | os.O_RDWR | os.O_CREAT) - os.write(fd, str(os.getpid())) + os.write(fd, str_to_bytes(str(os.getpid())) ) os.close(fd) return True except OSError, e: |