Ejemplo n.º 1
0
    def include(self, new_value):
        if self._link is not None:
            raise TypeError("%s.include: You can either set link or include, but not both." % repr(self))

        if not new_value:
            self._include = None
            self.clean()
            return

        if '#' in new_value:
            url, path = new_value.split('#', 1)
        else:
            url, path = new_value, None

        terminology.deferred_load(url)

        if self.parent is None:
            self._include = new_value
            return

        term = terminology.load(url)
        new_section = term.get_section_by_path(path) if path is not None else term.sections[0]

        if self._include is not None:
            self.clean()
        self._include = new_value
        self.merge(new_section)
Ejemplo n.º 2
0
 def get_terminology_equivalent(self):
     repo = self.get_repository()
     if repo is None:
         return None
     term = terminology.load(repo)
     if term is None:
         return None
     return term.find_related(type=self.type)
Ejemplo n.º 3
0
 def get_terminology_equivalent(self):
     repo = self.get_repository()
     if repo is None:
         return None
     term = terminology.load(repo)
     if term is None:
         return None
     return term.find_related(type=self.type)
    def test_terminology_refresh(self):
        """
        Test terminology cache refresh using local files to detach
        loading and resolving from the live online terminology repository.
        """
        # Fetch current cache content specific to the two local terminologies
        # With the default file glob '*' all files in the odml cache directory would be
        # included in the test.
        file_filter = "*%s*" % self.temp_dir_base
        main_url = self.main_terminology_url

        # Initially load main and included file from temp directory into the odml cache directory
        terminology.load(main_url)

        orig_map = self._cache_files_map(file_filter)

        # Test cache content does not change
        terminology.load(main_url)
        load_map = self._cache_files_map(file_filter)

        self.assertEqual(len(orig_map), len(load_map))
        for curr_file in orig_map:
            self.assertIn(curr_file, load_map)
            self.assertEqual(orig_map[curr_file], load_map[curr_file])

        sleep_time = 0.5
        if platform == "darwin":
            sleep_time = 2

        # Sleep is needed since the tests might be too fast to result in a
        # different file mtime. Travis macOS seems to require sleep time > 1s.
        sleep(sleep_time)

        # Test refresh loads same cached files but changes them.
        # Different mtimes and id strings are sufficient.
        terminology.refresh(main_url)
        refresh_map = self._cache_files_map(file_filter)
        self.assertEqual(len(orig_map), len(refresh_map))
        for curr_file in orig_map:
            self.assertIn(curr_file, refresh_map)
            # Check identical md5 hash
            self.assertEqual(orig_map[curr_file][0], refresh_map[curr_file][0])
            # Check different mtime
            self.assertLess(orig_map[curr_file][1], refresh_map[curr_file][1])
Ejemplo n.º 5
0
    def get_popup_mapping_suggestions(self, prop):
        """
        build a submenu with mapping suggestions
        """
        repo = prop.parent.get_repository()
        if not repo: return None
        term = terminology.load(repo)

        menu = self.create_menu_item("Map", stock="odml-set-Mapping")
        submenu = self.get_popup_menu(
            lambda: self.get_popup_mapping_section(term, prop))
        menu.set_submenu(submenu)
        return menu
Ejemplo n.º 6
0
    def get_popup_mapping_suggestions(self, prop):
        """
        build a submenu with mapping suggestions
        """
        repo = prop.parent.get_repository()
        if not repo:
            return None
        term = terminology.load(repo)

        menu = self.create_menu_item("Map", stock="odml-set-Mapping")
        submenu = self.get_popup_menu(lambda: self.get_popup_mapping_section(term, prop))
        menu.set_submenu(submenu)
        return menu
Ejemplo n.º 7
0
 def get_mapping_object(url):
     """
     returns the object instance a mapping-url points to
     """
     url, stype, prop_name = mapable.parse_mapping(url)
     term = terminology.load(url)
     if term is None:
         raise MappingError("Terminology '%s' could not be loaded" % url)
     if stype is None:
         return term.sections[0]
     sec = term.find_related(type=stype)
     if sec is None:
         raise MappingError("No section of type '%s' could be found" % stype)
     if prop_name is None:
         return sec
     try:
         return sec.properties[prop_name]
     except KeyError:
         raise MappingError("No property named '%s' could be found in section '%s'" % (prop_name, sec.name))
Ejemplo n.º 8
0
 def get_mapping_object(url):
     """
     returns the object instance a mapping-url points to
     """
     url, stype, prop_name = mapable.parse_mapping(url)
     term = terminology.load(url)
     if term is None:
         raise MappingError("Terminology '%s' could not be loaded" % url)
     if stype is None:
         return term.sections[0]
     sec = term.find_related(type=stype)
     if sec is None:
         raise MappingError("No section of type '%s' could be found" %
                            stype)
     if prop_name is None:
         return sec
     try:
         return sec.properties[prop_name]
     except KeyError:
         raise MappingError(
             "No property named '%s' could be found in section '%s'" %
             (prop_name, sec.name))
Ejemplo n.º 9
0
 def get_terminology_equivalent(self):
     if self.repository is None:
         return None
     term = terminology.load(self.repository)
     return term