def _get_connector_examples(): return [{ 'id': i, 'nice_name': CONNECTORS.get()[i].NICE_NAME.get() or i, 'description': '', 'dialect': CONNECTORS.get()[i].DIALECT.get(), 'interface': CONNECTORS.get()[i].INTERFACE.get(), 'settings': CONNECTORS.get()[i].SETTINGS.get(), 'is_demo': True, } for i in CONNECTORS.get()]
def _get_installed_connectors(): global CONNECTOR_INSTANCES connector_config = CONNECTORS.get() if CONNECTOR_INSTANCES is None: CONNECTOR_INSTANCES = [] for i in connector_config: connector_class = [ connector_type for connector_type in CONNECTOR_TYPES if connector_type['dialect'] == connector_config[i].DIALECT. get() and connector_type['interface'] == connector_config[i].INTERFACE.get() ] CONNECTOR_INSTANCES.append({ 'nice_name': connector_config[i].NICE_NAME.get() or i, 'name': i, 'dialect': connector_config[i].DIALECT.get(), 'interface': connector_config[i].INTERFACE.get(), 'settings': connector_config[i].SETTINGS.get(), # From Connector class 'is_sql': True, 'id': None, 'category': connector_class[0]['category'], 'description': connector_class[0]['description'] }) return CONNECTOR_INSTANCES
def _get_installed_connectors(category=None, categories=None, dialect=None, interface=None): global CONNECTOR_INSTANCES global CONNECTOR_IDS config_connectors = CONNECTORS.get() if CONNECTOR_INSTANCES is None: CONNECTOR_INSTANCES = [] for i in config_connectors: connector_class = [ connector_class for connector_class in CONNECTOR_CLASSES if connector_class['dialect'] == config_connectors[i].DIALECT. get() and connector_class['interface'] == config_connectors[i].INTERFACE.get() ] connector = { 'nice_name': config_connectors[i].NICE_NAME.get() or i, 'name': i, 'dialect': config_connectors[i].DIALECT.get(), 'interface': config_connectors[i].INTERFACE.get(), 'settings': config_connectors[i].SETTINGS.get(), 'id': CONNECTOR_IDS, 'category': connector_class[0]['category'], 'description': connector_class[0]['description'] } connector.update(connector_class[0]['properties']) CONNECTOR_INSTANCES.append(connector) CONNECTOR_IDS += 1 connectors = CONNECTOR_INSTANCES if categories is not None: connectors = [ connector for connector in connectors if connector['category'] in categories ] if category is not None: connectors = [ connector for connector in connectors if connector['category'] == category ] if dialect is not None: connectors = [ connector for connector in connectors if connector['dialect'] == dialect ] if interface is not None: connectors = [ connector for connector in connectors if connector['interface'] == interface ] return connectors
def _get_installed_connectors(category=None, categories=None, dialect=None, interface=None, user=None): global CONNECTOR_INSTANCES global CONNECTOR_IDS config_connectors = CONNECTORS.get() if CONNECTOR_INSTANCES is None: CONNECTOR_INSTANCES = [] for i in config_connectors: connector_types = [] for connector_type in CONNECTOR_TYPES: if connector_type['dialect'] == config_connectors[ i].DIALECT.get(): connector_types.insert(0, connector_type) elif connector_type.get( 'interface') == config_connectors[i].INTERFACE.get(): connector_types.append(connector_type) if not connector_types: LOG.warn( 'Skipping connector %s as connector dialect %s or interface %s are not installed' % (i, config_connectors[i].DIALECT.get(), config_connectors[i].INTERFACE.get())) else: connector_type = connector_types[0] connector = { 'nice_name': config_connectors[i].NICE_NAME.get() or i, 'name': i, 'dialect': config_connectors[i].DIALECT.get(), 'interface': config_connectors[i].INTERFACE.get() or connector_type.get('interface'), 'settings': config_connectors[i].SETTINGS.get(), 'id': CONNECTOR_IDS, 'category': connector_type['category'], 'description': connector_type['description'], 'dialect_properties': connector_type.get('properties', {}) } CONNECTOR_INSTANCES.append(connector) CONNECTOR_IDS += 1 connectors = CONNECTOR_INSTANCES if categories is not None: connectors = [ connector for connector in connectors if connector['category'] in categories ] if category is not None: connectors = [ connector for connector in connectors if connector['category'] == category ] if dialect is not None: connectors = [ connector for connector in connectors if connector['dialect'] == dialect ] if interface is not None: connectors = [ connector for connector in connectors if connector['interface'] == interface ] if user is not None: allowed_connectors = user.get_permissions().values_list('app', flat=True) connectors = [ connector for connector in connectors if connector['name'] in allowed_connectors ] return connectors
def _get_installed_connectors(category=None, categories=None, dialect=None, interface=None, user=None): connectors = [] connector_instances = [ { 'id': connector.id, 'nice_name': connector.name, 'description': connector.description, 'dialect': connector.dialect, 'interface': None, 'settings': json.loads(connector.settings), 'is_demo': False, } for connector in Connector.objects.all() ] + [ # TODO move to samples? or auto { 'id': i, 'nice_name': CONNECTORS.get()[i].NICE_NAME.get() or i, 'description': '', 'dialect': CONNECTORS.get()[i].DIALECT.get(), 'interface': CONNECTORS.get()[i].INTERFACE.get(), 'settings': CONNECTORS.get()[i].SETTINGS.get(), 'is_demo': True, } for i in CONNECTORS.get() ] for connector in connector_instances: connector_types = [] for connector_type in get_connectors_types(): if connector_type['dialect'] == connector['dialect']: connector_types.insert(0, connector_type) elif connector_type.get('interface') == connector['interface']: connector_types.append(connector_type) if not connector_types: LOG.warn( 'Skipping connector %(id)s as connector dialect %(dialect)s or interface %(interface)s are not installed' % ({ 'id': connector['id'], 'dialect': connector['dialect'], 'interface': connector['interface'] })) else: connector_type = connector_types[0] connectors.append({ 'nice_name': connector['nice_name'], 'name': str(connector['id']), 'dialect': connector['dialect'], 'interface': connector['interface'] or connector_type['interface'], 'settings': connector['settings'], 'id': str(connector['id']), 'category': connector_type['category'], 'description': connector_type['description'], 'dialect_properties': connector_type.get('properties', {}) }) if categories is not None: connectors = [ connector for connector in connectors if connector['category'] in categories ] if category is not None: connectors = [ connector for connector in connectors if connector['category'] == category ] if dialect is not None: connectors = [ connector for connector in connectors if connector['dialect'] == dialect ] if interface is not None: connectors = [ connector for connector in connectors if connector['interface'] == interface ] if user is not None: allowed_connectors = user.get_permissions().values_list('app', flat=True) connectors = [ connector for connector in connectors if connector['id'] in allowed_connectors ] return connectors