<s> from django . conf import settings <EOL> from hashlib import sha1 <EOL> from mediagenerator . base import Generator <EOL> from mediagenerator . utils import get_media_dirs , find_file , prepare_patterns <EOL> from mimetypes import guess_type <EOL> import os <EOL> import sys <EOL> COPY_MEDIA_FILETYPES = getattr ( settings , '<STR_LIT>' , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> IGNORE_PATTERN = prepare_patterns ( getattr ( settings , <EOL> '<STR_LIT>' , ( ) ) , '<STR_LIT>' ) <EOL> class CopyFiles ( Generator ) : <EOL> def get_dev_output ( self , name ) : <EOL> path = find_file ( name ) <EOL> fp = open ( path , '<STR_LIT:rb>' ) <EOL> content = fp . read ( ) <EOL> fp . close ( ) <EOL> mimetype = guess_type ( path ) [ <NUM_LIT:0> ] <EOL> return content , mimetype <EOL> def get_dev_output_names ( self ) : <EOL> media_files = { } <EOL> for root in get_media_dirs ( ) : <EOL> self . collect_copyable_files ( media_files , root ) <EOL> for name , source in media_files . items ( ) : <EOL> fp = open ( source , '<STR_LIT:rb>' ) <EOL> hash = sha1 ( fp . read ( ) ) . hexdigest ( ) <EOL> fp . close ( ) <EOL> yield name , name , hash <EOL> def collect_copyable_files ( self , media_files , root ) : <EOL> has_followlinks = sys . version_info >= ( <NUM_LIT:2> , <NUM_LIT:6> ) <EOL> if has_followlinks : <EOL> allfiles = os . walk ( root , followlinks = True ) <EOL> else : <EOL> allfiles = os . walk ( root ) <EOL> for root_path , dirs , files in allfiles : <EOL> for file in files : <EOL> ext = os . path . splitext ( file ) [ <NUM_LIT:1> ] . lstrip ( '<STR_LIT:.>' ) <EOL> path = os . path . join ( root_path , file ) <EOL> if not has_followlinks : <EOL> path = os . path . abspath ( path ) <EOL> media_path = path [ len ( root ) + <NUM_LIT:1> : ] . replace ( os . sep , '<STR_LIT:/>' ) <EOL> if ext in COPY_MEDIA_FILETYPES and not IGNORE_PATTERN . match ( media_path ) : <EOL> media_files [ media_path ] = path </s>
