diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2013-02-26 22:07:22 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2013-02-26 22:07:22 -0300 |
| commit | 8459eac031b3f0737857facae4aeb2e937b3d9f9 (patch) | |
| tree | d37ceda59ea03b9e2f5306ff2fe91348534b3759 | |
| parent | dfa9324966ce1a38346d15e35805d042848aabf1 (diff) | |
Move management helper function to new utils module.
This allows us to iremove an inter-command import.
| -rw-r--r-- | django/core/management/commands/makemessages.py | 25 | ||||
| -rw-r--r-- | django/core/management/templates.py | 2 | ||||
| -rw-r--r-- | django/core/management/utils.py | 24 |
3 files changed, 26 insertions, 25 deletions
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index daa4c5f023..e0b136a9e2 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -9,6 +9,7 @@ from subprocess import PIPE, Popen import django from django.core.management.base import CommandError, NoArgsCommand +from django.core.management.utils import handle_extensions from django.utils.functional import total_ordering from django.utils.text import get_text_list from django.utils.jslex import prepare_js_for_gettext @@ -130,30 +131,6 @@ def write_pot_file(potfile, msgs): with open(potfile, 'a') as fp: fp.write(msgs) -def handle_extensions(extensions=('html',), ignored=('py',)): - """ - 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). - - 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']) - set(['.html', '.js']) - >>> handle_extensions(['.html, txt,.tpl']) - set(['.html', '.tpl', '.txt']) - """ - ext_list = [] - for ext in extensions: - ext_list.extend(ext.replace(' ', '').split(',')) - 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]) - class Command(NoArgsCommand): option_list = NoArgsCommand.option_list + ( diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 7904b72dd9..0f45399109 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -21,7 +21,7 @@ from django.template import Template, Context from django.utils import archive from django.utils._os import rmtree_errorhandler from django.core.management.base import BaseCommand, CommandError -from django.core.management.commands.makemessages import handle_extensions +from django.core.management.utils import handle_extensions _drive_re = re.compile('^([a-z]):', re.I) diff --git a/django/core/management/utils.py b/django/core/management/utils.py index 4204a313bf..769f9723c1 100644 --- a/django/core/management/utils.py +++ b/django/core/management/utils.py @@ -12,3 +12,27 @@ def popen_wrapper(args): close_fds=os.name != 'nt', universal_newlines=True) output, errors = p.communicate() return output, errors, p.returncode + +def handle_extensions(extensions=('html',), ignored=('py',)): + """ + 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). + + 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']) + set(['.html', '.js']) + >>> handle_extensions(['.html, txt,.tpl']) + set(['.html', '.tpl', '.txt']) + """ + ext_list = [] + for ext in extensions: + ext_list.extend(ext.replace(' ', '').split(',')) + 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]) |
