Commits

Jason R. Coombs committed 5bd7641

Added recursive_glob

Comments (0)

Files changed (3)

 Changes
 -------
 
+4.3
+~~~
+
+* Added `jaraco.filesystem.recursive_glob`, which acts like a regular glob,
+  but recurses into sub-directories.
+
 4.2
 ~~~
 

jaraco/filesystem/__init__.py

 import contextlib
 import logging
 import datetime
+import glob
 
 log = logging.getLogger(__name__)
 
 			yield
 		finally:
 			self.popd()
+
+def recursive_glob(root, spec):
+	"""
+	Like iglob, but recurse directories
+
+	>>> any('filesystem.py' in result for result in recursive_glob('.', '*.py'))
+	True
+
+	>>> all(result.startswith('.') for result in recursive_glob('.', '*.py'))
+	True
+
+	>>> len(list(recursive_glob('.', '*.foo')))
+	0
+
+	"""
+	specs = (
+		os.path.join(dirpath, dirname, spec)
+		for dirpath, dirnames, filenames in os.walk(root)
+		for dirname in dirnames
+	)
+
+	return itertools.chain.from_iterable(
+		glob.iglob(spec)
+		for spec in specs
+	)
 setup_params = dict(
 	# convert to bytes to work around UnicodeDecodeError when using bdist --formats gztar
 	name = bytes(name),
-	use_hg_version=dict(increment="0.0.1"),
+	use_hg_version=dict(increment="0.1"),
 	description = 'General utility modules that supply commonly-used functionality',
 	long_description = open('README').read(),
 	author = 'Jason R. Coombs',