Beispiel #1
0
    def createWorkspace(self, name, description=""):
        """Uses the instance of workspace manager passed into __init__ to
        get all the workspaces names and see if they don't clash with
        the one the user wrote. If everything's fine, it saves the new
        workspace and returns True. If something went wrong, return False"""

        if name in self.workspace_manager.getWorkspacesNames():
            error_str = "A workspace with name %s already exists" % name
            faraday.client.model.api.log(error_str, "ERROR")
            errorDialog(self.window, error_str)
            creation_ok = False
        else:
            faraday.client.model.api.log("Creating workspace '%s'" % name)
            faraday.client.model.api.devlog("Looking for the delegation class")
            manager = self.getWorkspaceManager()
            try:
                name = manager.createWorkspace(name, description)
                self.change_workspace(name)
                creation_ok = True
            except Exception as e:
                faraday.client.model.guiapi.notification_center.showDialog(
                    str(e))
                creation_ok = False

        return creation_ok
Beispiel #2
0
    def on_open_report_button(self, action, param):
        """What happens when the user clicks the open report button.
        A dialog will present itself with a combobox to select a plugin.
        Then a file chooser to select a report. The report will be processed
        with the selected plugin.
        """
        def select_plugin():
            """Creates a simple dialog with a combo box to select a plugin"""
            plugins_id = list(self.plugin_manager.getPlugins())
            plugins_id = sorted(plugins_id, key=lambda s: s.lower())
            dialog = Gtk.Dialog("Select plugin", self.window, 0)

            combo_box = Gtk.ComboBoxText()
            combo_box.set_wrap_width(3)
            for plugin_id in plugins_id:
                combo_box.append_text(plugin_id)
            combo_box.show()

            dialog.vbox.pack_start(combo_box, False, True, 10)

            dialog.add_button("Cancel", Gtk.ResponseType.DELETE_EVENT)
            dialog.add_button("OK", Gtk.ResponseType.ACCEPT)

            response = dialog.run()
            selected = combo_box.get_active_text()

            dialog.destroy()
            return response, selected

        def on_file_selected(plugin_id, report):
            """Send the plugin_id and the report file to be processed"""
            try:
                self.report_manager.sendReportToPluginById(plugin_id, report)
            except Unauthorized:
                self.show_normal_error("You are not authorized to write data "
                                       "to this workspace.")

        plugin_response, plugin_id = select_plugin()

        while plugin_response == Gtk.ResponseType.ACCEPT and plugin_id is None:
            # force user to select a plugin if he did not do it
            errorDialog(self.window,
                        "Please select a plugin to parse your report!")
            plugin_response, plugin_id = select_plugin()
        else:
            if plugin_response == Gtk.ResponseType.ACCEPT:
                dialog = Gtk.FileChooserDialog(
                    title="Import a report",
                    parent=self.window,
                    action=Gtk.FileChooserAction.OPEN,
                    buttons=("Open", Gtk.ResponseType.ACCEPT, "Cancel",
                             Gtk.ResponseType.CANCEL))
                dialog.set_modal(True)

                res = dialog.run()
                if res == Gtk.ResponseType.ACCEPT:
                    on_file_selected(plugin_id, dialog.get_filename())
                dialog.destroy()
Beispiel #3
0
    def connect_to_couch(self, server_url, parent=None):
        """Tries to connect to a CouchDB on a specified Couch URI.
        Returns the success status of the operation, False for not successful,
        True for successful
        """
        if parent is None:
            parent = self.window

        if not self.serverIO.check_server_url(server_url):
            errorDialog(parent, "Could not connect to Faraday Server.",
                        ("Are you sure it is running and that you can "
                         "connect to it? \n Make sure your username and "
                         "password are still valid."))
            success = False
        elif server_url.startswith("https://"):
            if not checkSSL(server_url):
                errorDialog(self.window,
                            "The SSL certificate validation has failed")
            success = False
        else:
            try:
                check_faraday_version()
            except RuntimeError:
                errorDialog(
                    parent,
                    "The server ir running a different Faraday version then the "
                    "client you are runnung. Version numbers must match!")
                success = False
                return success
            CONF.setAPIUrl(server_url)
            CONF.saveConfig()
            self.reload_workspaces()
            self.open_last_workspace()
            success = True
            self.lost_connection_dialog_raised = False
        return success