예제 #1
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
예제 #2
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))
예제 #3
0
    def find_wralea_dir(self, directory, recursive=True):
        """
        Find in a directory wralea files,
        Search recursivly is recursive is True

        :return : a list of pkgreader instances
        """

        if DEBUG:
            t0 = clock()

        wralea_files = set()
        if(not os.path.isdir(directory)):
            logger.warning("%s Not a directory" % repr(directory))
            # self.log.add("%s Not a directory"%repr(directory))
            return []

        p = path(directory).abspath()

        # search for wralea.py
        if recursive and SEARCH_OUTSIDE_ENTRY_POINTS:
            for f in p.walkfiles("*wralea*.py"):
                wralea_files.add(str(f))
        else:
            wralea_files.update(p.glob("*wralea*.py"))

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

        if DEBUG:
            t1 = clock()
            dt = t1 - t0
            print('search wralea files takes %f sec' % dt)

        readers = list(map(self.get_pkgreader, wralea_files))

        if DEBUG:
            t2 = clock()
            dt1 = t2 - t1
            print('readers takes %f sec: ' % (dt1,))

        return readers
예제 #4
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