def _run_localcommand(self, args): # a local command is being invoked, if local command support is not # installed, fail and report to the user. Otherwise, delegate # to running a local command if HAS_LOCAL_COMMANDS: runner = TemplerLocalCommand('add') result = runner.run(args[1:]) if result is None: return runner.return_code else: return result else: # situation 1, fail and report. print self.texts['no_localcommands_warning'] return 1
def list_sorted_templates(filter_group=False, scope='global'): """ Returns a dictionary of template lists by category. Key is the category name, value is a list of templates. If "filter_group" is True, then this explictly filters to things provided by the ZopeSkel package--thereby hiding any templates the user may have on their system that sit on top of zopeskel's base classes. This is required in places where we want to generate canonical documents, and don't want to accidentally include things from the machine it's being run on. "scope" determines whether to find top-level (global) templates, or templates that apply to local commands, or both. """ cats = {} templates = [] # grab a list of all paster create template entry points # # TODO: fix this filtering, post break-up this will not work as expected if scope in ['global', 'all']: if filter_group: t_e_ps = pkg_resources.get_entry_map( 'zopeskel')['paste.paster_create_template'].values() else: t_e_ps = pkg_resources.iter_entry_points( 'paste.paster_create_template') templates.extend(_get_templates(t_e_ps, BaseTemplate)) if scope in ['local', 'all']: from templer.localcommands.command import TemplerLocalCommand from templer.localcommands.template import TemplerLocalTemplate localcommand = TemplerLocalCommand('dummy') t_e_ps = localcommand._all_entry_points() templates.extend(_get_templates(t_e_ps, TemplerLocalTemplate)) templates.sort(key=lambda x: x['name']) for entry in templates: cats.setdefault(entry['category'], []).append(entry) return cats