class ImportsManager(object): def __init__(self, project): self.project = project self.templates = None def _load_templates(self): # TODO: detect if the config file changed, and reload. if self.templates is not None: return self.templates = OrderedDict() config_path = join(self.project.path, 'manager', 'imports_config.py') config = { # Give access to the project 'project': self.project, } if os.path.isfile(config_path): execfile(config_path, { 'project': self.project, }, config) if 'import_templates' not in config: log.warn('No imports config') return for template_config in config['import_templates']: template = ImportTemplate(self, template_config) self.templates[template.id] = template def get_import_templates(self): self._load_templates() # TODO: sort by key return self.templates.values() def get_import_template(self, template_id): self._load_templates() return self.templates[template_id] def get_import(self, template_id, import_id): import_template = self.get_import_template(template_id) return import_template.get_import(import_id)