def introspect(self): self._ensure_datatype_tables_are_created() populate_datatypes_registry() for algo_category_class in IntrospectionRegistry.ADAPTERS: algo_category_id = self._populate_algorithm_categories(algo_category_class) self._populate_algorithms(algo_category_class, algo_category_id) removers_factory.update_dictionary(DATATYPE_REMOVERS)
def introspect(self, do_create): """ Introspect a given module to: - create tables for custom DataType; - populate adapter algorithms references. """ self.logger.debug("Introspection into module:" + self.module_name) module = __import__(self.module_name, globals(), locals(), ["__init__"]) try: path_adapters = module.ADAPTERS self.path_types = module.DATATYPES_PATH self.removers_path = module.REMOVERS_PATH self.path_portlets = getattr(module, 'PORTLETS_PATH', []) except Exception as excep: self.logger.warning("Module " + self.module_name + " is not fully introspect compatible!") self.logger.warning(excep.message) return if do_create: self.logger.debug("Found Datatypes_Path=" + str(self.path_types)) # DataTypes only need to be imported for adding to DB tables for path in self.path_types: self.__get_datatypes(path) session = SA_SESSIONMAKER() model.Base.metadata.create_all(bind=session.connection()) session.commit() session.close() self.logger.debug("Found Adapters_Dict=" + str(path_adapters)) for category_name in path_adapters: category_details = path_adapters[category_name] launchable = bool(category_details.get(LAUNCHABLE)) rawinput = bool(category_details.get(RAWINPUT)) display = bool(category_details.get(DISPLAYER)) order_nr = category_details.get(ORDER, 999) category_instance = dao.filter_category( category_name, rawinput, display, launchable, order_nr) if category_instance is not None: category_instance.last_introspection_check = datetime.datetime.now( ) category_instance.removed = False else: category_state = category_details.get(STATE, '') category_instance = model.AlgorithmCategory( category_name, launchable, rawinput, display, category_state, order_nr, datetime.datetime.now()) category_instance = dao.store_entity(category_instance) for actual_module in path_adapters[category_name]['modules']: self.__read_adapters(category_instance.id, actual_module) for path in self.path_portlets: self.__get_portlets(path) ### Register Remover instances for current introspected module removers.update_dictionary(self.get_removers_dict())
def introspect(self, do_create): """ Introspect a given module to: - create tables for custom DataType; - populate adapter algorithms references. """ self.logger.debug("Introspection into module:" + self.module_name) module = __import__(self.module_name, globals(), locals(), ["__init__"]) try: path_adapters = module.ADAPTERS self.path_types = module.DATATYPES_PATH self.removers_path = module.REMOVERS_PATH self.path_portlets = getattr(module, 'PORTLETS_PATH', []) except Exception as excep: self.logger.warning("Module " + self.module_name + " is not fully introspect compatible!") self.logger.warning(excep.message) return if do_create: self.logger.debug("Found Datatypes_Path=" + str(self.path_types)) # DataTypes only need to be imported for adding to DB tables for path in self.path_types: self.__get_datatypes(path) session = SA_SESSIONMAKER() model.Base.metadata.create_all(bind=session.connection()) session.commit() session.close() self.logger.debug("Found Adapters_Dict=" + str(path_adapters)) for category_name in path_adapters: category_details = path_adapters[category_name] launchable = bool(category_details.get(LAUNCHABLE)) rawinput = bool(category_details.get(RAWINPUT)) display = bool(category_details.get(DISPLAYER)) order_nr = category_details.get(ORDER, 999) category_instance = dao.filter_category(category_name, rawinput, display, launchable, order_nr) if category_instance is not None: category_instance.last_introspection_check = datetime.datetime.now() category_instance.removed = False else: category_state = category_details.get(STATE, '') category_instance = model.AlgorithmCategory(category_name, launchable, rawinput, display, category_state, order_nr, datetime.datetime.now()) category_instance = dao.store_entity(category_instance) for actual_module in path_adapters[category_name]['modules']: self.__read_adapters(category_instance.id, actual_module) for path in self.path_portlets: self.__get_portlets(path) ### Register Remover instances for current introspected module removers.update_dictionary(self.get_removers_dict())
) else: category_state = category_details[ STATE] if STATE in category_details else '' category_instance = model.AlgorithmCategory( category_name, launchable, rawinput, display, category_state, order_nr, datetime.datetime.now()) category_instance = dao.store_entity(category_instance) for actual_module in path_adapters[category_name]['modules']: self.__populate_algorithms(category_instance.id, actual_module) for path in self.path_portlets: self.__get_portlets(path) ### Register Remover instances for current introspected module removers.update_dictionary(self.get_removers_dict()) def __get_portlets(self, path_portlets): """ Given a path in the form of a python package e.g.: "tvb.portlets', import the package, get it's folder and look for all the XML files defined there, then read all the portlets defined there and store them in DB. """ portlet_package = __import__(path_portlets, locals(), globals(), ["__init__"]) portlet_folder = os.path.dirname(portlet_package.__file__) portlets_list = [] for file_n in os.listdir(portlet_folder): try: if file_n.endswith('.xml'): complete_file_path = os.path.join(portlet_folder, file_n)
category_instance = dao.filter_category(category_name, rawinput, display, launchable, order_nr) if category_instance is not None: category_instance.last_introspection_check = datetime.datetime.now() category_instance.removed = False else: category_state = category_details.get(STATE, '') category_instance = model.AlgorithmCategory(category_name, launchable, rawinput, display, category_state, order_nr, datetime.datetime.now()) category_instance = dao.store_entity(category_instance) for actual_module in path_adapters[category_name]['modules']: self.__read_adapters(category_instance.id, actual_module) for path in self.path_portlets: self.__get_portlets(path) ### Register Remover instances for current introspected module removers.update_dictionary(self.get_removers_dict()) def __read_adapters(self, category_key, module_name): """ Add or update lines into STORED_ADAPTERS table: One line for each custom class found which is extending from ABCAdapter. """ for adapters_file in Introspector.__read_module_variable(module_name): try: adapters_module = __import__(module_name + "." + adapters_file, globals(), locals(), [adapters_file]) for ad_class in dir(adapters_module): ad_class = adapters_module.__dict__[ad_class] if Introspector._is_concrete_subclass(ad_class, ABCAdapter): if ad_class.can_be_active(): stored_adapter = model.Algorithm(ad_class.__module__, ad_class.__name__, category_key,