Return a map of "likely service/template name" to "template file".
    This includes all the template files in fixtures and in services.
191936
def scan_dir_for_template_files(search_dir):
    
    template_files = {}
    cf_dir = os.path.join(search_dir, 'cloudformation')
    for type in os.listdir(cf_dir):
        template_dir = os.path.join(cf_dir, type, 'templates')
        for x in os.listdir(template_dir):
            name = os.path.splitext(x)[0]
            template_files[name] = os.path.join(template_dir, x)
    return template_files
499746
def get_template_name(self):
        
        template = self.get_template()
        page_templates = settings.get_page_templates()
        for t in page_templates:
            if t[0] == template:
                return t[1]
        return template
685620
def load_template_help(builtin):
    """"""

    help_file = "templates/%s-help.yml" % builtin
    help_file = resource_filename(__name__, help_file)
    help_obj = {}
    if os.path.exists(help_file):
        help_data = yaml.safe_load(open(help_file))
        if 'name' in help_data:
            help_obj['name'] = help_data['name']

        if 'help' in help_data:
            help_obj['help'] = help_data['help']

        if 'args' in help_data:
            help_obj['args'] = help_data['args']

    return help_obj
622157
def get_host_template(self, name):
    
    return host_templates.get_host_template(self._get_resource_root(), name, self.name)
1217929
def get_template(name, base=None):
    '''
    '''
    # If the file doesn't exist, assume relative to base
    template_file = name
    if not os.path.exists(template_file):
        if base is None:
            base = get_templatedir()
        template_file = "%s/%s" %(base, name)

    # Then try again, if it still doesn't exist, bad name
    if os.path.exists(template_file):
        with open(template_file,"r") as filey:
            template = "".join(filey.readlines())
        return template
    bot.error("%s does not exist." %template_file)
364523
def GetConfigFromTemplate(self, template_path):
    """"""
    with zipfile.ZipFile(template_path) as template_zip:
      build_yaml = None
      for name in template_zip.namelist():
        if name.endswith("build.yaml"):
          build_yaml = name
          break
      if not build_yaml:
        raise RuntimeError("Couldn't find build.yaml in %s" % template_path)
      with template_zip.open(build_yaml) as buildfile:
        repack_config = config.CONFIG.CopyConfig()
        utf8_buildfile = io.TextIOWrapper(buildfile, encoding="utf-8")
        parser = config_lib.YamlParser(fd=utf8_buildfile)
        config_data = parser.RawData()
        self.Validate(config_data, template_path)
        repack_config.MergeData(config_data)
    return repack_config
732973
def get_template_path(self, content=None):
        
        if isinstance(content, Paginator):
            return op.join('api', 'paginator.%s' % self.format)

        if isinstance(content, UpdatedList):
            return op.join('api', 'updated.%s' % self.format)

        app = ''
        name = self.resource._meta.name

        if not content:
            content = self.resource._meta.model

        if isinstance(content, (Model, ModelBase)):
            app = content._meta.app_label
            name = content._meta.module_name

        basedir = 'api'
        if getattr(self.resource, 'api', None):
            basedir = self.resource.api.prefix

        return op.join(
            basedir,
            str(self.resource.api or ''), app, "%s.%s" % (name, self.format)
        )
1213857
def get_template(name):
    
    path = os.path.join(base_dir, name)

    if path not in templates:
        try:
            templates[path] = Template(path)
        except IOError:
            return None

    return copy.deepcopy(templates[path])
1144479
def find_name(self, template_name, search_dirs):
        
        file_name = self.make_file_name(template_name)

        return self._find_path_required(search_dirs, file_name)
608030
def _get_template(self, template_name, template_file):
        
        template = os.path.join(self.location, 'templates',
                                template_name, template_file)
        return jinja2.Template(open(template).read())
1110938
def dirs(self):
        
        if self._dirs.get(connection.schema_name, None) is None:
            try:
                # Use directories configured via MULTITENANT_TEMPLATE_DIRS
                dirs = [
                    utils.parse_tenant_config_path(dir_)
                    for dir_ in settings.MULTITENANT_TEMPLATE_DIRS
                ]
            except AttributeError:
                raise ImproperlyConfigured(
                    "To use {}.{} you must define the MULTITENANT_TEMPLATE_DIRS setting.".format(
                        __name__, Loader.__name__
                    )
                )

            self.dirs = dirs

        return self._dirs[connection.schema_name]
456353
def _service_by_name(name):
    '''
    
    '''
    services = _available_services()
    name = name.lower()

    if name in services:
        # Match on label
        return services[name]

    for service in six.itervalues(services):
        if service['file_path'].lower() == name:
            # Match on full path
            return service
        basename, ext = os.path.splitext(service['filename'])
        if basename.lower() == name:
            # Match on basename
            return service

    return False
237560
def _TemplateNamesToFiles(self, template_str):
        """"""
        template_list = template_str.split(":")
        template_files = []
        try:
            for tmplt in template_list:
                template_files.append(open(os.path.join(self.template_dir, tmplt), "r"))
        except:  # noqa
            for tmplt in template_files:
                tmplt.close()
            raise

        return template_files
933095
def linkify_templates(self):
        
        self.hosts.linkify_templates()
        self.contacts.linkify_templates()
        self.services.linkify_templates()
        self.servicedependencies.linkify_templates()
        self.hostdependencies.linkify_templates()
        self.timeperiods.linkify_templates()
        self.hostsextinfo.linkify_templates()
        self.servicesextinfo.linkify_templates()
        self.escalations.linkify_templates()
        # But also old srv and host escalations
        self.serviceescalations.linkify_templates()
        self.hostescalations.linkify_templates()
696835
def load_template(self, name):
        
        # hopefully speeds up loading of templates a little, especially when loaded multiple times
        if name in self.cached_templates:
            logger.debug("Using cached template: %s", name)
            return self.cached_templates[name]

        logger.debug("Attempting to find template by name: %s", name)
        name_with_ext, provider_name, base_path = self.find_template_details(name)

        full_path = None
        if base_path is not None:
            full_path = os.path.join(base_path, name_with_ext)

        # load it with the relevant provider
        template = template_exception_handler(
            lambda: self.get_provider(provider_name).load_template(
                name_with_ext,
                full_path=full_path
            ),
            self.error_context,
            filename=full_path
        )

        # cache it for potential later use
        self.cached_templates[name] = template
        return template
94628
def get_template(self, name):
        """"""
        filename = path.join(self.search_path, *[p for p in name.split('/')
                                                 if p and p[0] != '.'])
        if not path.exists(filename):
            raise TemplateNotFound(name)
        return Template.from_file(filename, self.encoding)
869422
public static String getConfiguredTemplateMapping() {

        String param = null;
        for (CmsModule module : OpenCms.getModuleManager().getAllInstalledModules()) {
            param = module.getParameter("template-mapping");
            if (param != null) {
                break;
            }
        }
        return param;
    }