Example #1
0
    def find_vlab_dir(self, directory, recursive=True):
        """
        Find in a directory vlab specification file.

        Search recursivly is recursive is True

        :return: a list of pkgreader instances
        """

        spec_files = set()
        if(not os.path.isdir(directory)):
            logger.error("Not a directory", directory, repr(directory))
            # self.log.add("Not a directory", directory, repr(directory))
            return []

        p = path(directory).abspath()
        spec_name = '*specifications'
        # search for wralea.py
        if(recursive and SEARCH_OUTSIDE_ENTRY_POINTS):
            spec_files.update(p.walkfiles(spec_name))
        else:
            spec_files.update(p.glob(spec_name))

        for f in spec_files:
            logger.info("Package Manager : found  VLAB %s" % p)
            # self.log.add("Package Manager : found  VLAB %s" % p)

        return list(map(self.get_pkgreader, spec_files))
Example #2
0
    def load_directory(self, dirname):
        """ Load a directory containing wraleas"""

        dirname = os.path.abspath(dirname)

        if(not os.path.exists(dirname) or
           not os.path.isdir(dirname)):
            logger.error("Package directory : %s does not exists." % (dirname,))
            # self.log.add("Package directory : %s does not exists."%(dirname,))
            return None

        self.add_wralea_path(dirname, self.user_wralea_path)

        # find wralea
        readers = self.find_wralea_dir(dirname)
        if not readers:
            logger.info("Search Vlab objects.")
            # self.log.add("Search Vlab objects.")
            readers = self.find_vlab_dir(dirname)
        ret = None
        for r in readers:
            if r:
                ret = r.register_packages(self)
            else:
                logger.error("Unable to load package %s." % (dirname,))
                # self.log.add("Unable to load package %s."%(dirname, ))
                ret = None

        if(readers):
#            self.save_cache()
            self.rebuild_category()

        return ret
