Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move management helper function to new utils module.

This allows us to iremove an inter-command import.
  • Loading branch information...
commit 8459eac031b3f0737857facae4aeb2e937b3d9f9 1 parent dfa9324
@ramiro ramiro authored
View
25 django/core/management/commands/makemessages.py
@@ -9,6 +9,7 @@
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 + (
View
2  django/core/management/templates.py
@@ -21,7 +21,7 @@
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)
View
24 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])
Please sign in to comment.
Something went wrong with that request. Please try again.