def test_load_project_from_graphol_v3(session, qtbot, tmpdir): # GIVEN graphol = tmpdir.join('MovieOntology/MovieOntology_v3.graphol') grapholDir = tmpdir.join('MovieOntology') mkdir(str(grapholDir)) os.open(str(graphol), os.O_CREAT) fcopy( expandPath( '@tests/test_resources/loaders/graphol/v3/MovieOntology/MovieOntology_v3.graphol' ), str(graphol)) project = session.project diagram1 = 'movie' diagram2 = 'territory' with qtbot.waitSignal(session.sgnDiagramFocused): session.sgnFocusDiagram.emit(project.diagram('diagram')) # WHEN loader = GrapholIRIProjectLoader_v3(str(graphol), session) loader.run() # THEN assert diagram1 in map(lambda d: d.name, loader.session.project.diagrams()) assert len(loader.session.project.diagram(diagram1).nodes()) == 347 assert len(loader.session.project.diagram(diagram1).edges()) == 433 assert len( list( filter(lambda n: n.type() == Item.ConceptIRINode, loader.session.project.diagram(diagram1).nodes()))) == 65 assert len( list( filter(lambda n: n.type() == Item.RoleIRINode, loader.session.project.diagram(diagram1).nodes()))) == 60 assert len( list( filter(lambda n: n.type() == Item.AttributeIRINode, loader.session.project.diagram(diagram1).nodes()))) == 27 assert len( list( filter(lambda n: n.type() == Item.IndividualIRINode, loader.session.project.diagram(diagram1).nodes()))) == 0 assert diagram2 in map(lambda d: d.name, loader.session.project.diagrams()) assert len(loader.session.project.diagram(diagram2).nodes()) == 8 assert len(loader.session.project.diagram(diagram2).edges()) == 8 assert len( list( filter(lambda n: n.type() == Item.ConceptIRINode, loader.session.project.diagram(diagram2).nodes()))) == 2 assert len( list( filter(lambda n: n.type() == Item.RoleIRINode, loader.session.project.diagram(diagram2).nodes()))) == 2 assert len( list( filter(lambda n: n.type() == Item.AttributeIRINode, loader.session.project.diagram(diagram2).nodes()))) == 0 assert len( list( filter(lambda n: n.type() == Item.IndividualIRINode, loader.session.project.diagram(diagram2).nodes()))) == 0
def install(self, archive): """ Install the given plugin archive. During the installation process we'll check for a correct plugin structure, i.e. for the .spec file and the plugin module to be available. We won't check if the plugin actually runs since this will be handle by the application start sequence. :type archive: str :rtype: PluginSpec """ try: # CHECK FOR CORRECT PLUGIN ARCHIVE if not fexists(archive): raise PluginError('file not found: %s' % archive) if not File.forPath(archive) is File.Zip: raise PluginError('%s is not a valid plugin' % archive) # LOOKUP THE SPEC FILE zf = ZipFile(archive) zf_name_list = zf.namelist() if 'plugin.spec' in zf_name_list: LOGGER.debug('Found plugin .spec: %s', os.path.join(archive, 'plugin.spec')) plugin_spec_content = zf.read('plugin.spec').decode('utf8') plugin_spec = self.spec(plugin_spec_content) else: raise PluginError('missing plugin.spec in %s' % archive) # LOOKUP THE PLUGIN MODULE plugin_name = plugin_spec.get('plugin', 'id') for extension in importlib.machinery.all_suffixes() + ['/']: plugin_zip_module_path = '%s%s' % (plugin_name, extension) if plugin_zip_module_path in zf_name_list: LOGGER.debug('Found plugin module: %s', os.path.join(archive, plugin_zip_module_path)) break else: raise PluginError('missing plugin module in %s' % archive) # CHECK FOR THE PLUGIN TO BE ALREADY RUNNING plugin_id = plugin_spec.get('plugin', 'id') plugin_name = plugin_spec.get('plugin', 'name') if self.session.plugin(plugin_spec.get('plugin', 'id')): raise PluginError('plugin %s (id: %s) is already installed' % (plugin_name, plugin_id)) # CHECK FOR THE PLUGIN NAMESPACE TO BE UNIQUE if plugin_id in self.info: raise PluginError('plugin %s (id: %s) is already installed' % (plugin_name, plugin_id)) # COPY THE PLUGIN mkdir('@home/plugins/') fcopy(archive, '@home/plugins/') except Exception as e: LOGGER.error('Failed to install plugin: %s', e, exc_info=not isinstance(e, PluginError)) raise e else: return plugin_spec
def install(self, archive): """ Install the given reasoner archive. During the installation process we'll check for a correct reasoner structure, i.e. for the .spec file and the reasoner module to be available. We won't check if the reasoner actually runs since this will be handle by the application statt sequence. :type archive: str :rtype: ReasonerSpec """ try: ## CHECK FOR CORRECT REASONER ARCHIVE if not fexists(archive): raise ReasonerError('file not found: %s' % archive) if not File.forPath(archive) is File.Zip: raise ReasonerError('%s is not a valid reasoner' % archive) ## LOOKUP THE SPEC FILE zf = ZipFile(archive) zf_name_list = zf.namelist() for file_or_directory in zf_name_list: if file_or_directory.endswith('reasoner.spec'): LOGGER.debug('Found reasoner .spec: %s', os.path.join(archive, file_or_directory)) reasoner_spec_content = zf.read(file_or_directory).decode('utf8') reasoner_spec = self.spec(reasoner_spec_content) break else: raise ReasonerError('missing reasoner.spec in %s' % archive) ## LOOKUP THE REASONER MODULE reasoner_name = reasoner_spec.get('reasoner', 'id') reasoner_zip_base_path = rstrip(file_or_directory, 'reasoner.spec') reasoner_zip_module_base_path = os.path.join(reasoner_zip_base_path, reasoner_name) for extension in ('.pyc', '.pyo', '.py'): reasoner_zip_module_path = '%s%s' % (reasoner_zip_module_base_path, extension) if reasoner_zip_module_path in zf_name_list: LOGGER.debug('Found reasoner module: %s', os.path.join(archive, reasoner_zip_module_path)) break else: raise ReasonerError('missing reasoner module: %s.py(c|o) in %s' % (reasoner_zip_module_base_path, archive)) # CHECK FOR THE REASONER TO BE ALREADY RUNNING reasoner_id = reasoner_spec.get('reasoner', 'id') reasoner_name = reasoner_spec.get('reasoner', 'name') if self.session.reasoner(reasoner_spec.get('reasoner', 'id')): raise ReasonerError('reasoner %s (id: %s) is already installed' % (reasoner_name, reasoner_id)) # CHECK FOR THE REASONER NAMESPACE TO BE UNIQUE reasoner_module_base_path = rstrip(first(filter(None, reasoner_zip_module_path.split(os.path.sep))), File.Zip.extension) for path in (expandPath('@reasoners/'), expandPath('@home/reasoners/')): for entry in os.listdir(path): if reasoner_module_base_path == rstrip(entry, File.Zip.extension): raise ReasonerError('reasoner %s (id: %s) is already installed' % (reasoner_name, reasoner_id)) # COPY THE REASONER mkdir('@home/reasoners/') fcopy(archive, '@home/reasoners/') except Exception as e: LOGGER.error('Failed to install reasoner: %s', e, exc_info=not isinstance(e, ReasonerError)) raise e else: return reasoner_spec
def install(self, archive): """ Install the given plugin archive. During the installation process we'll check for a correct plugin structure, i.e. for the .spec file and the plugin module to be available. We won't check if the plugin actually runs since this will be handle by the application statt sequence. :type archive: str :rtype: PluginSpec """ try: ## CHECK FOR CORRECT PLUGIN ARCHIVE if not fexists(archive): raise PluginError('file not found: %s' % archive) if not File.forPath(archive) is File.Zip: raise PluginError('%s is not a valid plugin' % archive) ## LOOKUP THE SPEC FILE zf = ZipFile(archive) zf_name_list = zf.namelist() for file_or_directory in zf_name_list: if file_or_directory.endswith('plugin.spec'): LOGGER.debug('Found plugin .spec: %s', os.path.join(archive, file_or_directory)) plugin_spec_content = zf.read(file_or_directory).decode('utf8') plugin_spec = self.spec(plugin_spec_content) break else: raise PluginError('missing plugin.spec in %s' % archive) ## LOOKUP THE PLUGIN MODULE plugin_name = plugin_spec.get('plugin', 'id') plugin_zip_base_path = rstrip(file_or_directory, 'plugin.spec') plugin_zip_module_base_path = os.path.join(plugin_zip_base_path, plugin_name) for extension in ('.pyc', '.pyo', '.py'): plugin_zip_module_path = '%s%s' % (plugin_zip_module_base_path, extension) if plugin_zip_module_path in zf_name_list: LOGGER.debug('Found plugin module: %s', os.path.join(archive, plugin_zip_module_path)) break else: raise PluginError('missing plugin module: %s.py(c|o) in %s' % (plugin_zip_module_base_path, archive)) # CHECK FOR THE PLUGIN TO BE ALREADY RUNNING plugin_id = plugin_spec.get('plugin', 'id') plugin_name = plugin_spec.get('plugin', 'name') if self.session.plugin(plugin_spec.get('plugin', 'id')): raise PluginError('plugin %s (id: %s) is already installed' % (plugin_name, plugin_id)) # CHECK FOR THE PLUGIN NAMESPACE TO BE UNIQUE plugin_module_base_path = rstrip(first(filter(None, plugin_zip_module_path.split(os.path.sep))), File.Zip.extension) for path in (expandPath('@plugins/'), expandPath('@home/plugins/')): for entry in os.listdir(path): if plugin_module_base_path == rstrip(entry, File.Zip.extension): raise PluginError('plugin %s (id: %s) is already installed' % (plugin_name, plugin_id)) # COPY THE PLUGIN mkdir('@home/plugins/') fcopy(archive, '@home/plugins/') except Exception as e: LOGGER.error('Failed to install plugin: %s', e, exc_info=not isinstance(e, PluginError)) raise e else: return plugin_spec