Skip to content
This repository has been archived by the owner on Jan 9, 2018. It is now read-only.

Commit

Permalink
Improve options handling in collectstatic
Browse files Browse the repository at this point in the history
Instead of a private method which is called twice (once in handle_noargs and
once in collect), process options once in handle_noargs. Tests which call
collect() will have to manually call set_options() beforehand to configure
their desired options.
  • Loading branch information
idan committed Feb 7, 2012
1 parent 69ad06c commit a7559f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 13 additions & 6 deletions staticfiles/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def __init__(self, *args, **kwargs):
if hasattr(os, 'stat_float_times'):
os.stat_float_times(False)

def _set_options(self, **options):
def set_options(self, **options):
"""
Set instance variables based on an options dict
"""
self.interactive = options['interactive']
self.verbosity = int(options.get('verbosity', 1))
self.symlink = options['link']
Expand All @@ -74,8 +77,12 @@ def _set_options(self, **options):
self.ignore_patterns = list(set(ignore_patterns))
self.post_process = options['post_process']

def collect(self, **options):
self._set_options(**options)
def collect(self):
"""
Perform the bulk of the work of collectstatic.
Split off from handle_noargs() to facilitate testing.
"""
if self.symlink:
if sys.platform == 'win32':
raise CommandError("Symlinking is not supported by this "
Expand Down Expand Up @@ -105,7 +112,7 @@ def collect(self, **options):
# Here we check if the storage backend has a post_process
# method and pass it the list of modified files.
if self.post_process and hasattr(self.storage, 'post_process'):
processor = self.storage.post_process(found_files, **options)
processor = self.storage.post_process(found_files, dry_run=self.dry_run)
for original_path, processed_path, processed in processor:
if processed:
self.log(u"Post-processed '%s' as '%s" %
Expand All @@ -121,7 +128,7 @@ def collect(self, **options):
}

def handle_noargs(self, **options):
self._set_options(**options)
self.set_options(**options)
# Warn before doing anything more.
if (isinstance(self.storage, FileSystemStorage) and
self.storage.location):
Expand Down Expand Up @@ -149,7 +156,7 @@ def handle_noargs(self, **options):
if confirm != 'yes':
raise CommandError("Collecting static files cancelled.")

collected = self.collect(**options)
collected = self.collect()
modified_count = len(collected['modified'])
unmodified_count = len(collected['unmodified'])
post_processed_count = len(collected['post_processed'])
Expand Down
3 changes: 2 additions & 1 deletion staticfiles/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ def test_post_processing(self):
}

collectstatic_cmd = CollectstaticCommand()
stats = collectstatic_cmd.collect(**collectstatic_args)
collectstatic_cmd.set_options(**collectstatic_args)
stats = collectstatic_cmd.collect()
self.assertTrue(u'cached/css/window.css' in stats['post_processed'])
self.assertTrue(u'cached/css/img/window.png' in stats['unmodified'])

Expand Down

0 comments on commit a7559f7

Please sign in to comment.