Example #3
0
 def _load_entry_point_plugin(self,
                              category,
                              entry_point,
                              plugin_proxy=None):
     ep = entry_point
     identifier = '%s:%s:%s' % (category, ep.module_name, ep.name)
     plugin_class = None
     if identifier in self._plugin_loaded:
         plugin_class = self._plugin_loaded[identifier]
     else:
         if self.debug:
             plugin_class = ep.load()
             logger.debug('%s load plugin %s' %
                          (self.__class__.__name__, ep))
             self._plugin_loaded[identifier] = plugin_class
             self.add_plugin(category,
                             plugin_class,
                             plugin_proxy=plugin_proxy)
         else:
             try:
                 plugin_class = ep.load()
             except KeyboardInterrupt:
                 logger.error('%s: error loading %s ' % (category, ep))
             except Exception, e:
                 # never want a plugin load to kill the test run
                 # but we can't log here because the logger is not yet
                 # configured
                 warn("Unable to load plugin %s: %s" % (ep, e),
                      RuntimeWarning)
             else:
                 logger.debug('%s load plugin %s' %
Example #4
0
 def _load_entry_point_plugin(self, group, entry_point, item_proxy=None):
     ep = entry_point
     plugin_class = None
     if self.debug:
         plugin_class = ep.load()
         logger.debug('%s load plugin %s' % (self.__class__.__name__, ep))
         self._add_plugin_from_ep(group, ep, plugin_class, item_proxy)
     else:
         try:
             plugin_class = ep.load()
         except Exception:
             logger.error('%s: error loading %s ' % (group, ep))
         else:
             self._add_plugin_from_ep(group, ep, plugin_class, item_proxy)
Example #5
0
 def __call__(self, category, func=None, **kwds):
     """
     Use this method to launch a function in debug mode.
     If debug is enabled for this category, errors are raised,
     else debug is disable, errors pass silently.
     """
     func_args = kwds.pop('func_args', [])
     func_kwds = kwds.pop('func_kwds', {})
     callback = kwds.pop('callback', None)
     if self._debug_mode(category):
         return func(*func_args, **func_kwds)
     else:
         try:
             return func(*func_args, **func_kwds)
         except:
             logger.error('%s: error calling %s ' % (category, func))
             if callback:
                 callback()
Example #6
0
 def __call__(self, category, func=None, **kwds):
     """
     Use this method to launch a function in debug mode.
     If debug is enabled for this category, errors are raised,
     else debug is disable, errors pass silently.
     """
     func_args = kwds.pop('func_args', [])
     func_kwds = kwds.pop('func_kwds', {})
     callback = kwds.pop('callback', None)
     if self._debug_mode(category):
         return func(*func_args, **func_kwds)
     else:
         try:
             return func(*func_args, **func_kwds)
         except:
             logger.error('%s: error calling %s ' % (category, func))
             if callback:
                 callback()
Example #7
0
 def _load_entry_point_plugin(self, category, entry_point, plugin_proxy=None):
     ep = entry_point
     identifier = "%s:%s:%s" % (category, ep.module_name, ep.name)
     plugin_class = None
     if identifier in self._plugin_loaded:
         plugin_class = self._plugin_loaded[identifier]
     else:
         if self.debug:
             plugin_class = ep.load()
             logger.debug("%s load plugin %s" % (self.__class__.__name__, ep))
             self._plugin_loaded[identifier] = plugin_class
             self.add_plugin(category, plugin_class, plugin_proxy=plugin_proxy)
         else:
             try:
                 plugin_class = ep.load()
             except KeyboardInterrupt:
                 logger.error("%s: error loading %s " % (category, ep))
             except Exception, e:
                 # never want a plugin load to kill the test run
                 # but we can't log here because the logger is not yet
                 # configured
                 warn("Unable to load plugin %s: %s" % (ep, e), RuntimeWarning)
             else:
                 logger.debug("%s load plugin %s" % (self.__class__.__name__, ep))
Example #8
0
    def set_sys_wralea_path(self):
        """ Define the default wralea search path

        For that, we look for "wralea" entry points
        and deprecated_wralea entry point
        if a package is declared as deprecated_wralea,
        the module is not load
        """

        if self.sys_wralea_path:
            return

        self.sys_wralea_path = set()
        self.deprecated_pkg = set()

        if DEBUG:
            res = {}
        # Use setuptools entry_point
        for epoint in iter_entry_points("wralea"):
            # Get Deprecated packages
            if self.verbose:
                pmanLogger.debug(epoint.name + " " + epoint.module_name)
            if(epoint.module_name == "deprecated"):
                self.deprecated_pkg.add(epoint.name.lower())
                continue

            # base = epoint.dist.location
            # m = epoint.module_name.split('.')
            # p = os.path.join(base, *m)

            # Be careful, this lines will import __init__.py and all its predecessor
            # to find the path.
            if DEBUG:
                print(epoint.module_name)
                t1 = clock()

            try:
                m = importlib.import_module(epoint.module_name)
                #m = __import__(epoint.module_name, fromlist=epoint.module_name)
            except ImportError as e:
                logger.error("Cannot load %s : %s" % (epoint.module_name, e))
                # self.log.add("Cannot load %s : %s"%(epoint.module_name, e))
                continue

            if DEBUG:
                print((epoint.module_name))
                tn = clock() - t1
                res[tn] = epoint.module_name


            l = list(m.__path__)
            for p in l:
                p = os.path.abspath(p)
                logger.info("Wralea entry point: %s (%s) " % (epoint.module_name, p))
                # self.log.add("Wralea entry point: %s (%s) "%(epoint.module_name, p))
                self.add_wralea_path(p, self.sys_wralea_path)

        # Search the path based on the old method (by hand).
        # Search in openalea namespace
#        if(self.include_namespace):
#            l = list(openalea.__path__)
#            for p in l :
#                self.add_wralea_path(p, self.sys_wralea_path)

        if SEARCH_OUTSIDE_ENTRY_POINTS:
            self.add_wralea_path(os.path.dirname(__file__), self.sys_wralea_path)
            self.add_wralea_path(get_userpkg_dir(), self.sys_wralea_path)

        if DEBUG:
            return res