Kaydet (Commit) 94a38dfd authored tarafından Jannis Leidel's avatar Jannis Leidel

Fixed #16161 -- Added `--clear` option to `collectstatic` management command to…

Fixed #16161 -- Added `--clear` option to `collectstatic` management command to be able to explicitly clear the files stored in the destination storage before collecting.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16509 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst c2a48110
......@@ -143,20 +143,34 @@ specified by the :setting:`INSTALLED_APPS` setting.
Some commonly used options are:
``--noinput``
.. django-admin-option:: --noinput
Do NOT prompt the user for input of any kind.
``-i PATTERN`` or ``--ignore=PATTERN``
.. django-admin-option:: -i <pattern>
.. django-admin-option:: --ignore <pattern>
Ignore files or directories matching this glob-style pattern. Use multiple
times to ignore more.
``-n`` or ``--dry-run``
.. django-admin-option:: -n
.. django-admin-option:: --dry-run
Do everything except modify the filesystem.
``-l`` or ``--link``
.. django-admin-option:: -c
.. django-admin-option:: --clear
.. versionadded:: 1.4
Clear the existing files before trying to copy or link the original file.
.. django-admin-option:: -l
.. django-admin-option:: --link
Create a symbolic link to each file instead of copying.
``--no-default-ignore``
.. django-admin-option:: --no-default-ignore
Don't ignore the common private glob-style patterns ``'CVS'``, ``'.*'``
and ``'*~'``.
......
......@@ -213,6 +213,9 @@ Django 1.4 also includes several smaller improvements worth noting:
to the :mod:`django.contrib.auth.utils` module. Importing it from the old
location will still work, but you should update your imports.
* The :djadmin:`collectstatic` management command gained a ``--clear`` option
to delete all files at the destination before copying or linking the static
files.
.. _backwards-incompatible-changes-1.4:
......
# -*- encoding: utf-8 -*-
from __future__ import with_statement
import codecs
import os
import posixpath
......@@ -36,11 +37,8 @@ class StaticFilesTestCase(TestCase):
# during checkout, we actually create one file dynamically.
_nonascii_filepath = os.path.join(
TEST_ROOT, 'apps', 'test', 'static', 'test', u'fi\u015fier.txt')
f = codecs.open(_nonascii_filepath, 'w', 'utf-8')
try:
with codecs.open(_nonascii_filepath, 'w', 'utf-8') as f:
f.write(u"fi\u015fier in the app dir")
finally:
f.close()
self.addCleanup(os.unlink, _nonascii_filepath)
def assertFileContains(self, filepath, text):
......@@ -94,12 +92,8 @@ class BuildStaticTestCase(StaticFilesTestCase):
def _get_file(self, filepath):
assert filepath, 'filepath is empty.'
filepath = os.path.join(settings.STATIC_ROOT, filepath)
f = codecs.open(filepath, "r", "utf-8")
try:
with codecs.open(filepath, "r", "utf-8") as f:
return f.read()
finally:
f.close()
class TestDefaults(object):
......@@ -197,9 +191,23 @@ class TestBuildStatic(BuildStaticTestCase, TestDefaults):
self.assertFileNotFound('test/CVS')
class TestBuildStaticClear(BuildStaticTestCase):
"""
Test the ``--clear`` option of the ``collectstatic`` managemenet command.
"""
def run_collectstatic(self, **kwargs):
clear_filepath = os.path.join(settings.STATIC_ROOT, 'cleared.txt')
with open(clear_filepath, 'w') as f:
f.write('should be cleared')
super(TestBuildStaticClear, self).run_collectstatic(clear=True)
def test_cleared_not_found(self):
self.assertFileNotFound('cleared.txt')
class TestBuildStaticExcludeNoDefaultIgnore(BuildStaticTestCase, TestDefaults):
"""
Test ``--exclude-dirs`` and ``--no-default-ignore`` options for
Test ``--exclude-dirs`` and ``--no-default-ignore`` options of the
``collectstatic`` management command.
"""
def run_collectstatic(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment