which now properly resolves to ``en_GB``.
- Fixed a bug that made it impossible to import the CLDR data
from scratch on windows systems.
+- Fixed a bug with extracting messages from "hidden" dirs when
+ they where scanned one after another.
Version 1.3
-----------
import sys
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
-from babel.util import parse_encoding, pathmatch, relpath
+from babel.util import filter_dirs, parse_encoding, pathmatch, relpath
from babel._compat import PY2, text_type
from textwrap import dedent
absname = os.path.abspath(dirname)
for root, dirnames, filenames in os.walk(absname):
- for subdir in dirnames:
- if subdir.startswith('.') or subdir.startswith('_'):
- dirnames.remove(subdir)
+ dirnames = filter_dirs(dirnames)
dirnames.sort()
filenames.sort()
+
for filename in filenames:
filename = relpath(
os.path.join(root, filename).replace(os.sep, '/'),
yield item
seen.add(item)
+
+def filter_dirs(dirnames):
+ """
+ Filters out all unwanted directories from `diranmes`
+
+ Examples:
+
+ >>> filter_dirs(['dir_a', '.dir_b'])
+ ['dir_a', ]
+
+ >>> filter_dirs(['dir_a', 'dir_b', '_dir_c', '.dir_d'])
+ ['dir_a', 'dir_b']
+
+
+ :param dirnames: list of directories
+ """
+ return [
+ subdir for subdir in dirnames
+ if not subdir.startswith('.') and not subdir.startswith('_')
+ ]
+
# Regexp to match python magic encoding line
PYTHON_MAGIC_COMMENT_re = re.compile(
br'[ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)', re.VERBOSE)
from babel import util
+def test_filter_dirs():
+ assert util.filter_dirs(['dir_a', ]) == ['dir_a', ]
+ assert util.filter_dirs(['dir_a', '.dir_b']) == ['dir_a', ]
+ assert util.filter_dirs(['.dir_a', '_dir_b', 'dir_c', 'dir_d']) == [
+ 'dir_c',
+ 'dir_d'
+ ]
+
+
def test_distinct():
assert list(util.distinct([1, 2, 1, 3, 4, 4])) == [1, 2, 3, 4]
assert list(util.distinct('foobar')) == ['f', 'o', 'b', 'a', 'r']