From 624068a084cd47298d6b455d5b4942c4574b7125 Mon Sep 17 00:00:00 2001
From: Filip Noetzel <filip@j03.de>
Date: Sat, 18 Apr 2009 23:49:50 +0200
Subject: [PATCH] ./manage.py makemessages: add -D switch for specifying input directories
---
django/core/management/commands/makemessages.py | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index 604cb03..4b73a99 100644
a
|
b
|
def handle_extensions(extensions=('html',)):
|
43 | 43 | # trick xgettext to parse them as Python files) |
44 | 44 | return set([x for x in ext_list if x != '.py']) |
45 | 45 | |
46 | | def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None): |
| 46 | def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, inputdirs=None): |
47 | 47 | """ |
48 | 48 | Uses the locale directory from the Django SVN tree or an application/ |
49 | 49 | project to process all |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
|
97 | 97 | elif all: |
98 | 98 | languages = [el for el in os.listdir(localedir) if not el.startswith('.')] |
99 | 99 | |
| 100 | if inputdirs == None: |
| 101 | inputdirs = ["."] |
| 102 | |
100 | 103 | for locale in languages: |
101 | 104 | if verbosity > 0: |
102 | 105 | print "processing language", locale |
… |
… |
def make_messages(locale=None, domain='django', verbosity='1', all=False, extens
|
111 | 114 | os.unlink(potfile) |
112 | 115 | |
113 | 116 | all_files = [] |
114 | | for (dirpath, dirnames, filenames) in os.walk("."): |
115 | | all_files.extend([(dirpath, f) for f in filenames]) |
| 117 | |
| 118 | for inputdir in inputdirs: |
| 119 | if not os.path.exists(inputdir): |
| 120 | raise CommandError("The input directory '%s' does not exist." % inputdir) |
| 121 | for (dirpath, dirnames, filenames) in os.walk(inputdir): |
| 122 | all_files.extend([(dirpath, f) for f in filenames]) |
| 123 | |
116 | 124 | all_files.sort() |
117 | 125 | for dirpath, file in all_files: |
118 | 126 | file_base, file_ext = os.path.splitext(file) |
… |
… |
class Command(BaseCommand):
|
204 | 212 | make_option('--extension', '-e', dest='extensions', |
205 | 213 | help='The file extension(s) to examine (default: ".html", separate multiple extensions with commas, or use -e multiple times)', |
206 | 214 | action='append'), |
| 215 | make_option('--directory', '-D', dest='inputdirs', |
| 216 | help='add DIRECTORY to list for input files search (default: ".", separate multiple directories with commas, or use -D multiple times)', |
| 217 | action='append'), |
207 | 218 | ) |
208 | 219 | help = "Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory." |
209 | 220 | |
… |
… |
class Command(BaseCommand):
|
219 | 230 | verbosity = int(options.get('verbosity')) |
220 | 231 | process_all = options.get('all') |
221 | 232 | extensions = options.get('extensions') or ['html'] |
| 233 | inputdirs = options.get('inputdirs') |
| 234 | if inputdirs: |
| 235 | inputdirs = (",".join(inputdirs)).split(",") |
222 | 236 | |
223 | 237 | if domain == 'djangojs': |
224 | 238 | extensions = [] |
… |
… |
class Command(BaseCommand):
|
228 | 242 | if '.js' in extensions: |
229 | 243 | raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.") |
230 | 244 | |
231 | | make_messages(locale, domain, verbosity, process_all, extensions) |
| 245 | make_messages(locale, domain, verbosity, process_all, extensions, inputdirs) |