mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Issue #12285: Merge with 3.4
This commit is contained in:
commit
65e3319283
3 changed files with 60 additions and 30 deletions
|
@ -6,6 +6,7 @@ and building lists of files.
|
||||||
|
|
||||||
import os, re
|
import os, re
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import functools
|
||||||
from distutils.util import convert_path
|
from distutils.util import convert_path
|
||||||
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
|
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
|
||||||
from distutils import log
|
from distutils import log
|
||||||
|
@ -242,35 +243,28 @@ class FileList:
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# Utility functions
|
# Utility functions
|
||||||
|
|
||||||
def findall(dir=os.curdir):
|
def _find_all_simple(path):
|
||||||
"""Find all files under 'dir' and return the list of full filenames
|
|
||||||
(relative to 'dir').
|
|
||||||
"""
|
"""
|
||||||
from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
|
Find all files under 'path'
|
||||||
|
"""
|
||||||
|
results = (
|
||||||
|
os.path.join(base, file)
|
||||||
|
for base, dirs, files in os.walk(path, followlinks=True)
|
||||||
|
for file in files
|
||||||
|
)
|
||||||
|
return filter(os.path.isfile, results)
|
||||||
|
|
||||||
list = []
|
|
||||||
stack = [dir]
|
|
||||||
pop = stack.pop
|
|
||||||
push = stack.append
|
|
||||||
|
|
||||||
while stack:
|
def findall(dir=os.curdir):
|
||||||
dir = pop()
|
"""
|
||||||
names = os.listdir(dir)
|
Find all files under 'dir' and return the list of full filenames.
|
||||||
|
Unless dir is '.', return full filenames with dir prepended.
|
||||||
for name in names:
|
"""
|
||||||
if dir != os.curdir: # avoid the dreaded "./" syndrome
|
files = _find_all_simple(dir)
|
||||||
fullname = os.path.join(dir, name)
|
if dir == os.curdir:
|
||||||
else:
|
make_rel = functools.partial(os.path.relpath, start=dir)
|
||||||
fullname = name
|
files = map(make_rel, files)
|
||||||
|
return list(files)
|
||||||
# Avoid excess stat calls -- just one will do, thank you!
|
|
||||||
stat = os.stat(fullname)
|
|
||||||
mode = stat[ST_MODE]
|
|
||||||
if S_ISREG(mode):
|
|
||||||
list.append(fullname)
|
|
||||||
elif S_ISDIR(mode) and not S_ISLNK(mode):
|
|
||||||
push(fullname)
|
|
||||||
return list
|
|
||||||
|
|
||||||
|
|
||||||
def glob_to_re(pattern):
|
def glob_to_re(pattern):
|
||||||
|
|
|
@ -6,8 +6,10 @@ from distutils import debug
|
||||||
from distutils.log import WARN
|
from distutils.log import WARN
|
||||||
from distutils.errors import DistutilsTemplateError
|
from distutils.errors import DistutilsTemplateError
|
||||||
from distutils.filelist import glob_to_re, translate_pattern, FileList
|
from distutils.filelist import glob_to_re, translate_pattern, FileList
|
||||||
|
from distutils import filelist
|
||||||
|
|
||||||
from test.support import captured_stdout, run_unittest
|
import test.support
|
||||||
|
from test.support import captured_stdout
|
||||||
from distutils.tests import support
|
from distutils.tests import support
|
||||||
|
|
||||||
MANIFEST_IN = """\
|
MANIFEST_IN = """\
|
||||||
|
@ -292,8 +294,40 @@ class FileListTestCase(support.LoggingSilencer,
|
||||||
self.assertWarnings()
|
self.assertWarnings()
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
class FindAllTestCase(unittest.TestCase):
|
||||||
return unittest.makeSuite(FileListTestCase)
|
@test.support.skip_unless_symlink
|
||||||
|
def test_missing_symlink(self):
|
||||||
|
with test.support.temp_cwd():
|
||||||
|
os.symlink('foo', 'bar')
|
||||||
|
self.assertEqual(filelist.findall(), [])
|
||||||
|
|
||||||
|
def test_basic_discovery(self):
|
||||||
|
"""
|
||||||
|
When findall is called with no parameters or with
|
||||||
|
'.' as the parameter, the dot should be omitted from
|
||||||
|
the results.
|
||||||
|
"""
|
||||||
|
with test.support.temp_cwd():
|
||||||
|
os.mkdir('foo')
|
||||||
|
file1 = os.path.join('foo', 'file1.txt')
|
||||||
|
test.support.create_empty_file(file1)
|
||||||
|
os.mkdir('bar')
|
||||||
|
file2 = os.path.join('bar', 'file2.txt')
|
||||||
|
test.support.create_empty_file(file2)
|
||||||
|
expected = [file2, file1]
|
||||||
|
self.assertEqual(sorted(filelist.findall()), expected)
|
||||||
|
|
||||||
|
def test_non_local_discovery(self):
|
||||||
|
"""
|
||||||
|
When findall is called with another path, the full
|
||||||
|
path name should be returned.
|
||||||
|
"""
|
||||||
|
with test.support.temp_dir() as temp_dir:
|
||||||
|
file1 = os.path.join(temp_dir, 'file1.txt')
|
||||||
|
test.support.create_empty_file(file1)
|
||||||
|
expected = [file1]
|
||||||
|
self.assertEqual(filelist.findall(temp_dir), expected)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run_unittest(test_suite())
|
unittest.main()
|
||||||
|
|
|
@ -50,6 +50,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12285: Fix error when distutils encounters symlink.
|
||||||
|
|
||||||
- Issue #27881: Fixed possible bugs when setting sqlite3.Connection.isolation_level.
|
- Issue #27881: Fixed possible bugs when setting sqlite3.Connection.isolation_level.
|
||||||
Based on patch by Xiang Zhang.
|
Based on patch by Xiang Zhang.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue