mirror of https://github.com/django/django.git
Optimized file copy in TemplateCommand
This commit is contained in:
parent
d75c2ccaa0
commit
1f5b69917d
|
@ -1,5 +1,6 @@
|
||||||
import cgi
|
import cgi
|
||||||
import errno
|
import errno
|
||||||
|
import io
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
|
@ -158,15 +159,15 @@ class TemplateCommand(BaseCommand):
|
||||||
|
|
||||||
# Only render the Python files, as we don't want to
|
# Only render the Python files, as we don't want to
|
||||||
# accidentally render Django templates files
|
# accidentally render Django templates files
|
||||||
with open(old_path, 'rb') as template_file:
|
|
||||||
content = template_file.read()
|
|
||||||
if new_path.endswith(extensions) or filename in extra_files:
|
if new_path.endswith(extensions) or filename in extra_files:
|
||||||
content = content.decode('utf-8')
|
with io.open(old_path, 'r', encoding='utf-8') as template_file:
|
||||||
|
content = template_file.read()
|
||||||
template = Engine().from_string(content)
|
template = Engine().from_string(content)
|
||||||
content = template.render(context)
|
content = template.render(context)
|
||||||
content = content.encode('utf-8')
|
with io.open(new_path, 'w', encoding='utf-8') as new_file:
|
||||||
with open(new_path, 'wb') as new_file:
|
new_file.write(content)
|
||||||
new_file.write(content)
|
else:
|
||||||
|
shutil.copyfile(old_path, new_path)
|
||||||
|
|
||||||
if self.verbosity >= 2:
|
if self.verbosity >= 2:
|
||||||
self.stdout.write("Creating %s\n" % new_path)
|
self.stdout.write("Creating %s\n" % new_path)
|
||||||
|
|
Loading…
Reference in New Issue