Esempio n. 1
0
 def test_rstrip(self):
     self.assertEqual('Pizza', rstrip('Pizza.graphol', '.graphol'))
     self.assertEqual('Pizza.graphol',
                      rstrip('Pizza.graphol', 'random_string'))
     self.assertEqual('Family', rstrip('Family.graphol', 'graphol', '.'))
     self.assertEqual('ThisIs',
                      rstrip('ThisIsATestMessage', 'Message', 'Test', 'A'))
Esempio n. 2
0
File: setup.py Progetto: jonntd/eddy
 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)
Esempio n. 3
0
 def import_plugin_from_zip(cls, archive):
     """
     Import a plugin from the given zip archive:
     * Lookup for the plugin .spec configuration file.
     * Search for the module where the plugin is implemented.
     * Search for the class implementing the plugin.
     * Import the plugin module.
     :type archive: str
     :rtype: tuple
     """
     if fexists(archive) and File.forPath(archive) is File.Zip:
         zf = ZipFile(archive)
         zf_name_list = zf.namelist()
         for file_or_directory in zf_name_list:
             if file_or_directory.endswith('plugin.spec'):
                 try:
                     #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 = PluginManager.spec(plugin_spec_content)
                     plugin_name = plugin_spec.get('plugin', 'id')
                     plugin_zip_base_path = rstrip(file_or_directory, 'plugin.spec')
                     plugin_abs_base_path = os.path.join(archive, plugin_zip_base_path)
                     plugin_zip_module_base_path = os.path.join(plugin_zip_base_path, plugin_name)
                     plugin_abs_module_base_path = os.path.join(archive, plugin_zip_module_base_path)
                     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))
                             plugin_module = zipimporter(plugin_abs_base_path).load_module(plugin_name)
                             plugin_class = PluginManager.find_class(plugin_module, plugin_name)
                             return plugin_spec, plugin_class
                     else:
                         raise PluginError('missing plugin module: %s.py(c|o)' % plugin_abs_module_base_path)
                 except Exception as e:
                     LOGGER.exception('Failed to import plugin: %s', e)
Esempio n. 4
0
 def import_reasoner_from_zip(cls, archive):
     """
     Import a reasoner from the given zip archive:
     * Lookup for the reasoner .spec configuration file.
     * Search for the module where the reasoner is implemented.
     * Search for the class implementing the reasoner.
     * Import the reasoner module.
     :type archive: str
     :rtype: tuple
     """
     if fexists(archive) and File.forPath(archive) is File.Zip:
         zf = ZipFile(archive)
         zf_name_list = zf.namelist()
         for file_or_directory in zf_name_list:
             if file_or_directory.endswith('reasoner.spec'):
                 try:
                     #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 = ReasonerManager.spec(reasoner_spec_content)
                     reasoner_name = reasoner_spec.get('reasoner', 'id')
                     reasoner_zip_base_path = rstrip(file_or_directory, 'reasoner.spec')
                     reasoner_abs_base_path = os.path.join(archive, reasoner_zip_base_path)
                     reasoner_zip_module_base_path = os.path.join(reasoner_zip_base_path, reasoner_name)
                     reasoner_abs_module_base_path = os.path.join(archive, reasoner_zip_module_base_path)
                     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))
                             reasoner_module = zipimporter(reasoner_abs_base_path).load_module(reasoner_name)
                             reasoner_class = ReasonerManager.find_class(reasoner_module, reasoner_name)
                             return reasoner_spec, reasoner_class
                     else:
                         raise ReasonerError('missing reasoner module: %s.py(c|o)' % reasoner_abs_module_base_path)
                 except Exception as e:
                     LOGGER.exception('Failed to import reasoner: %s', e)
