mirror of
https://github.com/django/django.git
synced 2024-12-26 02:56:25 +00:00
Merge walk and find_files in makemessages command
This commit is contained in:
parent
ab2f65bb7f
commit
fd58d6c258
@ -47,31 +47,27 @@ def _popen(cmd):
|
|||||||
output, errors = p.communicate()
|
output, errors = p.communicate()
|
||||||
return output, errors, p.returncode
|
return output, errors, p.returncode
|
||||||
|
|
||||||
def walk(root, topdown=True, onerror=None, followlinks=False,
|
def find_files(root, ignore_patterns, verbosity, stdout=sys.stdout, symlinks=False):
|
||||||
ignore_patterns=None, verbosity=0, stdout=sys.stdout):
|
|
||||||
"""
|
"""
|
||||||
A version of os.walk that can follow symlinks for Python < 2.6
|
Helper function to get all files in the given root.
|
||||||
"""
|
"""
|
||||||
if ignore_patterns is None:
|
|
||||||
ignore_patterns = []
|
|
||||||
dir_suffix = '%s*' % os.sep
|
dir_suffix = '%s*' % os.sep
|
||||||
norm_patterns = [p[:-len(dir_suffix)] if p.endswith(dir_suffix) else p for p in ignore_patterns]
|
norm_patterns = [p[:-len(dir_suffix)] if p.endswith(dir_suffix) else p for p in ignore_patterns]
|
||||||
for dirpath, dirnames, filenames in os.walk(root, topdown, onerror):
|
all_files = []
|
||||||
remove_dirs = []
|
for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=symlinks):
|
||||||
for dirname in dirnames:
|
for dirname in dirnames[:]:
|
||||||
if is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns):
|
if is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns):
|
||||||
remove_dirs.append(dirname)
|
|
||||||
for dirname in remove_dirs:
|
|
||||||
dirnames.remove(dirname)
|
dirnames.remove(dirname)
|
||||||
if verbosity > 1:
|
if verbosity > 1:
|
||||||
stdout.write('ignoring directory %s\n' % dirname)
|
stdout.write('ignoring directory %s\n' % dirname)
|
||||||
yield (dirpath, dirnames, filenames)
|
for filename in filenames:
|
||||||
if followlinks:
|
if is_ignored(os.path.normpath(os.path.join(dirpath, filename)), ignore_patterns):
|
||||||
for d in dirnames:
|
if verbosity > 1:
|
||||||
p = os.path.join(dirpath, d)
|
stdout.write('ignoring file %s in %s\n' % (filename, dirpath))
|
||||||
if os.path.islink(p):
|
else:
|
||||||
for link_dirpath, link_dirnames, link_filenames in walk(p):
|
all_files.extend([(dirpath, filename)])
|
||||||
yield (link_dirpath, link_dirnames, link_filenames)
|
all_files.sort()
|
||||||
|
return all_files
|
||||||
|
|
||||||
def is_ignored(path, ignore_patterns):
|
def is_ignored(path, ignore_patterns):
|
||||||
"""
|
"""
|
||||||
@ -82,23 +78,6 @@ def is_ignored(path, ignore_patterns):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def find_files(root, ignore_patterns, verbosity, stdout=sys.stdout, symlinks=False):
|
|
||||||
"""
|
|
||||||
Helper function to get all files in the given root.
|
|
||||||
"""
|
|
||||||
all_files = []
|
|
||||||
for (dirpath, dirnames, filenames) in walk(root, followlinks=symlinks,
|
|
||||||
ignore_patterns=ignore_patterns, verbosity=verbosity, stdout=stdout):
|
|
||||||
for filename in filenames:
|
|
||||||
norm_filepath = os.path.normpath(os.path.join(dirpath, filename))
|
|
||||||
if is_ignored(norm_filepath, ignore_patterns):
|
|
||||||
if verbosity > 1:
|
|
||||||
stdout.write('ignoring file %s in %s\n' % (filename, dirpath))
|
|
||||||
else:
|
|
||||||
all_files.extend([(dirpath, filename)])
|
|
||||||
all_files.sort()
|
|
||||||
return all_files
|
|
||||||
|
|
||||||
def copy_plural_forms(msgs, locale, domain, verbosity, stdout=sys.stdout):
|
def copy_plural_forms(msgs, locale, domain, verbosity, stdout=sys.stdout):
|
||||||
"""
|
"""
|
||||||
Copies plural forms header contents from a Django catalog of locale to
|
Copies plural forms header contents from a Django catalog of locale to
|
||||||
|
Loading…
Reference in New Issue
Block a user