Example #1
0
    def fix_paths(self, d, root=None, project=None):
        """
        Fix the paths in the given dictionary to get absolute paths

        Parameters
        ----------
        d: dict
            One experiment configuration dictionary
        root: str
            The root path of the project
        project: str
            The project name

        Returns
        -------
        dict
            The modified `d`

        Notes
        -----
        d is modified in place!"""
        if root is None and project is None:
            project = d.get('project')
            if project is not None:
                root = self.projects[project]['root']
            else:
                root = d['root']
        elif root is None:
            root = self.projects[project]['root']
        elif project is None:
            pass
        paths = self.paths
        for key, val in d.items():
            if isinstance(val, dict):
                d[key] = self.fix_paths(val, root, project)
            elif key in paths:
                val = d[key]
                if isinstance(val, six.string_types) and not osp.isabs(val):
                    d[key] = osp.join(root, val)
                elif (isinstance(utils.safe_list(val)[0], six.string_types) and
                      not osp.isabs(val[0])):
                    for i in range(len(val)):
                        val[i] = osp.join(root, val[i])
        return d
Example #2
0
    def rel_paths(self, d, root=None, project=None):
        """
        Fix the paths in the given dictionary to get relative paths

        Parameters
        ----------
        %(ExperimentsConfig.fix_paths.parameters)s

        Returns
        -------
        %(ExperimentsConfig.fix_paths.returns)s

        Notes
        -----
        d is modified in place!"""
        if root is None and project is None:
            project = d.get('project')
            if project is not None:
                root = self[project]['root']
            else:
                root = d['root']
        elif root is None:
            root = self[project]['root']
        elif project is None:
            pass
        paths = self.paths
        for key, val in d.items():
            if isinstance(val, dict):
                d[key] = self.rel_paths(val, root, project)
            elif key in paths:
                val = d[key]
                if isinstance(val, six.string_types) and osp.isabs(val):
                    d[key] = osp.relpath(val, root)
                elif (isinstance(utils.safe_list(val)[0], six.string_types) and
                      osp.isabs(val[0])):
                    for i in range(len(val)):
                        val[i] = osp.relpath(val[i], root)
        return d