Simplified handle_extensions management utility

makemessages now doesn't need any special ignoring logic, after
commit bb4a92d784.
This commit is contained in:
Claude Paroz 2014-11-17 09:24:56 +01:00
parent bb4a92d784
commit 6a05f0dfe3
3 changed files with 6 additions and 10 deletions

View File

@ -251,7 +251,7 @@ class Command(BaseCommand):
exts = extensions if extensions else ['js']
else:
exts = extensions if extensions else ['html', 'txt', 'py']
self.extensions = handle_extensions(exts, ignored=())
self.extensions = handle_extensions(exts)
if (locale is None and not exclude and not process_all) or self.domain is None:
raise CommandError("Type '%s help %s' for usage information." % (

View File

@ -85,8 +85,7 @@ class TemplateCommand(BaseCommand):
raise CommandError("Destination directory '%s' does not "
"exist, please create it first." % top_dir)
extensions = tuple(
handle_extensions(options['extensions'], ignored=()))
extensions = tuple(handle_extensions(options['extensions']))
extra_files = []
for file in options['files']:
extra_files.extend(map(lambda x: x.strip(), file.split(',')))

View File

@ -32,19 +32,16 @@ def popen_wrapper(args, os_err_exc_type=CommandError):
)
def handle_extensions(extensions=('html',), ignored=('py',)):
def handle_extensions(extensions):
"""
Organizes multiple extensions that are separated with commas or passed by
using --extension/-e multiple times. Note that the .py extension is ignored
here because of the way non-*.py files are handled in make_messages() (they
are copied to file.ext.py files to trick xgettext to parse them as Python
files).
using --extension/-e multiple times.
For example: running 'django-admin makemessages -e js,txt -e xhtml -a'
would result in an extension list: ['.js', '.txt', '.xhtml']
>>> handle_extensions(['.html', 'html,js,py,py,py,.py', 'py,.py'])
{'.html', '.js'}
{'.html', '.js', '.py'}
>>> handle_extensions(['.html, txt,.tpl'])
{'.html', '.tpl', '.txt'}
"""
@ -54,7 +51,7 @@ def handle_extensions(extensions=('html',), ignored=('py',)):
for i, ext in enumerate(ext_list):
if not ext.startswith('.'):
ext_list[i] = '.%s' % ext_list[i]
return set(x for x in ext_list if x.strip('.') not in ignored)
return set(ext_list)
def find_command(cmd, path=None, pathext=None):