def get_plugins_as_table(name=None): """Retrieve a table listing all plugins and their requirements. Or just a single plugin if name is passed. Args: name str optional name of a specific plugin. Returns: table instance containing plugin descriptive data Raises: None """ table_body = [] header = TableRow([_('Title'), _('ID'), _('Requirements')], header=True) table_body.append(header) plugins_dict = dict([(pretty_function_name(p), p) for p in FunctionProvider.plugins]) if name is not None: if isinstance(name, basestring): # Add the names plugins_dict.update( dict([(p.__name__, p) for p in FunctionProvider.plugins])) msg = ('No plugin named "%s" was found. ' 'List of available plugins is: %s' % (name, ', '.join(plugins_dict.keys()))) if name not in plugins_dict: raise RuntimeError(msg) plugins_dict = {name: plugins_dict[name]} else: msg = ('get_plugins expects either no parameters or a string ' 'with the name of the plugin, you passed: ' '%s which is a %s' % (name, type(name))) raise Exception(msg) # Now loop through the plugins adding them to the table for key, func in plugins_dict.iteritems(): for requirement in requirements_collect(func): row = [] row.append(TableCell(get_function_title(func), header=True)) row.append(key) row.append(requirement) table_body.append(TableRow(row)) table = Table(table_body) table.caption = _('Available Impact Functions') return table
def get_plugins_as_table(name=None): """Retrieve a table listing all plugins and their requirements. Or just a single plugin if name is passed. Args: name str optional name of a specific plugin. Returns: table instance containing plugin descriptive data Raises: None """ table_body = [] header = TableRow([_('Title'), _('ID'), _('Requirements')], header=True) table_body.append(header) plugins_dict = dict([(pretty_function_name(p), p) for p in FunctionProvider.plugins]) if name is not None: if isinstance(name, basestring): # Add the names plugins_dict.update(dict([(p.__name__, p) for p in FunctionProvider.plugins])) msg = ('No plugin named "%s" was found. ' 'List of available plugins is: %s' % (name, ', '.join(plugins_dict.keys()))) if name not in plugins_dict: raise RuntimeError(msg) plugins_dict = {name: plugins_dict[name]} else: msg = ('get_plugins expects either no parameters or a string ' 'with the name of the plugin, you passed: ' '%s which is a %s' % (name, type(name))) raise Exception(msg) # Now loop through the plugins adding them to the table for key, func in plugins_dict.iteritems(): for requirement in requirements_collect(func): row = [] row.append(TableCell(get_function_title(func), header=True)) row.append(key) row.append(requirement) table_body.append(TableRow(row)) table = Table(table_body) table.caption = _('Available Impact Functions') return table
def get_plugins_as_table(dict_filter=None): """Retrieve a table listing all plugins and their requirements. Or just a single plugin if name is passed. Args: * dict_filter = dictionary that contains filters - id = list_id - title = list_title - category : list_category - subcategory : list_subcategory - layertype : list_layertype - datatype : list_datatype - unit: list_unit - disabled : list_disabled # not included Returns: * table contains plugins match with dict_filter Raises: None """ if dict_filter is None: dict_filter = { 'id': [], 'title': [], 'category': [], 'subcategory': [], 'layertype': [], 'datatype': [], 'unit': [] } table_body = [] # use this list for avoiding wrong order in dict atts = ['category', 'subcategory', 'layertype', 'datatype', 'unit'] header = TableRow([ tr('Title'), tr('ID'), tr('Category'), tr('Sub Category'), tr('Layer type'), tr('Data type'), tr('Unit') ], header=True) table_body.append(header) plugins_dict = dict([(pretty_function_name(p), p) for p in FunctionProvider.plugins]) not_found_value = 'N/A' for key, func in plugins_dict.iteritems(): for requirement in requirements_collect(func): dict_found = { 'title': False, 'id': False, 'category': False, 'subcategory': False, 'layertype': False, 'datatype': False, 'unit': False } dict_req = parse_single_requirement(str(requirement)) # If the impact function is disabled, do not show it if dict_req.get('disabled', False): continue for myKey in dict_found.iterkeys(): myFilter = dict_filter.get(myKey, []) if myKey == 'title': myValue = str(get_function_title(func)) elif myKey == 'id': myValue = str(key) else: myValue = dict_req.get(myKey, not_found_value) if myFilter != []: for myKeyword in myFilter: if type(myValue) == type(str()): if myValue == myKeyword: dict_found[myKey] = True break elif type(myValue) == type(list()): if myKeyword in myValue: dict_found[myKey] = True break else: if myValue.find(str(myKeyword)) != -1: dict_found[myKey] = True break else: dict_found[myKey] = True add_row = True for found_value in dict_found.itervalues(): if not found_value: add_row = False break if add_row: row = [] row.append(TableCell(get_function_title(func), header=True)) row.append(key) for myKey in atts: myValue = pretty_string( dict_req.get(myKey, not_found_value)) row.append(myValue) table_body.append(TableRow(row)) cw = 100 / 7 table_col_width = [ str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%' ] table = Table(table_body, col_width=table_col_width) table.caption = tr('Available Impact Functions') return table
def get_plugins_as_table(dict_filter=None): """Retrieve a table listing all plugins and their requirements. Or just a single plugin if name is passed. Args: * dict_filter = dictionary that contains filters - id = list_id - title = list_title - category : list_category - subcategory : list_subcategory - layertype : list_layertype - datatype : list_datatype - unit: list_unit - disabled : list_disabled # not included Returns: * table contains plugins match with dict_filter Raises: None """ if dict_filter is None: dict_filter = {'id': [], 'title': [], 'category': [], 'subcategory': [], 'layertype': [], 'datatype': [], 'unit': []} table_body = [] # use this list for avoiding wrong order in dict atts = ['category', 'subcategory', 'layertype', 'datatype', 'unit'] header = TableRow([tr('Title'), tr('ID'), tr('Category'), tr('Sub Category'), tr('Layer type'), tr('Data type'), tr('Unit')], header=True) table_body.append(header) plugins_dict = dict([(pretty_function_name(p), p) for p in FunctionProvider.plugins]) not_found_value = 'N/A' for key, func in plugins_dict.iteritems(): for requirement in requirements_collect(func): dict_found = {'title': False, 'id': False, 'category': False, 'subcategory': False, 'layertype': False, 'datatype': False, 'unit': False} dict_req = parse_single_requirement(str(requirement)) # If the impact function is disabled, do not show it if dict_req.get('disabled', False): continue for myKey in dict_found.iterkeys(): myFilter = dict_filter.get(myKey, []) if myKey == 'title': myValue = str(get_function_title(func)) elif myKey == 'id': myValue = str(key) else: myValue = dict_req.get(myKey, not_found_value) if myFilter != []: for myKeyword in myFilter: if type(myValue) == type(str()): if myValue == myKeyword: dict_found[myKey] = True break elif type(myValue) == type(list()): if myKeyword in myValue: dict_found[myKey] = True break else: if myValue.find(str(myKeyword)) != -1: dict_found[myKey] = True break else: dict_found[myKey] = True add_row = True for found_value in dict_found.itervalues(): if not found_value: add_row = False break if add_row: row = [] row.append(TableCell(get_function_title(func), header=True)) row.append(key) for myKey in atts: myValue = pretty_string(dict_req.get(myKey, not_found_value)) row.append(myValue) table_body.append(TableRow(row)) cw = 100 / 7 table_col_width = [str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%'] table = Table(table_body, col_width=table_col_width) table.caption = tr('Available Impact Functions') return table