<s> from . settings import MEDIA_BUNDLES <EOL> from . utils import _load_root_filter , _get_key <EOL> try : <EOL> from itertools import product <EOL> except ImportError : <EOL> try : <EOL> from django . utils . itercompat import product <EOL> except ImportError : <EOL> from . itercompat import product <EOL> from mediagenerator . base import Generator <EOL> from mimetypes import guess_type <EOL> import os <EOL> class Bundles ( Generator ) : <EOL> def get_output ( self ) : <EOL> for items in MEDIA_BUNDLES : <EOL> bundle = items [ <NUM_LIT:0> ] <EOL> backend = _load_root_filter ( bundle ) <EOL> variations = backend . _get_variations_with_input ( ) <EOL> if not variations : <EOL> name , content = self . generate_file ( backend , bundle , { } ) <EOL> yield _get_key ( bundle ) , name , content <EOL> else : <EOL> combinations = product ( * ( variations [ key ] <EOL> for key in sorted ( variations . keys ( ) ) ) ) <EOL> for combination in combinations : <EOL> variation_map = zip ( sorted ( variations . keys ( ) ) , combination ) <EOL> variation = dict ( variation_map ) <EOL> name , content = self . generate_file ( backend , bundle , <EOL> variation , combination ) <EOL> key = _get_key ( bundle , variation_map ) <EOL> yield key , name , content <EOL> def get_dev_output ( self , name ) : <EOL> bundle_combination , path = name . split ( '<STR_LIT:|>' , <NUM_LIT:1> ) <EOL> parts = bundle_combination . split ( '<STR_LIT>' ) <EOL> bundle = parts [ <NUM_LIT:0> ] <EOL> combination = parts [ <NUM_LIT:1> : ] <EOL> root = _load_root_filter ( bundle ) <EOL> variations = root . _get_variations_with_input ( ) <EOL> variation = dict ( zip ( sorted ( variations . keys ( ) ) , combination ) ) <EOL> content = root . get_dev_output ( path , variation ) <EOL> mimetype = guess_type ( bundle ) [ <NUM_LIT:0> ] <EOL> return content , mimetype <EOL> def get_dev_output_names ( self ) : <EOL> for items in MEDIA_BUNDLES : <EOL> bundle = items [ <NUM_LIT:0> ] <EOL> backend = _load_root_filter ( bundle ) <EOL> variations = backend . _get_variations_with_input ( ) <EOL> if not variations : <EOL> for name , hash in backend . get_dev_output_names ( { } ) : <EOL> url = '<STR_LIT>' % ( bundle , name ) <EOL> yield _get_key ( bundle ) , url , hash <EOL> else : <EOL> combinations = product ( * ( variations [ key ] <EOL> for key in sorted ( variations . keys ( ) ) ) ) <EOL> for combination in combinations : <EOL> variation_map = zip ( sorted ( variations . keys ( ) ) , combination ) <EOL> variation = dict ( variation_map ) <EOL> for name , hash in backend . get_dev_output_names ( variation ) : <EOL> url = '<STR_LIT>' % ( bundle , '<STR_LIT>' . join ( combination ) , name ) <EOL> yield _get_key ( bundle , variation_map ) , url , hash <EOL> def generate_file ( self , backend , bundle , variation , combination = ( ) ) : <EOL> print '<STR_LIT>' % ( bundle , variation ) <EOL> output = list ( backend . get_output ( variation ) ) <EOL> if len ( output ) == <NUM_LIT:0> : <EOL> output = ( '<STR_LIT>' , ) <EOL> assert len ( output ) == <NUM_LIT:1> , '<STR_LIT>' % bundle <EOL> content = output [ <NUM_LIT:0> ] <EOL> combination = '<STR_LIT>' . join ( combination ) <EOL> if combination : <EOL> combination = '<STR_LIT>' + combination <EOL> base , ext = os . path . splitext ( bundle ) <EOL> filename = base + combination + ext <EOL> return filename , content </s>
