コード例 #1
0
    def get_tags(self, site=None, study=None):
        """
        Returns a TagInfo instance.

        If you get the tags without a study set or without specifying a site
        you get the configuration of all defined tags from 'ExportSettings' in
        the system config file.

        If you specify a site, you get the configuration for that site merged
        with the configuration of 'ExportSettings' for the tags matching that
        site. If there's a key conflict between 'ExportInfo' (study config) and
        'ExportSettings' (system config) the values in 'ExportInfo' will
        override the values in 'ExportSettings'.
        """
        if site:
            export_info = self.get_key("ExportInfo", site=site)
        else:
            export_info = {}

        try:
            export_settings = self.get_key("ExportSettings")
        except UndefinedSetting:
            raise UndefinedSetting("Tag dictionary 'ExportSettings' not "
                                   "defined in main configuration file.")

        return TagInfo(export_settings, export_info)
コード例 #2
0
    def set_study(self, study_name):
        """
        This function can take just the study ID for every study except DTI. So
        where possible, please give it an exact match to a project name or a
        full session ID.
        """
        # make the supplied project_name case insensitive
        valid_projects = {k.lower(): k for k in self.get_key("Projects")}

        if study_name.lower() in valid_projects:
            study_name = study_name.upper()
        else:
            # This will raise an exception if given only the 'DTI' id because
            # two studies are mapped to this ID. Give set_study() a full
            # session ID to avoid this
            study_name = self.map_xnat_archive_to_project(study_name)

        self.study_name = study_name

        config_path = self.get_key("ConfigDir")
        projects = self.get_key("Projects")

        try:
            study_yaml = projects[study_name]
        except KeyError:
            raise UndefinedSetting(f"Study {study_name} not configured.")

        project_settings_file = os.path.join(config_path, study_yaml)
        self.study_config = self.load_yaml(project_settings_file)
        self.study_config_path = project_settings_file
コード例 #3
0
    def get_path(self, path_type, study=None):
        """returns the absolute path to a folder type"""
        paths = self.get_key("Paths")

        try:
            sub_dir = paths[path_type]
        except KeyError:
            raise UndefinedSetting(f"Path {path_type} not defined")

        return os.path.join(self.get_study_base(), sub_dir)
コード例 #4
0
    def _search_system_conf(self, key):
        """
        Searches the global system-wide settings for 'key'. Will not search
        recursively (i.e. will not check within studies or sites)

        Raises UndefinedSetting if key is not found.
        """
        try:
            value = self.system_config[key]
        except KeyError:
            raise UndefinedSetting(f"'{key}' not set")
        return value
コード例 #5
0
    def _search_study_conf(self, key):
        """
        Search the current study's config for 'key'. Does not search
        recursively i.e. will not check all sites.

        Raises UndefinedSetting if key is not found
        """
        if not self.study_config:
            raise ConfigException("Study not set.")
        try:
            value = self.study_config[key]
        except KeyError:
            raise UndefinedSetting(
                f"'{key}' not defined for study {self.study_name}")
        return value
コード例 #6
0
    def _search_site_conf(self, site, key):
        """
        Search a specific study's site for 'key'.

        Raises 'UndefinedSetting' if the key does not exist
        """
        try:
            site_conf = self._search_study_conf("Sites")
        except UndefinedSetting:
            raise ConfigException(
                f"'Sites' not defined for study {self.study_name}")
        try:
            site_conf = site_conf[site]
        except KeyError:
            raise ConfigException(
                f"Site '{site}' not found for study {self.study_name}")
        try:
            value = site_conf[key]
        except KeyError:
            raise UndefinedSetting(f"'{key}' not set for site {site}")
        return value
コード例 #7
0
    def _search_local_conf(self, key):
        """
        Searches the currently configured system (i.e. the system found in
        'SystemSettings' for 'key')

        Raises UndefinedSetting if key is not found
        """
        try:
            system_settings = self._search_system_conf("SystemSettings")
        except UndefinedSetting:
            raise ConfigException("'SystemSettings' not defined")
        try:
            local_system = system_settings[self.system]
        except KeyError:
            raise ConfigException(
                f"System '{key}' not defined in SystemSettings")
        try:
            value = local_system[key]
        except KeyError:
            raise UndefinedSetting(
                f"'{key}' not defined for system {self.system}")
        return value