def collect(self):
if self.symlink and not self.local:<EOL><INDENT>raise CommandError("<STR_LIT>")<EOL><DEDENT>if self.clear:<EOL><INDENT>self.clear_dir('<STR_LIT>')<EOL><DEDENT>if self.symlink:<EOL><INDENT>handler = self.link_file<EOL><DEDENT>else:<EOL><INDENT>handler = self.copy_file<EOL><DEDENT>found_files = OrderedDict()<EOL>for finder in get_finders():<EOL><INDENT>for path, storage in finder.list(self.ignore_patterns):<EOL><INDENT>if getattr(storage, '<STR_LIT>', None):<EOL><INDENT>prefixed_path = os.path.join(storage.prefix, path)<EOL><DEDENT>else:<EOL><INDENT>prefixed_path = path<EOL><DEDENT>if prefixed_path not in found_files:<EOL><INDENT>found_files[prefixed_path] = (storage, path)<EOL>handler(path, prefixed_path, storage)<EOL><DEDENT><DEDENT><DEDENT>if self.post_process and hasattr(self.storage, '<STR_LIT>'):<EOL><INDENT>processor = self.storage.post_process(found_files,<EOL>dry_run=self.dry_run)<EOL>for original_path, processed_path, processed in processor:<EOL><INDENT>if isinstance(processed, Exception):<EOL><INDENT>self.stderr.write("<STR_LIT>" % original_path)<EOL>self.stderr.write("<STR_LIT>")<EOL>raise processed<EOL><DEDENT>if processed:<EOL><INDENT>self.log("<STR_LIT>" %<EOL>(original_path, processed_path), level=<NUM_LIT:1>)<EOL>self.post_processed_files.append(original_path)<EOL><DEDENT>else:<EOL><INDENT>self.log("<STR_LIT>" % original_path)<EOL><DEDENT><DEDENT><DEDENT>return {<EOL>'<STR_LIT>': self.copied_files + self.symlinked_files,<EOL>'<STR_LIT>': self.unmodified_files,<EOL>'<STR_LIT>': self.post_processed_files,<EOL>}<EOL>
Perform the bulk of the work of collectmedia.

Split off from handle() to facilitate testing.