예제 #1
0
 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)
                 portlet_reader = XMLPortletReader.get_instance(complete_file_path)
                 portlet_list = portlet_reader.get_algorithms_dictionary()
                 self.logger.debug("Starting to verify currently declared portlets in %s." % (file_n,))
                 for algo_identifier in portlet_list:
                     adapters_chain = portlet_reader.get_adapters_chain(algo_identifier)
                     is_valid = True
                     for adapter in adapters_chain:
                         class_name = adapter[ABCAdapter.KEY_TYPE].split('.')[-1]
                         module_name = adapter[ABCAdapter.KEY_TYPE].replace('.' + class_name, '')
                         try:
                             #Check that module is properly declared
                             module = __import__(module_name, class_name, globals(), locals())
                             if type(module) != ModuleType:
                                 is_valid = False
                                 self.logger.error("Wrong module %s in portlet %s" % (module_name, algo_identifier))
                                 continue
                             #Check that class is properly declared
                             if not hasattr(module, class_name):
                                 is_valid = False
                                 self.logger.error("Wrong class %s in portlet %s." % (class_name, algo_identifier))
                                 continue
                             #Check inputs that refers to this adapter
                             portlet_inputs = portlet_list[algo_identifier][INPUTS_KEY]
                             adapter_instance, _ = PortletConfigurer.build_adapter_from_declaration(adapter)
                             if adapter_instance is None:
                                 is_valid = False
                                 self.logger.warning("No group having class=%s stored for "
                                                     "portlet %s." % (class_name, algo_identifier))
                                 continue
                             adapter_input_names = [entry[ABCAdapter.KEY_NAME] for entry
                                                    in adapter_instance.flaten_input_interface()]
                             for input_entry in portlet_inputs:
                                 if portlet_inputs[input_entry][ATT_OVERWRITE] == adapter[ABCAdapter.KEY_NAME]:
                                     if portlet_inputs[input_entry][ABCAdapter.KEY_NAME] not in adapter_input_names:
                                         self.logger.error("Invalid input %s for adapter %s" % (
                                             portlet_inputs[input_entry][ABCAdapter.KEY_NAME], adapter_instance))
                                         is_valid = False
                         except ImportError, _:
                             self.logger.error("Invalid adapter declaration %s in portlet %s" % (
                                               adapter[ABCAdapter.KEY_TYPE], algo_identifier))
                             is_valid = False
                     if is_valid:
                         portlets_list.append(model.Portlet(algo_identifier, complete_file_path,
                                                            portlet_list[algo_identifier]['name']))
         except XmlParserException, excep:
             self.logger.exception(excep)
             self.logger.error("Invalid Portlet description File " + file_n + " will continue without it!!")
예제 #2
0
 def __init__(self, portlet_entity):
     self.log = get_logger(self.__class__.__module__)
     self.reader = XMLPortletReader.get_instance(portlet_entity.xml_path)
     self.portlet_entity = portlet_entity
예제 #3
0
 def __init__(self, portlet_entity):
     self.log = get_logger(self.__class__.__module__)
     self.reader = XMLPortletReader.get_instance(portlet_entity.xml_path)
     self.portlet_entity = portlet_entity
예제 #4
0
 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)
                 portlet_reader = XMLPortletReader.get_instance(
                     complete_file_path)
                 portlet_list = portlet_reader.get_algorithms_dictionary()
                 self.logger.debug(
                     "Starting to verify currently declared portlets in %s."
                     % (file_n, ))
                 for algo_identifier in portlet_list:
                     adapters_chain = portlet_reader.get_adapters_chain(
                         algo_identifier)
                     is_valid = True
                     for adapter in adapters_chain:
                         class_name = adapter[ABCAdapter.KEY_TYPE].split(
                             '.')[-1]
                         module_name = adapter[ABCAdapter.KEY_TYPE].replace(
                             '.' + class_name, '')
                         try:
                             #Check that module is properly declared
                             module = __import__(module_name, class_name,
                                                 globals(), locals())
                             if type(module) != ModuleType:
                                 is_valid = False
                                 self.logger.error(
                                     "Wrong module %s in portlet %s" %
                                     (module_name, algo_identifier))
                                 continue
                             #Check that class is properly declared
                             if not hasattr(module, class_name):
                                 is_valid = False
                                 self.logger.error(
                                     "Wrong class %s in portlet %s." %
                                     (class_name, algo_identifier))
                                 continue
                             #Check inputs that refers to this adapter
                             portlet_inputs = portlet_list[algo_identifier][
                                 INPUTS_KEY]
                             adapter_instance, _ = PortletConfigurer.build_adapter_from_declaration(
                                 adapter)
                             if adapter_instance is None:
                                 is_valid = False
                                 self.logger.warning(
                                     "No group having class=%s stored for "
                                     "portlet %s." %
                                     (class_name, algo_identifier))
                                 continue
                             adapter_input_names = [
                                 entry[ABCAdapter.KEY_NAME] for entry in
                                 adapter_instance.flaten_input_interface()
                             ]
                             for input_entry in portlet_inputs:
                                 if portlet_inputs[input_entry][
                                         ATT_OVERWRITE] == adapter[
                                             ABCAdapter.KEY_NAME]:
                                     if portlet_inputs[input_entry][
                                             ABCAdapter.
                                             KEY_NAME] not in adapter_input_names:
                                         self.logger.error(
                                             "Invalid input %s for adapter %s"
                                             % (portlet_inputs[input_entry][
                                                 ABCAdapter.KEY_NAME],
                                                adapter_instance))
                                         is_valid = False
                         except ImportError, _:
                             self.logger.error(
                                 "Invalid adapter declaration %s in portlet %s"
                                 % (adapter[ABCAdapter.KEY_TYPE],
                                    algo_identifier))
                             is_valid = False
                     if is_valid:
                         portlets_list.append(
                             model.Portlet(
                                 algo_identifier, complete_file_path,
                                 portlet_list[algo_identifier]['name']))
         except XmlParserException, excep:
             self.logger.exception(excep)
             self.logger.error("Invalid Portlet description File " +
                               file_n + " will continue without it!!")