Пример #1
0
    def find_all(cls, location, key='slug', reload=False):
        """ List all workflows in the given location.

        :param location:    Location where the workflows are located
        :type location:     unicode or :py:class:`pathlib.Path`
        :param key:         Attribute to use as key for returned dict
        :type key:          str/unicode
        :param reload:      Do not load workflows from cache
        :type reload:       bool
        :return:            All found workflows
        :rtype:             dict
        """
        if not isinstance(location, Path):
            location = Path(location)
        if key not in ('slug', 'id'):
            raise ValueError("'key' must be one of ('id', 'slug')")
        if location in cls._cache and not reload:
            found = cls._cache[location]
        else:
            found = []
        for candidate in location.iterdir():
            is_workflow = (location.is_dir() and
                           ((candidate/'bagit.txt').exists or
                            (candidate/'raw').exists))
            if not is_workflow:
                continue
            if not next((wf for wf in found if wf.path == candidate), None):
                logging.debug(
                    "Cache missed, instantiating workflow from {0}."
                    .format(candidate))
                workflow = cls(candidate)
                found.append(workflow)
        cls._cache[location] = found
        return {getattr(wf, key): wf for wf in cls._cache[location]}
Пример #2
0
    def find_all(cls, location, key='slug', reload=False):
        """ List all workflows in the given location.

        :param location:    Location where the workflows are located
        :type location:     unicode/pathlib.Path
        :param key:         Attribute to use as key for returned dict
        :type key:          str
        :param reload:      Do not load workflows from cache
        :type reload:       bool
        :return:            All found workflows
        :rtype:             dict
        """
        if not isinstance(location, Path):
            location = Path(location)
        if key not in ('slug', 'id'):
            raise ValueError("'key' must be one of ('id', 'slug')")
        if location in cls._cache and not reload:
            found = cls._cache[location]
        else:
            found = []
        for candidate in location.iterdir():
            is_workflow = (location.is_dir() and
                           ((candidate/'bagit.txt').exists
                            or (candidate/'raw').exists))
            if not is_workflow:
                continue
            if not next((wf for wf in found if wf.path == candidate), None):
                logging.debug(
                    "Cache missed, instantiating workflow from {0}."
                    .format(candidate))
                workflow = cls(candidate)
                found.append(workflow)
        cls._cache[location] = found
        return {getattr(wf, key): wf for wf in cls._cache[location]}