Esempio n. 5
0
 def import_plugin_from_zip(self, archive):
     """
     Import a plugin from the given zip archive:
     * Lookup for the plugin .spec configuration file.
     * Search for the module where the plugin is implemented.
     * Search for the class implementing the plugin.
     * Import the plugin module.
     :type archive: str
     """
     if fexists(archive) and File.forPath(archive) is File.Zip:
         zf = ZipFile(archive)
         zf_name_list = zf.namelist()
         for file_or_directory in zf_name_list:
             if file_or_directory.endswith('plugin.spec'):
                 try:
                     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)
                     plugin_name = plugin_spec.get('plugin', 'id')
                     plugin_zip_base_path = rstrip(file_or_directory, 'plugin.spec')
                     plugin_abs_base_path = os.path.join(archive, plugin_zip_base_path)
                     plugin_zip_module_base_path = os.path.join(plugin_zip_base_path, plugin_name)
                     plugin_abs_module_base_path = os.path.join(archive, plugin_zip_module_base_path)
                     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))
                             plugin_module = zipimporter(plugin_abs_base_path).load_module(plugin_name)
                             plugin_class = self.find_class(plugin_module, plugin_name)
                             return plugin_spec, plugin_class
                     else:
                         raise PluginError('missing plugin module: %s.py(c|o)' % plugin_abs_module_base_path)
                 except Exception as e:
                     LOGGER.exception('Failed to import plugin: %s', e)
Esempio n. 6
0
 def childKey(diagram, node):
     """
     Returns the child key (text) used to place the given node in the treeview.
     :type diagram: Diagram
     :type node: TableNode
     :rtype: str
     """
     diagram = rstrip(diagram.name, File.Graphol.extension)
     return '[{0} - {1}] ({2})'.format(diagram, node.id,
                                       node.relationalTable.name)
Esempio n. 7
0
 def childKey(diagram, node):
     """
     Returns the child key (text) used to place the given node in the treeview.
     :type diagram: Diagram
     :type node: AbstractNode
     :rtype: str
     """
     predicate = node.text().replace('\n', '')
     diagram = rstrip(diagram.name, File.Graphol.extension)
     return '{0} ({1} - {2})'.format(predicate, diagram, node.id)
 def childKey(diagram, node):
     """
     Returns the child key (text) used to place the given node in the treeview.
     :type diagram: Diagram
     :type node: AbstractNode
     :rtype: str
     """
     predicate = node.text().replace('\n', '')
     diagram = rstrip(diagram.name, File.Graphol.extension)
     return '{0} ({1} - {2})'.format(predicate, diagram, node.id)
 def childKey(diagram, edge):
     """
     Returns the child key (text) used to place the given node in the treeview.
     :type diagram: Diagram
     :type edge: ForeignKeyEdge
     :rtype: str
     """
     diagram = rstrip(diagram.name, File.Graphol.extension)
     return '[{0} - {1}] ({2})'.format(diagram, edge.id,
                                       edge.foreignKey.name)
Esempio n. 10
0
    def createProject(self):
        """
        Create a new project.
        """
        self.nproject = Project(
            name=rstrip(os.path.basename(self.path), File.GraphML.extension),
            path=os.path.dirname(self.path),
            profile=self.session.createProfile('OWL 2'),
            session=self.session)

        LOGGER.debug('Created project: %s', self.nproject.name)
Esempio n. 11
0
    def childKey(diagram, node):
        """
        Returns the child key (text) used to place the given node in the treeview.
        :type diagram: Diagram
        :type node: AbstractNode
        :rtype: str
        """
        diagram = rstrip(diagram.name, File.Graphol.extension)

        if isinstance(node, (OntologyEntityNode, OntologyEntityResizableNode)):
            return '{0} - {1}'.format(diagram, node.id)
        else:
            predicate = node.text().replace('\n', '')
            return '{0} ({1} - {2})'.format(predicate, diagram, node.id)
Esempio n. 12
0
 def shortName(self):
     """
     Returns the item short name, i.e: attribute, concept.
     :rtype: str
     """
     return rstrip(self.realName, ' node', ' edge')
Esempio n. 13
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
Esempio n. 14
0
 def name(self):
     """
     Returns the name of the project.
     :rtype: str
     """
     return os.path.basename(rstrip(self.path, os.path.sep, os.path.altsep))
