def get_template_sources(self, template_name, _=None): """ Returns the absolute paths to "template_name", when appended to each directory in "template_dirs". Any paths that don't lie inside one of the template dirs are excluded from the result set, for security reasons. """ recipes.autodiscover() template_dirs = [] base_recipe = recipes.registry.get_base_recipe() module = (importpath(base_recipe.__module__)) template_dir = join(dirname(module.__file__), 'templates') if exists(template_dir) and isdir(template_dir): template_dirs.append(template_dir) for recipe in recipes.registry.all(): module = (importpath(recipe.__module__)) template_dir = join(dirname(module.__file__), 'templates') if exists(template_dir) and isdir(template_dir): template_dirs.append(template_dir) print 'Search in dirs:', template_dirs for template_dir in template_dirs: try: yield safe_join(template_dir, template_name) except UnicodeDecodeError: # The template dir name was a bytestring that wasn't valid UTF-8. raise except ValueError: # The joined path was located outside of this particular # template_dir (it might be inside another one, so this isn't # fatal). pass
def find_raw_folder(self): target_dir = self.project.path # Append raw folder in module module = (importpath(self.__module__)) raw_dirname = join(dirname(module.__file__), 'raw') if exists(raw_dirname) and isdir(raw_dirname): self.raw.append(RawDirectory(self, raw_dirname, target_dir))
def autodiscover(): for mod in __all__: try: registry.register(importpath('recipes.' + mod + '.recipe')) except (ImportError, AlreadyRegistered): pass