summaryrefslogtreecommitdiff
path: root/django/core/management/commands/compilemessages.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2018-06-13 21:37:46 +0200
committerClaude Paroz <claude@2xlibre.net>2018-06-16 11:52:02 +0200
commit998d7741951c68b194eb9fab02509024bf60949e (patch)
treeb6287e36e9d75bab241fb7d39bd77818dee8fff4 /django/core/management/commands/compilemessages.py
parent553617e61324dd5d9b34c47ceb2b6f20888daf20 (diff)
Fixed #29492 -- Improved compilemessages speed
Diffstat (limited to 'django/core/management/commands/compilemessages.py')
-rw-r--r--django/core/management/commands/compilemessages.py67
1 files changed, 37 insertions, 30 deletions
diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py
index 77dd0f085c..0934874662 100644
--- a/django/core/management/commands/compilemessages.py
+++ b/django/core/management/commands/compilemessages.py
@@ -1,4 +1,5 @@
import codecs
+import concurrent.futures
import glob
import os
@@ -106,35 +107,41 @@ class Command(BaseCommand):
"""
Locations is a list of tuples: [(directory, file), ...]
"""
- for i, (dirpath, f) in enumerate(locations):
- if self.verbosity > 0:
- self.stdout.write('processing file %s in %s\n' % (f, dirpath))
- po_path = os.path.join(dirpath, f)
- if has_bom(po_path):
- self.stderr.write(
- 'The %s file has a BOM (Byte Order Mark). Django only '
- 'supports .po files encoded in UTF-8 and without any BOM.' % po_path
- )
- self.has_errors = True
- continue
- base_path = os.path.splitext(po_path)[0]
+ with concurrent.futures.ThreadPoolExecutor() as executor:
+ futures = []
+ for i, (dirpath, f) in enumerate(locations):
+ if self.verbosity > 0:
+ self.stdout.write('processing file %s in %s\n' % (f, dirpath))
+ po_path = os.path.join(dirpath, f)
+ if has_bom(po_path):
+ self.stderr.write(
+ 'The %s file has a BOM (Byte Order Mark). Django only '
+ 'supports .po files encoded in UTF-8 and without any BOM.' % po_path
+ )
+ self.has_errors = True
+ continue
+ base_path = os.path.splitext(po_path)[0]
- # Check writability on first location
- if i == 0 and not is_writable(base_path + '.mo'):
- self.stderr.write(
- 'The po files under %s are in a seemingly not writable location. '
- 'mo files will not be updated/created.' % dirpath
- )
- self.has_errors = True
- return
+ # Check writability on first location
+ if i == 0 and not is_writable(base_path + '.mo'):
+ self.stderr.write(
+ 'The po files under %s are in a seemingly not writable location. '
+ 'mo files will not be updated/created.' % dirpath
+ )
+ self.has_errors = True
+ return
- args = [self.program] + self.program_options + [
- '-o', base_path + '.mo', base_path + '.po'
- ]
- output, errors, status = popen_wrapper(args)
- if status:
- if errors:
- self.stderr.write('Execution of %s failed: %s.' % (self.program, errors))
- else:
- self.stderr.write('Execution of %s failed.' % self.program)
- self.has_errors = True
+ args = [self.program] + self.program_options + [
+ '-o', base_path + '.mo', base_path + '.po'
+ ]
+ futures.append(executor.submit(popen_wrapper, args))
+
+ for future in concurrent.futures.as_completed(futures):
+ output, errors, status = future.result()
+ if status:
+ if self.verbosity > 0:
+ if errors:
+ self.stderr.write("Execution of %s failed: %s" % (self.program, errors))
+ else:
+ self.stderr.write("Execution of %s failed" % self.program)
+ self.has_errors = True