<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> from os import path , listdir , mkdir <EOL> def compile_file ( env , src_path , dst_path , encoding = '<STR_LIT:utf-8>' , base_dir = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> src_file = file ( src_path , '<STR_LIT:r>' ) <EOL> try : <EOL> source = src_file . read ( ) . decode ( encoding ) <EOL> except Exception , e : <EOL> sys . stderr . write ( "<STR_LIT>" <EOL> "<STR_LIT>" % src_path ) <EOL> raise <EOL> src_file . close ( ) <EOL> name = src_path . replace ( base_dir , '<STR_LIT>' ) <EOL> raw = env . compile ( source , name = name , filename = name , raw = True ) <EOL> dst_file = open ( dst_path , '<STR_LIT:wb>' ) <EOL> dst_file . write ( raw ) <EOL> dst_file . close ( ) <EOL> def compile_dir ( env , src_path , dst_path , pattern = r'<STR_LIT>' , <EOL> encoding = '<STR_LIT:utf-8>' , base_dir = None , <EOL> negative_pattern = r'<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if base_dir is None : <EOL> base_dir = src_path <EOL> for filename in listdir ( src_path ) : <EOL> if filename . startswith ( "<STR_LIT:.>" ) : <EOL> continue <EOL> src_name = path . join ( src_path , filename ) <EOL> dst_name = path . join ( dst_path , filename ) <EOL> if path . isdir ( src_name ) : <EOL> if not path . isdir ( dst_name ) : <EOL> mkdir ( dst_name ) <EOL> compile_dir ( env , src_name , dst_name , encoding = encoding , <EOL> base_dir = base_dir ) <EOL> elif path . isfile ( src_name ) and re . match ( pattern , filename ) and not re . match ( negative_pattern , filename ) : <EOL> compile_file ( env , src_name , dst_name , encoding = encoding , <EOL> base_dir = base_dir ) </s>
