<s> """<STR_LIT>""" <EOL> import copy <EOL> import logging <EOL> import md5 <EOL> import os <EOL> import re <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import types <EOL> import yaml <EOL> import kay <EOL> from kay . conf import settings <EOL> import kay . ext . media_compressor . default_settings as media_conf <EOL> IS_DEVSERVER = '<STR_LIT>' in os . environ and os . environ [ '<STR_LIT>' ] . startswith ( '<STR_LIT>' ) <EOL> IS_APPSERVER = '<STR_LIT>' in os . environ and os . environ [ '<STR_LIT>' ] . startswith ( '<STR_LIT>' ) <EOL> def union_list ( a , b ) : <EOL> return list ( set ( a ) . union ( b ) ) <EOL> class MediaInfo : <EOL> path_ = os . path . join ( kay . PROJECT_DIR , '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> self . info_ = { } <EOL> @ classmethod <EOL> def load ( cls ) : <EOL> instance = cls ( ) <EOL> if os . path . exists ( cls . path_ ) : <EOL> istream = open ( cls . path_ , '<STR_LIT:rb>' ) <EOL> try : <EOL> instance . info_ = yaml . safe_load ( istream ) <EOL> except : <EOL> pass <EOL> finally : <EOL> istream . close ( ) <EOL> return instance <EOL> def save ( self ) : <EOL> ostream = open ( self . path_ , '<STR_LIT:wb>' ) <EOL> try : <EOL> yaml . safe_dump ( self . info_ , ostream , indent = <NUM_LIT:2> ) <EOL> finally : <EOL> ostream . close ( ) <EOL> def get ( self , category , name ) : <EOL> info = self . info_ . get ( category ) <EOL> if info is None : <EOL> return None <EOL> return info . get ( name ) <EOL> def set ( self , category , name , new_value ) : <EOL> info = self . info_ . get ( category ) <EOL> if info is None : <EOL> self . info_ [ category ] = { name : new_value } <EOL> else : <EOL> self . info_ [ category ] [ name ] = new_value <EOL> media_info = None <EOL> VERBOSE_SURPRESS = <NUM_LIT:0> <EOL> VERBOSE_PRINT = <NUM_LIT:1> <EOL> VERBOSE_LOGGING = <NUM_LIT:2> <EOL> def surpress_print_status ( s ) : <EOL> pass <EOL> print_status_method = surpress_print_status <EOL> def print_status ( s ) : <EOL> print_status_method ( s ) <EOL> def set_verbose_method ( method ) : <EOL> global print_status_method <EOL> if method == VERBOSE_SURPRESS : <EOL> print_status_method = default_print_status <EOL> elif method == VERBOSE_PRINT : <EOL> print_status_method = kay . management . utils . print_status <EOL> elif method == VERBOSE_LOGGING : <EOL> print_status_method = logging . info <EOL> def _merge_css_config ( dst , another ) : <EOL> return _merge_config ( dst , another , [ '<STR_LIT>' ] ) <EOL> def _merge_js_config ( dst , another ) : <EOL> return _merge_config ( dst , another , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _merge_config ( dst , another , merge_keys ) : <EOL> if another is None : <EOL> return { } if dst is None else dst <EOL> if getattr ( another , '<STR_LIT>' , None ) : <EOL> for k , v in another . iteritems ( ) : <EOL> if k in merge_keys and k in dst : <EOL> dst [ k ] . update ( v ) <EOL> else : <EOL> dst [ k ] = copy . deepcopy ( v ) <EOL> return dst <EOL> COMPILE_COMMON = copy . deepcopy ( media_conf . COMPILE_MEDIA ) <EOL> COMPILE_COMMON . update ( getattr ( settings , '<STR_LIT>' , { } ) ) <EOL> COMPILE_CSS = _merge_css_config ( copy . deepcopy ( COMPILE_COMMON ) , <EOL> media_conf . COMPILE_MEDIA_CSS ) <EOL> if IS_DEVSERVER : <EOL> COMPILE_CSS = _merge_css_config ( COMPILE_CSS , <EOL> media_conf . COMPILE_MEDIA_CSS_DEV ) <EOL> COMPILE_CSS = _merge_css_config ( <EOL> COMPILE_CSS , getattr ( settings , '<STR_LIT>' , { } ) ) <EOL> if IS_DEVSERVER : <EOL> COMPILE_CSS = _merge_css_config ( <EOL> COMPILE_CSS , getattr ( settings , '<STR_LIT>' , { } ) ) <EOL> COMPILE_JS = _merge_js_config ( copy . deepcopy ( COMPILE_COMMON ) , <EOL> media_conf . COMPILE_MEDIA_JS ) <EOL> if IS_DEVSERVER : <EOL> COMPILE_JS = _merge_js_config ( COMPILE_JS , <EOL> media_conf . COMPILE_MEDIA_JS_DEV ) <EOL> COMPILE_JS = _merge_js_config ( <EOL> COMPILE_JS , getattr ( settings , '<STR_LIT>' , { } ) ) <EOL> if IS_DEVSERVER : <EOL> COMPILE_JS = _merge_js_config ( <EOL> COMPILE_JS , getattr ( settings , '<STR_LIT>' , { } ) ) <EOL> def manage_static_files ( ) : <EOL> if hasattr ( settings , '<STR_LIT>' ) and COMPILE_COMMON . has_key ( '<STR_LIT>' ) and COMPILE_COMMON [ '<STR_LIT>' ] : <EOL> _create_symlinks ( ) <EOL> def _create_symlinks ( ) : <EOL> for from_path , to_path in COMPILE_COMMON [ '<STR_LIT>' ] : <EOL> src_path = os . path . join ( kay . PROJECT_DIR , from_path ) <EOL> dest_path = make_output_path_ ( COMPILE_COMMON , to_path ) <EOL> print_status ( '<STR_LIT>' % ( from_path , dest_path [ len ( kay . PROJECT_DIR ) : ] ) ) <EOL> dest_dir = os . path . dirname ( dest_path ) <EOL> if dest_dir and not os . path . exists ( dest_dir ) : <EOL> os . makedirs ( dest_dir ) <EOL> if not os . path . lexists ( dest_path ) : <EOL> os . symlink ( os . path . abspath ( from_path ) , dest_path ) <EOL> def get_css_config ( tag_name ) : <EOL> if not getattr ( settings , '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if not tag_name in settings . COMPILE_MEDIA_CSS : <EOL> raise Exception ( '<STR_LIT>' % <EOL> tag_name ) <EOL> return _merge_css_config ( copy . deepcopy ( COMPILE_CSS ) , <EOL> settings . COMPILE_MEDIA_CSS [ tag_name ] ) <EOL> def get_css_urls ( tag_name , auto_compile = False ) : <EOL> css_config = get_css_config ( tag_name ) <EOL> if not css_config [ '<STR_LIT>' ] : <EOL> if css_config [ '<STR_LIT>' ] : <EOL> return css_config [ '<STR_LIT>' ] <EOL> else : <EOL> return [ path if re . match ( ur '<STR_LIT>' , path ) else '<STR_LIT>' % <EOL> path for path in css_config [ '<STR_LIT>' ] ] <EOL> if auto_compile : <EOL> compile_css ( tag_name ) <EOL> global media_info <EOL> if media_info is None : <EOL> media_info = MediaInfo . load ( ) <EOL> last_info = media_info . get ( css_config [ '<STR_LIT>' ] , tag_name ) <EOL> if not last_info : <EOL> raise Exception ( '<STR_LIT>' % <EOL> tag_name ) <EOL> return last_info [ '<STR_LIT>' ] <EOL> def compile_css ( tag_name = None , force = False ) : <EOL> for name , x in settings . COMPILE_MEDIA_CSS . iteritems ( ) : <EOL> if tag_name is not None : <EOL> if tag_name != name : <EOL> continue <EOL> print_status ( '<STR_LIT>' % name ) <EOL> css_config = get_css_config ( name ) <EOL> compile_css_ ( name , css_config , force ) <EOL> return True <EOL> def compile_css_ ( tag_name , css_config , force ) : <EOL> if IS_APPSERVER : <EOL> return <EOL> def needs_update ( media_info , output_path ) : <EOL> if not css_config [ '<STR_LIT>' ] : <EOL> return False <EOL> if not os . path . exists ( output_path ) : <EOL> return True <EOL> last_info = media_info . get ( css_config [ '<STR_LIT>' ] , tag_name ) <EOL> if not last_info : <EOL> return True <EOL> last_config = last_info . get ( '<STR_LIT>' ) <EOL> if not last_config : <EOL> return True <EOL> if not equal_object_ ( last_config , css_config ) : <EOL> return True <EOL> if '<STR_LIT>' not in last_info : <EOL> return True <EOL> for path , mtime in last_info [ '<STR_LIT>' ] : <EOL> if mtime != os . path . getmtime ( path ) : <EOL> return True <EOL> def csstidy ( css_path ) : <EOL> tmp_file = tempfile . NamedTemporaryFile ( mode = '<STR_LIT>' ) <EOL> ifile = open ( css_path ) <EOL> tmp_file . write ( ifile . read ( ) ) <EOL> ifile . close ( ) <EOL> tmp_file . flush ( ) <EOL> output_file = tempfile . NamedTemporaryFile ( mode = '<STR_LIT>' ) <EOL> print_status ( "<STR_LIT>" % ( css_config [ '<STR_LIT>' ] [ '<STR_LIT:path>' ] , <EOL> css_path , <EOL> css_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> command = '<STR_LIT>' % ( css_config [ '<STR_LIT>' ] [ '<STR_LIT:path>' ] , <EOL> tmp_file . name , <EOL> css_config [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> output_file . name ) <EOL> command_output = os . popen ( command ) . read ( ) <EOL> filtered_css = output_file . read ( ) <EOL> output_file . close ( ) <EOL> tmp_file . close ( ) <EOL> return filtered_css <EOL> def concat ( css_path ) : <EOL> print_status ( "<STR_LIT>" % css_path ) <EOL> ifile = open ( css_path ) <EOL> css = ifile . read ( ) <EOL> ifile . close ( ) <EOL> return css <EOL> if css_config [ '<STR_LIT>' ] not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print_status ( "<STR_LIT>" <EOL> "<STR_LIT>" % css_config [ '<STR_LIT>' ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> global media_info <EOL> if media_info is None : <EOL> media_info = MediaInfo . load ( ) <EOL> output_path = make_output_path_ ( css_config , css_config [ '<STR_LIT>' ] , <EOL> css_config [ '<STR_LIT>' ] ) <EOL> if not force and not needs_update ( media_info , output_path ) : <EOL> print_status ( '<STR_LIT>' ) <EOL> return <EOL> if css_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> tool_method = csstidy <EOL> elif css_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> tool_method = concat <EOL> source_files = [ ] <EOL> for path in css_config [ '<STR_LIT>' ] : <EOL> path = make_input_path_ ( path ) <EOL> logging . info ( path ) <EOL> source_files . append ( ( path , os . path . getmtime ( path ) ) ) <EOL> ofile = create_file_ ( output_path ) <EOL> try : <EOL> for path , mtime in source_files : <EOL> ofile . write ( tool_method ( path ) ) <EOL> finally : <EOL> ofile . close ( ) <EOL> result_url = '<STR_LIT:/>' + make_output_path_ ( css_config , css_config [ '<STR_LIT>' ] , <EOL> css_config [ '<STR_LIT>' ] , <EOL> relative = True ) <EOL> last_info = { '<STR_LIT>' : copy . deepcopy ( css_config ) , <EOL> '<STR_LIT>' : source_files , <EOL> '<STR_LIT>' : [ result_url ] } <EOL> media_info . set ( css_config [ '<STR_LIT>' ] , tag_name , last_info ) <EOL> media_info . save ( ) <EOL> def get_js_config ( tag_name ) : <EOL> if not getattr ( settings , '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if not tag_name in settings . COMPILE_MEDIA_JS : <EOL> raise Exception ( '<STR_LIT>' % <EOL> tag_name ) <EOL> return _merge_js_config ( copy . deepcopy ( COMPILE_JS ) , <EOL> settings . COMPILE_MEDIA_JS [ tag_name ] ) <EOL> def get_js_urls ( tag_name , auto_compile = False ) : <EOL> js_config = get_js_config ( tag_name ) <EOL> if not js_config [ '<STR_LIT>' ] : <EOL> if js_config [ '<STR_LIT>' ] : <EOL> return js_config [ '<STR_LIT>' ] <EOL> else : <EOL> return [ path if re . match ( ur '<STR_LIT>' , path ) else '<STR_LIT>' % <EOL> path for path in js_config [ '<STR_LIT>' ] ] <EOL> if auto_compile : <EOL> compile_js ( tag_name ) <EOL> global media_info <EOL> if media_info is None : <EOL> media_info = MediaInfo . load ( ) <EOL> last_info = media_info . get ( js_config [ '<STR_LIT>' ] , tag_name ) <EOL> if not last_info : <EOL> raise Exception ( '<STR_LIT>' % <EOL> tag_name ) <EOL> return last_info [ '<STR_LIT>' ] <EOL> def compile_js ( tag_name = None , force = False ) : <EOL> for name , x in settings . COMPILE_MEDIA_JS . iteritems ( ) : <EOL> if tag_name is not None : <EOL> if tag_name != name : <EOL> continue <EOL> print_status ( '<STR_LIT>' % name ) <EOL> js_config = get_js_config ( name ) <EOL> compile_js_ ( name , js_config , force ) <EOL> return True <EOL> def compile_js_ ( tag_name , js_config , force ) : <EOL> if IS_APPSERVER : <EOL> return <EOL> def needs_update ( media_info ) : <EOL> if js_config [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> target_path = make_output_path_ ( js_config , js_config [ '<STR_LIT>' ] , <EOL> js_config [ '<STR_LIT>' ] ) <EOL> if not os . path . exists ( target_path ) : <EOL> return True <EOL> last_info = media_info . get ( js_config [ '<STR_LIT>' ] , tag_name ) <EOL> if not last_info : <EOL> return True <EOL> last_config = last_info . get ( '<STR_LIT>' ) <EOL> if not last_config : <EOL> return True <EOL> if not equal_object_ ( last_config , js_config ) : <EOL> return True <EOL> if '<STR_LIT>' not in last_info : <EOL> return True <EOL> for path , mtime in last_info [ '<STR_LIT>' ] : <EOL> if mtime != os . path . getmtime ( path ) : <EOL> return True <EOL> def jsminify ( js_path ) : <EOL> from StringIO import StringIO <EOL> from kay . ext . media_compressor . jsmin import JavascriptMinify <EOL> ifile = open ( js_path ) <EOL> outs = StringIO ( ) <EOL> JavascriptMinify ( ) . minify ( ifile , outs ) <EOL> ret = outs . getvalue ( ) <EOL> if len ( ret ) > <NUM_LIT:0> and ret [ <NUM_LIT:0> ] == '<STR_LIT:\n>' : <EOL> ret = ret [ <NUM_LIT:1> : ] <EOL> return ret <EOL> def concat ( js_path ) : <EOL> print_status ( "<STR_LIT>" % js_path ) <EOL> ifile = open ( js_path ) <EOL> js = ifile . read ( ) <EOL> ifile . close ( ) <EOL> return js <EOL> def goog_calcdeps ( ) : <EOL> deps_config = copy . deepcopy ( js_config [ '<STR_LIT>' ] ) <EOL> deps_config . update ( js_config [ '<STR_LIT>' ] ) <EOL> if deps_config . get ( '<STR_LIT>' ) not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> print_status ( "<STR_LIT>" <EOL> "<STR_LIT>" % deps_config . get ( '<STR_LIT>' ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> output_urls = [ ] <EOL> if deps_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> source_files , output_urls = goog_calcdeps_separate ( deps_config ) <EOL> elif deps_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> source_files , output_urls = goog_calcdeps_concat ( deps_config ) <EOL> elif deps_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> source_files , output_urls = goog_calcdeps_concat_refs ( deps_config ) <EOL> elif deps_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> source_files , output_urls = goog_calcdeps_compile ( deps_config ) <EOL> source_files = [ file [ <NUM_LIT:0> ] for file in source_files ] <EOL> related_files = union_list ( source_files , <EOL> [ make_input_path_ ( path ) <EOL> for path in js_config [ '<STR_LIT>' ] ] ) <EOL> related_file_info = [ ( path , os . path . getmtime ( path ) ) <EOL> for path in related_files ] <EOL> last_info = { '<STR_LIT>' : copy . deepcopy ( js_config ) , <EOL> '<STR_LIT>' : related_file_info , <EOL> '<STR_LIT>' : output_urls } <EOL> media_info . set ( js_config [ '<STR_LIT>' ] , tag_name , last_info ) <EOL> media_info . save ( ) <EOL> def goog_calcdeps_separate ( deps_config ) : <EOL> source_files = goog_calcdeps_list ( deps_config ) <EOL> ( output_urls , extern_urls ) = goog_calcdeps_copy_files ( deps_config , <EOL> source_files ) <EOL> return ( source_files , extern_urls + output_urls ) <EOL> def goog_calcdeps_concat ( deps_config ) : <EOL> source_files = goog_calcdeps_list ( deps_config ) <EOL> ( output_urls , extern_urls ) = goog_calcdeps_concat_files ( deps_config , <EOL> source_files ) <EOL> return ( source_files , extern_urls + output_urls ) <EOL> def goog_calcdeps_concat_refs ( deps_config ) : <EOL> source_files = goog_calcdeps_list ( deps_config ) <EOL> original_files = [ make_input_path_ ( path ) <EOL> for path in js_config [ '<STR_LIT>' ] ] <EOL> ref_files = [ path for path in source_files if path not in original_files ] <EOL> ( output_urls , extern_urls ) = goog_calcdeps_concat_files ( deps_config , <EOL> ref_files ) <EOL> original_urls = [ path [ len ( kay . PROJECT_DIR ) : ] for path in original_files ] <EOL> return ( source_files , extern_urls + output_urls + original_urls ) <EOL> def goog_calcdeps_compile ( deps_config ) : <EOL> comp_config = copy . deepcopy ( js_config [ '<STR_LIT>' ] ) <EOL> comp_config . update ( js_config [ '<STR_LIT>' ] ) <EOL> source_files = [ ] <EOL> extern_urls = [ ] <EOL> command = '<STR_LIT>' % ( deps_config [ '<STR_LIT:path>' ] , <EOL> comp_config [ '<STR_LIT:path>' ] ) <EOL> for path in deps_config . get ( '<STR_LIT>' , [ ] ) : <EOL> command += '<STR_LIT>' % make_input_path_ ( path ) <EOL> for path in js_config [ '<STR_LIT>' ] : <EOL> path = make_input_path_ ( path ) <EOL> command += '<STR_LIT>' % path <EOL> source_files . append ( ( path , os . path . getmtime ( path ) ) ) <EOL> if comp_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> level = '<STR_LIT>' <EOL> elif comp_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> level = '<STR_LIT>' <EOL> else : <EOL> level = '<STR_LIT>' <EOL> flags = '<STR_LIT>' % level <EOL> command += '<STR_LIT>' % flags <EOL> print_status ( command ) <EOL> command_output = os . popen ( command ) . read ( ) <EOL> output_path = make_output_path_ ( js_config , js_config [ '<STR_LIT>' ] , <EOL> js_config [ '<STR_LIT>' ] ) <EOL> ofile = create_file_ ( output_path ) <EOL> try : <EOL> for path in comp_config . get ( '<STR_LIT>' , [ ] ) : <EOL> if re . match ( r'<STR_LIT>' , path ) : <EOL> extern_urls . append ( path ) <EOL> continue <EOL> path = make_input_path_ ( path ) <EOL> ifile = open ( path ) <EOL> try : <EOL> ofile . write ( ifile . read ( ) ) <EOL> finally : <EOL> ifile . close ( ) <EOL> source_files . append ( ( path , os . path . getmtime ( path ) ) ) <EOL> ofile . write ( command_output ) <EOL> finally : <EOL> ofile . close ( ) <EOL> return ( source_files , extern_urls + [ output_path [ len ( kay . PROJECT_DIR ) : ] ] ) <EOL> def goog_calcdeps_list ( deps_config ) : <EOL> source_files = [ ] <EOL> command = '<STR_LIT>' % deps_config [ '<STR_LIT:path>' ] <EOL> for path in deps_config [ '<STR_LIT>' ] : <EOL> command += '<STR_LIT>' % make_input_path_ ( path ) <EOL> for path in js_config [ '<STR_LIT>' ] : <EOL> command += '<STR_LIT>' % make_input_path_ ( path ) <EOL> print_status ( command ) <EOL> command_output = os . popen ( command ) . read ( ) <EOL> for path in command_output . split ( "<STR_LIT:\n>" ) : <EOL> if path == '<STR_LIT>' : continue <EOL> source_files . append ( path ) <EOL> return source_files <EOL> def goog_calcdeps_copy_files ( deps_config , source_files ) : <EOL> extern_urls = [ ] <EOL> output_urls = [ ] <EOL> output_dir_base = make_output_path_ ( js_config , '<STR_LIT>' ) <EOL> if not os . path . exists ( output_dir_base ) : <EOL> os . makedirs ( output_dir_base ) <EOL> if not deps_config . get ( '<STR_LIT>' , True ) : <EOL> output_path = os . path . join ( output_dir_base , '<STR_LIT>' ) <EOL> ofile = open ( output_path , "<STR_LIT:w>" ) <EOL> output_urls . append ( output_path [ len ( kay . PROJECT_DIR ) : ] ) <EOL> try : <EOL> ofile . write ( '<STR_LIT>' ) <EOL> finally : <EOL> ofile . close ( ) <EOL> output_dirs = { } <EOL> search_paths = [ make_input_path_ ( path ) <EOL> for path in deps_config [ '<STR_LIT>' ] ] <EOL> for path in search_paths : <EOL> output_dirs [ path ] = os . path . join ( output_dir_base , <EOL> md5 . new ( path ) . hexdigest ( ) ) <EOL> all_paths = [ make_input_path_ ( path ) <EOL> for path in deps_config . get ( '<STR_LIT>' , [ ] ) ] <EOL> all_paths . extend ( source_files ) <EOL> for path in all_paths : <EOL> if re . match ( r'<STR_LIT>' , path ) : <EOL> extern_urls . append ( path ) <EOL> continue <EOL> path = make_input_path_ ( path ) <EOL> output_path = os . path . join ( output_dir_base , re . sub ( '<STR_LIT>' , '<STR_LIT>' , path ) ) <EOL> for dir in search_paths : <EOL> if path [ <NUM_LIT:0> : len ( dir ) ] == dir : <EOL> output_path = os . path . join ( output_dirs [ dir ] , <EOL> re . sub ( '<STR_LIT>' , '<STR_LIT>' , path [ len ( dir ) : ] ) ) <EOL> break <EOL> output_dir = os . path . dirname ( output_path ) <EOL> if not os . path . exists ( output_dir ) : <EOL> os . makedirs ( output_dir ) <EOL> shutil . copy2 ( path , output_path ) <EOL> output_urls . append ( output_path [ len ( kay . PROJECT_DIR ) : ] ) <EOL> return ( output_urls , extern_urls ) <EOL> def goog_calcdeps_concat_files ( deps_config , source_files ) : <EOL> extern_urls = [ ] <EOL> output_path = make_output_path_ ( js_config , js_config [ '<STR_LIT>' ] , <EOL> js_config [ '<STR_LIT>' ] ) <EOL> ofile = create_file_ ( output_path ) <EOL> try : <EOL> if not deps_config . get ( '<STR_LIT>' , True ) : <EOL> ofile . write ( '<STR_LIT>' ) <EOL> all_paths = [ make_input_path_ ( path ) <EOL> for path in deps_config . get ( '<STR_LIT>' , [ ] ) ] <EOL> all_paths . extend ( source_files ) <EOL> for path in all_paths : <EOL> if re . match ( r'<STR_LIT>' , path ) : <EOL> extern_urls . append ( path ) <EOL> continue <EOL> ifile = open ( make_input_path_ ( path ) ) <EOL> ofile . write ( ifile . read ( ) ) <EOL> ifile . close ( ) <EOL> finally : <EOL> ofile . close ( ) <EOL> return ( [ output_path [ len ( kay . PROJECT_DIR ) : ] ] , extern_urls ) <EOL> selected_tool = js_config [ '<STR_LIT>' ] <EOL> if selected_tool not in ( None , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print_status ( "<STR_LIT>" <EOL> "<STR_LIT>" % selected_tool ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> global media_info <EOL> if media_info is None : <EOL> media_info = MediaInfo . load ( ) <EOL> if not force and not needs_update ( media_info ) : <EOL> print_status ( '<STR_LIT>' ) <EOL> return <EOL> if selected_tool == '<STR_LIT>' : <EOL> return goog_calcdeps ( ) <EOL> if selected_tool is None : <EOL> last_info = { '<STR_LIT>' : copy . deepcopy ( js_config ) , <EOL> '<STR_LIT>' : [ '<STR_LIT:/>' + f for f in js_config [ '<STR_LIT>' ] ] } <EOL> media_info . set ( js_config [ '<STR_LIT>' ] , tag_name , last_info ) <EOL> media_info . save ( ) <EOL> return <EOL> dest_path = make_output_path_ ( js_config , js_config [ '<STR_LIT>' ] , <EOL> js_config [ '<STR_LIT>' ] ) <EOL> ofile = create_file_ ( dest_path ) <EOL> try : <EOL> if selected_tool == '<STR_LIT>' : <EOL> for path in js_config [ '<STR_LIT>' ] : <EOL> src_path = make_input_path_ ( path ) <EOL> ofile . write ( jsminify ( src_path ) ) <EOL> elif selected_tool == '<STR_LIT>' : <EOL> for path in js_config [ '<STR_LIT>' ] : <EOL> src_path = make_input_path_ ( path ) <EOL> ofile . write ( concat ( src_path ) ) <EOL> finally : <EOL> ofile . close ( ) <EOL> if selected_tool == '<STR_LIT>' : <EOL> comp_config = copy . deepcopy ( js_config [ '<STR_LIT>' ] ) <EOL> comp_config . update ( js_config [ '<STR_LIT>' ] ) <EOL> if comp_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> level = '<STR_LIT>' <EOL> elif comp_config [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> level = '<STR_LIT>' <EOL> else : <EOL> level = '<STR_LIT>' <EOL> command_args = '<STR_LIT>' % level <EOL> for path in js_config [ '<STR_LIT>' ] : <EOL> command_args += '<STR_LIT>' % make_input_path_ ( path ) <EOL> command_args += '<STR_LIT>' % dest_path <EOL> command = '<STR_LIT>' % ( comp_config [ '<STR_LIT:path>' ] , command_args ) <EOL> command_output = os . popen ( command ) . read ( ) <EOL> info = copy . deepcopy ( js_config ) <EOL> info [ '<STR_LIT>' ] = make_output_path_ ( js_config , js_config [ '<STR_LIT>' ] , <EOL> js_config [ '<STR_LIT>' ] , <EOL> relative = True ) <EOL> info [ '<STR_LIT>' ] = [ '<STR_LIT:/>' + info [ '<STR_LIT>' ] ] <EOL> media_info . set ( js_config [ '<STR_LIT>' ] , tag_name , info ) <EOL> media_info . save ( ) <EOL> def make_input_path_ ( path ) : <EOL> return os . path . join ( kay . PROJECT_DIR , path ) <EOL> def make_output_path_ ( config , * path , ** kwargs ) : <EOL> version = config [ '<STR_LIT:version>' ] <EOL> if version is not None : <EOL> result = os . path . join ( config [ '<STR_LIT>' ] , str ( version ) , * path ) <EOL> else : <EOL> result = os . path . join ( config [ '<STR_LIT>' ] , * path ) <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> return result <EOL> else : <EOL> return os . path . join ( kay . PROJECT_DIR , result ) <EOL> def create_file_ ( path ) : <EOL> dirname = os . path . dirname ( path ) <EOL> if not os . path . exists ( dirname ) : <EOL> os . makedirs ( dirname ) <EOL> return open ( path , '<STR_LIT:wb>' ) <EOL> def equal_object_ ( a , b ) : <EOL> if type ( a ) == types . DictType and type ( b ) == types . DictType : <EOL> if len ( a . keys ( ) ) != len ( b . keys ( ) ) : <EOL> return False <EOL> for k , v in a . iteritems ( ) : <EOL> if k not in b : <EOL> return False <EOL> if not equal_object_ ( v , b [ k ] ) : <EOL> return False <EOL> return True <EOL> elif type ( a ) in [ types . ListType , types . TupleType ] and type ( b ) in [ types . ListType , types . TupleType ] : <EOL> if len ( a ) != len ( b ) : <EOL> return False <EOL> ia = iter ( a ) <EOL> ib = iter ( b ) <EOL> try : <EOL> while True : <EOL> if not equal_object_ ( ia . next ( ) , ib . next ( ) ) : <EOL> return False <EOL> except : <EOL> pass <EOL> return True <EOL> else : <EOL> return a == b </s>
