Package resources and templates for a multi-tier environment
    into a zip file.

    Templates are pre-compiled into ``*build_dir*/*app_name*/templates``.
    Compilation means {% assets '*path*' %} and {% static '*path*' %} tags
    are replaced by their compiled expression.

def package_theme(app_name, build_dir,
                  excludes=None, includes=None, path_prefix=None,
                  template_dirs=None):
    """
    Package resources and templates for a multi-tier environment
    into a zip file.

    Templates are pre-compiled into ``*build_dir*/*app_name*/templates``.
    Compilation means {% assets '*path*' %} and {% static '*path*' %} tags
    are replaced by their compiled expression.
    """
    #pylint:disable=too-many-locals,too-many-arguments
    templates_dest = os.path.join(build_dir, 'templates')
    # override STATIC_URL to prefix APP_NAME.
    orig_static_url = django_settings.STATIC_URL
    if (app_name != settings.APP_NAME
        and not django_settings.STATIC_URL.startswith('/' + app_name)):
        django_settings.STATIC_URL = '/' + app_name + orig_static_url
    if not os.path.exists(templates_dest):
        os.makedirs(templates_dest)
    if template_dirs is None:
        template_dirs = get_template_search_path(app_name)
    for template_dir in template_dirs:
        # The first of template_dirs usually contains the most specialized
        # templates (ie. the ones we truely want to install).
        if (templates_dest
            and not os.path.samefile(template_dir, templates_dest)):
            install_templates(template_dir, templates_dest,
                excludes=excludes, includes=includes, path_prefix=path_prefix)