<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> from jinja2 import FileSystemLoader <EOL> from tipfy import Tipfy <EOL> from tipfy . scripting import set_gae_sys_path <EOL> from tipfyext . jinja2 import Jinja2 <EOL> def walk ( top , topdown = True , onerror = None , followlinks = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> names = os . listdir ( top ) <EOL> except os . error , err : <EOL> if onerror is not None : <EOL> onerror ( err ) <EOL> return <EOL> dirs , nondirs = [ ] , [ ] <EOL> for name in names : <EOL> if os . path . isdir ( os . path . join ( top , name ) ) : <EOL> dirs . append ( name ) <EOL> else : <EOL> nondirs . append ( name ) <EOL> if topdown : <EOL> yield top , dirs , nondirs <EOL> for name in dirs : <EOL> path = os . path . join ( top , name ) <EOL> if followlinks or not os . path . islink ( path ) : <EOL> for x in walk ( path , topdown , onerror , followlinks ) : <EOL> yield x <EOL> if not topdown : <EOL> yield top , dirs , nondirs <EOL> def list_templates ( self ) : <EOL> """<STR_LIT>""" <EOL> found = set ( ) <EOL> for searchpath in self . searchpath : <EOL> for dirpath , dirnames , filenames in walk ( searchpath , followlinks = True ) : <EOL> for filename in filenames : <EOL> template = os . path . join ( dirpath , filename ) [ len ( searchpath ) : ] . strip ( os . path . sep ) . replace ( os . path . sep , '<STR_LIT:/>' ) <EOL> if template [ : <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> template = template [ <NUM_LIT:2> : ] <EOL> if template not in found : <EOL> found . add ( template ) <EOL> return sorted ( found ) <EOL> def logger ( msg ) : <EOL> sys . stderr . write ( '<STR_LIT>' % msg ) <EOL> def filter_templates ( tpl ) : <EOL> if os . path . basename ( tpl ) . startswith ( '<STR_LIT:.>' ) : <EOL> return False <EOL> if os . path . basename ( tpl ) . endswith ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> return False <EOL> return True <EOL> def compile_templates ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = sys . argv <EOL> base_path = os . getcwd ( ) <EOL> app_path = os . path . join ( base_path , '<STR_LIT>' ) <EOL> gae_path = os . path . join ( base_path , '<STR_LIT>' ) <EOL> extra_paths = [ <EOL> app_path , <EOL> os . path . join ( app_path , '<STR_LIT>' ) , <EOL> os . path . join ( app_path , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> gae_path , <EOL> os . path . join ( gae_path , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( gae_path , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( gae_path , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( gae_path , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( gae_path , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> sys . path = extra_paths + sys . path <EOL> from config import config <EOL> app = Tipfy ( config = config ) <EOL> template_path = app . get_config ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> compiled_path = app . get_config ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> if compiled_path is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if isinstance ( template_path , basestring ) : <EOL> source = os . path . join ( app_path , template_path ) <EOL> else : <EOL> source = [ os . path . join ( app_path , p ) for p in template_path ] <EOL> target = os . path . join ( app_path , compiled_path ) <EOL> app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] = source <EOL> app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] = None <EOL> if target . endswith ( '<STR_LIT>' ) : <EOL> zip_cfg = '<STR_LIT>' <EOL> else : <EOL> zip_cfg = None <EOL> old_list_templates = FileSystemLoader . list_templates <EOL> FileSystemLoader . list_templates = list_templates <EOL> env = Jinja2 . factory ( app , '<STR_LIT>' ) . environment <EOL> env . compile_templates ( target , extensions = None , <EOL> filter_func = filter_templates , zip = zip_cfg , log_function = logger , <EOL> ignore_errors = False , py_compile = False ) <EOL> FileSystemLoader . list_templates = old_list_templates </s>