Esempio n. 15
0
    def createDiagram(self):
        """
        Creates a diagram and reverse the content of the GraphML document in it.
        """
        LOGGER.debug('Initializing empty diagram with size: %s', Diagram.MaxSize)
        name = os.path.basename(self.path)
        name = rstrip(name, File.GraphML.extension)
        self.diagram = Diagram.create(name, Diagram.MaxSize, self.nproject)

        root = self.document.documentElement()
        graph = root.firstChildElement('graph')
        e = graph.firstChildElement('node')
        while not e.isNull():
            try:
                QtWidgets.QApplication.processEvents()
                item = self.itemFromXmlNode(e)
                if not item:
                    raise DiagramParseError('could not identify item for XML node')
                func = self.importFuncForItem[item]
                node = func(e)
                if not node:
                    raise DiagramParseError('could not generate item for XML node')
            except DiagramParseError as err:
                LOGGER.warning('Failed to create node %s: %s', e.attribute('id'), err)
            except Exception:
                LOGGER.exception('Failed to create node %s', e.attribute('id'))
            else:
                self.diagram.addItem(node)
                self.diagram.guid.update(node.id)
                self.nodes[node.id] = node
            finally:
                e = e.nextSiblingElement('node')

        LOGGER.debug('Loaded nodes: %s', len(self.nodes))

        e = graph.firstChildElement('edge')
        while not e.isNull():
            try:
                QtWidgets.QApplication.processEvents()
                item = self.itemFromXmlNode(e)
                if not item:
                    raise DiagramParseError('could not identify item for XML node')
                func = self.importFuncForItem[item]
                edge = func(e)
                if not edge:
                    raise DiagramParseError('could not generate item for XML node')
            except DiagramParseError as err:
                LOGGER.warning('Failed to create edge %s: %s', e.attribute('id'), err)
            except Exception:
                LOGGER.exception('Failed to create edge %s', e.attribute('id'))
            else:
                self.diagram.addItem(edge)
                self.diagram.guid.update(edge.id)
                self.edges[edge.id] = edge
            finally:
                e = e.nextSiblingElement('edge')

        LOGGER.debug('Loaded edges: %s', len(self.edges))

        nodes = [n for n in self.nodes.values() if Identity.Neutral in n.identities()]
        if nodes:
            LOGGER.debug('Running identification algorithm for %s nodes', len(nodes))
            for node in nodes:
                QtWidgets.QApplication.processEvents()
                self.diagram.sgnNodeIdentification.emit(node)

        LOGGER.debug('Diagram created: %s', self.diagram.name)

        connect(self.diagram.sgnItemAdded, self.nproject.doAddItem)
        connect(self.diagram.sgnItemRemoved, self.nproject.doRemoveItem)
        connect(self.diagram.selectionChanged, self.session.doUpdateState)

        self.nproject.addDiagram(self.diagram)

        LOGGER.debug('Diagram "%s" added to project "%s"', self.diagram.name, self.nproject.name)
