Exemple #1
0
 def make_plugins(self):
     """
     Package built-in plugins into ZIP archives.
     """
     if isdir('@plugins/'):
         mkdir(os.path.join(self.build_exe, 'plugins'))
         for file_or_directory in os.listdir(expandPath('@plugins/')):
             plugin = os.path.join(expandPath('@plugins/'), file_or_directory)
             if isdir(plugin):
                 distutils.log.info('packaging plugin: %s', file_or_directory)
                 zippath = os.path.join(self.build_exe, 'plugins', '%s.zip' % file_or_directory)
                 with zipfile.ZipFile(zippath, 'w', zipfile.ZIP_STORED) as zipf:
                     for root, dirs, files in os.walk(plugin):
                         if not root.endswith('__pycache__'):
                             for filename in files:
                                 path = expandPath(os.path.join(root, filename))
                                 if path.endswith('.py'):
                                     new_path = '%s.pyc' % rstrip(path, '.py')
                                     py_compile.compile(path, new_path)
                                     arcname = os.path.join(file_or_directory, os.path.relpath(new_path, plugin))
                                     zipf.write(new_path, arcname)
                                     fremove(new_path)
                                 else:
                                     arcname = os.path.join(file_or_directory, os.path.relpath(path, plugin))
                                     zipf.write(path, arcname)
Exemple #2
0
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
Exemple #3
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
Exemple #4
0
 def createProjectFile(self):
     """
     Serialize a previously created QDomDocument to disk.
     """
     try:
         mkdir(self.project.path)
         filename = postfix(self.project.name, File.Graphol.extension)
         filepath = os.path.join(self.project.path, filename)
         fwrite(self.document.toString(2), filepath)
     except Exception as e:
         raise e
     else:
         LOGGER.info('Saved project %s to %s', self.project.name, self.project.path)
Exemple #5
0
 def createProjectFile(self):
     """
     Serialize a previously created QDomDocument to disk.
     """
     try:
         mkdir(self.project.path)
         filename = postfix(self.project.name, File.Graphol.extension)
         filepath = os.path.join(self.project.path, filename)
         fwrite(self.document.toString(2), filepath)
     except Exception as e:
         raise e
     else:
         LOGGER.info('Saved project %s to %s', self.project.name,
                     self.project.path)
Exemple #6
0
 def setUp(self):
     """
     Initialize test case environment.
     """
     # MAKE SURE TO USE CORRECT SETTINGS
     settings = QtCore.QSettings(ORGANIZATION, APPNAME)
     settings.setValue('workspace/home', WORKSPACE)
     settings.setValue('update/check_on_startup', False)
     settings.sync()
     # MAKE SURE THE WORKSPACE DIRECTORY EXISTS
     mkdir(expandPath(WORKSPACE))
     # MAKE SURE TO HAVE A CLEAN TEST ENVIRONMENT
     rmdir('@tests/.tests/')
     mkdir('@tests/.tests/')
     # INITIALIZED VARIABLES
     self.eddy = None
     self.project = None
     self.session = None
Exemple #7
0
 def createProjectFile(self):
     """
     Serialize a previously created QDomDocument to disk.
     """
     try:
         currPath = self.exportPath if self.exportPath else self.project.path
         if not fexists(currPath):
             folderPath = os.path.dirname(currPath)
             if not isdir(folderPath):
                 mkdir(folderPath)
             fd = os.open(currPath, os.O_CREAT)
             os.close(fd)
         #TODO filename = postfix(self.project.name, File.Graphol.extension)
         #TODO filepath = os.path.join(self.project.path, filename)
         #TODO fwrite(self.document.toString(2), filepath)
         fwrite(self.document.toString(2), currPath)
     except Exception as e:
         raise e
     else:
         LOGGER.info('Saved project %s to %s', self.project.name, currPath)
Exemple #8
0
 def setUp(self):
     """
     Initialize test case environment.
     """
     # ACQUIRE LOCK AND FLUSH STREAMS
     testcase_lock.acquire()
     sys.stderr.flush()
     sys.stdout.flush()
     # MAKE SURE TO USE CORRECT SETTINGS
     settings = QtCore.QSettings(ORGANIZATION, APPNAME)
     settings.setValue('workspace/home', WORKSPACE)
     settings.setValue('update/check_on_startup', False)
     settings.sync()
     # MAKE SURE THE WORKSPACE DIRECTORY EXISTS
     mkdir(expandPath(WORKSPACE))
     # MAKE SURE TO HAVE A CLEAN TEST ENVIRONMENT
     rmdir('@tests/.tests/')
     mkdir('@tests/.tests/')
     # INITIALIZED VARIABLES
     self.eddy = None
     self.project = None
     self.session = None
Exemple #9
0
    def accept(self):
        """
        Create Eddy workspace (if necessary).
        """
        path = self.workspaceField.value()

        try:
            mkdir(path)
        except Exception as e:
            msgbox = QtWidgets.QMessageBox(self)
            msgbox.setDetailedText(format_exception(e))
            msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48))
            msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
            msgbox.setText('{0} could not create the specified workspace: {1}!'.format(APPNAME, path))
            msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
            msgbox.setWindowTitle('Workspace setup failed!')
            msgbox.exec_()
            super().reject()
        else:
            settings = QtCore.QSettings(ORGANIZATION, APPNAME)
            settings.setValue('workspace/home', path)
            settings.sync()
            super().accept()
Exemple #10
0
 def make_dist(self):
     """
     Create 'dist' directory.
     """
     mkdir(self.dist_dir)
Exemple #11
0
    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
Exemple #12
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 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