summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-04-09 17:57:52 (GMT)
committerGitHub <noreply@github.com>2018-04-09 17:57:52 (GMT)
commit9b25bd6e26b50ade8d52a85c78d957b1f6f9131c (patch)
treee02a1cef350345c9f0f6e5aa19f5cad034aa15df /Tools
parent558e7e42becd52dc6fa828b072083c6855be6f8b (diff)
downloadcpython-9b25bd6e26b50ade8d52a85c78d957b1f6f9131c.zip
cpython-9b25bd6e26b50ade8d52a85c78d957b1f6f9131c.tar.gz
cpython-9b25bd6e26b50ade8d52a85c78d957b1f6f9131c.tar.bz2
bpo-31920: Fixed handling directories as arguments in the ``pygettext`` script. (GH-6259)
Based on patch by Oleg Krasnikov. (cherry picked from commit c93938b5beea4c3f592119ebee6d4029558db8de) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/i18n/pygettext.py30
1 files changed, 11 insertions, 19 deletions
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py
index 0f0395a..13d7a64 100755
--- a/Tools/i18n/pygettext.py
+++ b/Tools/i18n/pygettext.py
@@ -259,24 +259,6 @@ def containsAny(str, set):
return 1 in [c in str for c in set]
-def _visit_pyfiles(list, dirname, names):
- """Helper for getFilesForName()."""
- # get extension for python source files
- if '_py_ext' not in globals():
- global _py_ext
- _py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
-
- # don't recurse into CVS directories
- if 'CVS' in names:
- names.remove('CVS')
-
- # add all *.py files to list
- list.extend(
- [os.path.join(dirname, file) for file in names
- if os.path.splitext(file)[1] == _py_ext]
- )
-
-
def getFilesForName(name):
"""Get a list of module files for a filename, a module or package name,
or a directory.
@@ -302,7 +284,17 @@ def getFilesForName(name):
if os.path.isdir(name):
# find all python files in directory
list = []
- os.walk(name, _visit_pyfiles, list)
+ # get extension for python source files
+ _py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
+ for root, dirs, files in os.walk(name):
+ # don't recurse into CVS directories
+ if 'CVS' in dirs:
+ dirs.remove('CVS')
+ # add all *.py files to list
+ list.extend(
+ [os.path.join(root, file) for file in files
+ if os.path.splitext(file)[1] == _py_ext]
+ )
return list
elif os.path.exists(name):
# a single file