Esempio n. 16
0
    def __init__(self, parent=None):
        """
        Initialize the project dialog.
        :type parent: QWidget
        """
        super().__init__(parent)

        #############################################
        # FORM AREA
        #################################

        settings = QtCore.QSettings(ORGANIZATION, APPNAME)

        self.workspace = expandPath(
            settings.value('workspace/home', WORKSPACE, str))
        self.workspace = '{0}{1}'.format(rstrip(self.workspace, os.path.sep),
                                         os.path.sep)

        self.nameLabel = QtWidgets.QLabel(self)
        self.nameLabel.setFont(Font('Roboto', 12))
        self.nameLabel.setText('Name')
        self.nameField = StringField(self)
        self.nameField.setFont(Font('Roboto', 12))
        self.nameField.setMinimumWidth(400)
        self.nameField.setMaxLength(64)

        self.prefixLabel = QtWidgets.QLabel(self)
        self.prefixLabel.setFont(Font('Roboto', 12))
        self.prefixLabel.setText('Prefix')
        self.prefixField = StringField(self)
        self.prefixField.setFont(Font('Roboto', 12))
        self.prefixField.setMinimumWidth(400)

        self.iriLabel = QtWidgets.QLabel(self)
        self.iriLabel.setFont(Font('Roboto', 12))
        self.iriLabel.setText('IRI')
        self.iriField = StringField(self)
        self.iriField.setFont(Font('Roboto', 12))
        self.iriField.setMinimumWidth(400)

        connect(self.prefixField.textChanged, self.doAcceptForm)
        connect(self.iriField.textChanged, self.doAcceptForm)
        connect(self.nameField.textChanged, self.doAcceptForm)
        connect(self.nameField.textChanged, self.onNameFieldChanged)

        self.pathLabel = QtWidgets.QLabel(self)
        self.pathLabel.setFont(Font('Roboto', 12))
        self.pathLabel.setText('Location')
        self.pathField = StringField(self)
        self.pathField.setFont(Font('Roboto', 12))
        self.pathField.setMinimumWidth(400)
        self.pathField.setReadOnly(True)
        self.pathField.setFocusPolicy(QtCore.Qt.NoFocus)
        self.pathField.setValue(self.workspace)

        spacer = QtWidgets.QFrame()
        spacer.setFrameShape(QtWidgets.QFrame.HLine)
        spacer.setFrameShadow(QtWidgets.QFrame.Sunken)

        self.formWidget = QtWidgets.QWidget(self)
        self.formLayout = QtWidgets.QFormLayout(self.formWidget)
        self.formLayout.addRow(self.nameLabel, self.nameField)
        self.formLayout.addRow(self.prefixLabel, self.prefixField)
        self.formLayout.addRow(self.iriLabel, self.iriField)
        self.formLayout.addWidget(spacer)
        self.formLayout.addRow(self.pathLabel, self.pathField)

        #############################################
        # CONFIRMATION AREA
        #################################

        self.confirmationBox = QtWidgets.QDialogButtonBox(
            QtCore.Qt.Horizontal, self)
        self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Ok)
        self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Cancel)
        self.confirmationBox.setContentsMargins(10, 0, 10, 10)
        self.confirmationBox.setFont(Font('Roboto', 12))
        self.confirmationBox.button(
            QtWidgets.QDialogButtonBox.Ok).setEnabled(False)

        #############################################
        # SETUP DIALOG LAYOUT
        #################################

        self.caption = QtWidgets.QLabel(self)
        self.caption.setFont(Font('Roboto', 12))
        self.caption.setContentsMargins(8, 0, 8, 0)
        self.caption.setProperty('class', 'invalid')
        self.caption.setVisible(False)

        self.gridLayout = QtWidgets.QVBoxLayout(self)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.addWidget(self.formWidget)
        self.gridLayout.addWidget(self.caption)
        self.gridLayout.addWidget(self.confirmationBox, 0,
                                  QtCore.Qt.AlignRight)

        self.setFixedSize(self.sizeHint())
        self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
        self.setWindowTitle('New project')

        connect(self.confirmationBox.accepted, self.accept)
        connect(self.confirmationBox.rejected, self.reject)
Esempio n. 17
0
def test_rstrip():
    assert 'Pizza' == rstrip('Pizza.graphol', '.graphol')
    assert 'Pizza.graphol' == rstrip('Pizza.graphol', 'random_string')
    assert 'Family' == rstrip('Family.graphol', 'graphol', '.')
    assert 'ThisIs' == rstrip('ThisIsATestMessage', 'Message', 'Test', 'A')
