def install_templates(srcroot, destroot, prefix='<STR_LIT>', excludes=None,<EOL>includes=None, path_prefix=None):<EOL>
<EOL>if excludes is None:<EOL><INDENT>excludes = []<EOL><DEDENT>if includes is None:<EOL><INDENT>includes = []<EOL><DEDENT>if not os.path.exists(os.path.join(prefix, destroot)):<EOL><INDENT>os.makedirs(os.path.join(prefix, destroot))<EOL><DEDENT>for pathname in os.listdir(os.path.join(srcroot, prefix)):<EOL><INDENT>pathname = os.path.join(prefix, pathname)<EOL>excluded = False<EOL>for pat in excludes:<EOL><INDENT>if re.match(pat, pathname):<EOL><INDENT>excluded = True<EOL>break<EOL><DEDENT><DEDENT>if excluded:<EOL><INDENT>for pat in includes:<EOL><INDENT>if re.match(pat, pathname):<EOL><INDENT>excluded = False<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if excluded:<EOL><INDENT>LOGGER.debug("<STR_LIT>", pathname)<EOL>continue<EOL><DEDENT>source_name = os.path.join(srcroot, pathname)<EOL>dest_name = os.path.join(destroot, pathname)<EOL>if os.path.isfile(source_name) and not os.path.exists(dest_name):<EOL><INDENT>with open(source_name) as source:<EOL><INDENT>template_string = source.read()<EOL><DEDENT>try:<EOL><INDENT>template_string = force_text(template_string)<EOL>lexer = DebugLexer(template_string)<EOL>tokens = lexer.tokenize()<EOL>if not os.path.isdir(os.path.dirname(dest_name)):<EOL><INDENT>os.makedirs(os.path.dirname(dest_name))<EOL><DEDENT>engine, libraries, builtins = get_html_engine()<EOL>if isinstance(engine, DjangoTemplates):<EOL><INDENT>with open(dest_name, '<STR_LIT:w>') as dest:<EOL><INDENT>parser = AssetsParser(tokens,<EOL>URLRewriteWrapper(dest, path_prefix),<EOL>libraries=libraries,<EOL>builtins=builtins,<EOL>origin=None)<EOL>parser.parse_through()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>template_name = None<EOL>tokens = Lexer(engine.env).tokeniter(template_string,<EOL>template_name, filename=source_name)<EOL>buffered_tokens = []<EOL>state = None<EOL>with open(dest_name, '<STR_LIT:w>') as dest:<EOL><INDENT>for token in tokens:<EOL><INDENT>if state is None:<EOL><INDENT>if token[<NUM_LIT:1>] == '<STR_LIT>':<EOL><INDENT>state = STATE_BLOCK_BEGIN<EOL><DEDENT><DEDENT>elif state == STATE_BLOCK_BEGIN:<EOL><INDENT>if token[<NUM_LIT:1>] == '<STR_LIT:name>':<EOL><INDENT>if token[<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>state = STATE_ASSETS_BEGIN<EOL><DEDENT>else:<EOL><INDENT>buffered_tokens += [token]<EOL>state = None<EOL><DEDENT><DEDENT><DEDENT>elif state == STATE_ASSETS_BEGIN:<EOL><INDENT>if (token[<NUM_LIT:1>] == '<STR_LIT:name>'<EOL>and token[<NUM_LIT:2>] == '<STR_LIT>'):<EOL><INDENT>state = STATE_ASSETS_END<EOL><DEDENT><DEDENT>elif state == STATE_ASSETS_END:<EOL><INDENT>if token[<NUM_LIT:1>] == '<STR_LIT>':<EOL><INDENT>buffered_tokens += [token]<EOL>state = None<EOL><DEDENT><DEDENT>if state is None:<EOL><INDENT>if buffered_tokens:<EOL><INDENT>for tok in buffered_tokens:<EOL><INDENT>if (tok[<NUM_LIT:1>] == '<STR_LIT:name>' and<EOL>tok[<NUM_LIT:2>] == '<STR_LIT>'):<EOL><INDENT>dest.write(_render_assets(<EOL>buffered_tokens,<EOL>engine.env.assets_environment))<EOL>buffered_tokens = []<EOL>break<EOL><DEDENT><DEDENT>if buffered_tokens:<EOL><INDENT>dest.write("<STR_LIT:%s>" % '<STR_LIT>'.join([token[<NUM_LIT:2>]<EOL>for token in buffered_tokens]))<EOL><DEDENT>buffered_tokens = []<EOL><DEDENT>else:<EOL><INDENT>dest.write("<STR_LIT:%s>" % str(token[<NUM_LIT:2>]))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>buffered_tokens += [token]<EOL><DEDENT><DEDENT>if buffered_tokens:<EOL><INDENT>dest.write("<STR_LIT:%s>" % '<STR_LIT>'.join([<EOL>token[<NUM_LIT:2>] for token in buffered_tokens]))<EOL>buffered_tokens = []<EOL><DEDENT>dest.write("<STR_LIT:\n>")<EOL><DEDENT><DEDENT>cmdline = ['<STR_LIT>', '<STR_LIT>', source_name, dest_name]<EOL>cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)<EOL>lines = cmd.stdout.readlines()<EOL>cmd.wait()<EOL>if lines:<EOL><INDENT>verb = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>verb = '<STR_LIT>'<EOL><DEDENT>dest_multitier_name = dest_name.replace(destroot,<EOL>'<STR_LIT>')<EOL>LOGGER.debug("<STR_LIT>", verb,<EOL>source_name.replace(<EOL>django_settings.BASE_DIR, '<STR_LIT>'),<EOL>dest_multitier_name)<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>LOGGER.warning("<STR_LIT>"<EOL>"<STR_LIT>", source_name)<EOL><DEDENT><DEDENT>elif os.path.isdir(source_name):<EOL><INDENT>install_templates(srcroot, destroot, prefix=pathname,<EOL>excludes=excludes, includes=includes, path_prefix=path_prefix)<EOL><DEDENT><DEDENT>
Expand link to compiled assets all templates in *srcroot*
and its subdirectories.