[Python-checkins] [2.7] bpo-31920: Fixed handling directories as arguments in the ``pygettext`` script. (GH-6259) (GH-6436)

Serhiy Storchaka webhook-mailer at python.org
Tue Apr 10 04:04:01 EDT 2018


https://github.com/python/cpython/commit/a61f5da54772b0ea6a7eccf21df08e61585ef712
commit: a61f5da54772b0ea6a7eccf21df08e61585ef712
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-04-10T11:03:52+03:00
summary:

[2.7] bpo-31920: Fixed handling directories as arguments in the ``pygettext`` script. (GH-6259) (GH-6436)

Based on patch by Oleg Krasnikov.
(cherry picked from commit c93938b5beea4c3f592119ebee6d4029558db8de)

files:
A Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst
M Misc/ACKS
M Tools/i18n/pygettext.py

diff --git a/Misc/ACKS b/Misc/ACKS
index ee2e4fc19393..28255740c7f0 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -767,6 +767,7 @@ Jerzy Kozera
 Maksim Kozyarchuk
 Stefan Krah
 Bob Kras
+Oleg Krasnikov
 Sebastian Kreft
 Holger Krekel
 Michael Kremer
diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst b/Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst
new file mode 100644
index 000000000000..39c694b0728d
--- /dev/null
+++ b/Misc/NEWS.d/next/Tools-Demos/2018-03-26-18-54-24.bpo-31920.u_WKsT.rst
@@ -0,0 +1,2 @@
+Fixed handling directories as arguments in the ``pygettext`` script. Based
+on patch by Oleg Krasnikov.
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py
index a62d2fe441f8..ddd750ed44d6 100755
--- a/Tools/i18n/pygettext.py
+++ b/Tools/i18n/pygettext.py
@@ -261,25 +261,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 not globals().has_key('_py_ext'):
-        global _py_ext
-        _py_ext = [triple[0] for triple in imp.get_suffixes()
-                   if triple[2] == imp.PY_SOURCE][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 _get_modpkg_path(dotted_name, pathlist=None):
     """Get the filesystem path for a module or a package.
 
@@ -340,7 +321,20 @@ def getFilesForName(name):
     if os.path.isdir(name):
         # find all python files in directory
         list = []
-        os.path.walk(name, _visit_pyfiles, list)
+        # get extension for python source files
+        if '_py_ext' not in globals():
+            global _py_ext
+            _py_ext = [triple[0] for triple in imp.get_suffixes()
+                       if triple[2] == imp.PY_SOURCE][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



More information about the Python-checkins mailing list