Esempio n. 18
0
    def __init__(self, parent=None):
        """
        Initialize the project dialog.
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)

        #############################################
        # FORM AREA
        #################################

        settings = QtCore.QSettings(ORGANIZATION, APPNAME)

        self.workspace = expandPath(settings.value('workspace/home', WORKSPACE, str))
        self.workspace = '{0}{1}'.format(rstrip(self.workspace, os.path.sep), os.path.sep)

        self.nameLabel = QtWidgets.QLabel(self)
        self.nameLabel.setFont(Font('Roboto', 12))
        self.nameLabel.setText('Name')
        self.nameField = StringField(self)
        self.nameField.setFont(Font('Roboto', 12))
        self.nameField.setMinimumWidth(400)
        self.nameField.setMaxLength(64)
        connect(self.nameField.textChanged, self.onNameFieldChanged)

        self.prefixLabel = QtWidgets.QLabel(self)
        self.prefixLabel.setFont(Font('Roboto', 12))
        self.prefixLabel.setText('Prefix')
        self.prefixField = StringField(self)
        self.prefixField.setFont(Font('Roboto', 12))
        self.prefixField.setMinimumWidth(400)

        self.iriLabel = QtWidgets.QLabel(self)
        self.iriLabel.setFont(Font('Roboto', 12))
        self.iriLabel.setText('IRI')
        self.iriField = StringField(self)
        self.iriField.setFont(Font('Roboto', 12))
        self.iriField.setMinimumWidth(400)

        connect(self.iriField.textChanged, self.doProjectPathValidate)
        connect(self.nameField.textChanged, self.doProjectPathValidate)
        connect(self.prefixField.textChanged, self.doProjectPathValidate)

        self.pathLabel = QtWidgets.QLabel(self)
        self.pathLabel.setFont(Font('Roboto', 12))
        self.pathLabel.setText('Location')
        self.pathField = StringField(self)
        self.pathField.setFont(Font('Roboto', 12))
        self.pathField.setMinimumWidth(400)
        self.pathField.setReadOnly(True)
        self.pathField.setFocusPolicy(QtCore.Qt.NoFocus)
        self.pathField.setValue(self.workspace)

        spacer = QtWidgets.QFrame()
        spacer.setFrameShape(QtWidgets.QFrame.HLine)
        spacer.setFrameShadow(QtWidgets.QFrame.Sunken)

        self.formWidget = QtWidgets.QWidget(self)
        self.formLayout = QtWidgets.QFormLayout(self.formWidget)
        self.formLayout.addRow(self.nameLabel, self.nameField)
        self.formLayout.addRow(self.prefixLabel, self.prefixField)
        self.formLayout.addRow(self.iriLabel, self.iriField)
        self.formLayout.addWidget(spacer)
        self.formLayout.addRow(self.pathLabel, self.pathField)

        #############################################
        # CONFIRMATION AREA
        #################################

        self.confirmationBox = QtWidgets.QDialogButtonBox(QtCore.Qt.Horizontal, self)
        self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Ok)
        self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Cancel)
        self.confirmationBox.setContentsMargins(10, 0, 10, 10)
        self.confirmationBox.setFont(Font('Roboto', 12))
        self.confirmationBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)

        #############################################
        # SETUP DIALOG LAYOUT
        #################################

        self.caption = QtWidgets.QLabel(self)
        self.caption.setFont(Font('Roboto', 12))
        self.caption.setContentsMargins(8, 0, 8, 0)
        self.caption.setProperty('class', 'invalid')
        self.caption.setVisible(False)

        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.addWidget(self.formWidget)
        self.mainLayout.addWidget(self.caption)
        self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight)

        self.setFixedSize(self.sizeHint())
        self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
        self.setWindowTitle('New project')

        connect(self.confirmationBox.accepted, self.accept)
        connect(self.confirmationBox.rejected, self.reject)
Esempio n. 19
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
Esempio n. 20
0
 def shortName(self):
     """
     Returns the item short name, i.e: attribute, concept.
     :rtype: str
     """
     return rstrip(self.realName, ' node', ' edge')
Esempio n. 21
0
 def test_rstrip(self):
     self.assertEqual('Pizza', rstrip('Pizza.graphol', '.graphol'))
     self.assertEqual('Pizza.graphol', rstrip('Pizza.graphol', 'random_string'))
     self.assertEqual('Family', rstrip('Family.graphol', 'graphol', '.'))
     self.assertEqual('ThisIs', rstrip('ThisIsATestMessage', 'Message', 'Test', 'A'))