Ejemplo n.º 1
0
    def on_db_popup(self, popup, item):
        """
        :param popup:
        :param item:
        :return:
        """
        path, column = self.get_cursor()
        _iter = self.connections_model.get_iter(path)
        what = item.name
        db = self.connections_model.get_value(_iter, 0)

        if what == "refresh_database":
            new_tables = db.refresh()
            self.redraw_db(db, _iter, new_tables)
        elif what == "drop_database":
            hostname = db.host.name.replace('&', '&')
            dbname = db.name.replace('&', '&')
            if not dialogs.confirm(
                    "drop database",
                    "do you really want to drop the <b>%s</b> "
                    "database on <b>%s</b>?" %
                (dbname, hostname), self.emma.mainwindow):
                return
            host = db.host
            if host.query("drop database`%s`" % db.name, False, True):
                host.refresh()
                self.redraw_host(host,
                                 self.emma.connections_tv.get_host_iter(host))
        elif what == "new_table":
            name = dialogs.input_dialog(
                "New table",
                "Please enter the name of the new table:",
                window=self.emma.mainwindow)
            if not name:
                return
            if db.query(
                    "create table `%s` (`%s_id` int primary key auto_increment)"
                    % (name, name)):
                new_tables = db.refresh()
                self.redraw_db(db, self.emma.connections_tv.get_db_iter(db),
                               new_tables)
        elif what == "check_tables":
            self.current_host = db.host
            self.current_host.select_database(db)
            db.refresh()
            self.emma.events.trigger(
                'execute_query', None, "check table %s" %
                (",".join(map(lambda s: "`%s`" % s, db.tables.keys()))))
        elif what == "repair_tables":
            self.current_host = db.host
            self.current_host.select_database(db)
            db.refresh()
            self.emma.events.trigger(
                'execute_query', None, "repair table %s" %
                (",".join(map(lambda s: "`%s`" % s, db.tables.keys()))))
        elif what == "list_tables":
            self.emma.main_notebook.add_tables_list_tab()
Ejemplo n.º 2
0
 def on_rename_query_tab_clicked(self, button):
     label = self.get_label()
     new_name = dialogs.input_dialog(
         "Rename tab", "Please enter the new name of this tab:",
         label.get_text(), self.emma.mainwindow)
     if new_name is None:
         return
     if new_name == "":
         self.last_auto_name = None
         self.update_db_label()
         return
     self.user_rename(new_name)
Ejemplo n.º 3
0
        def callback_on_button_click(**kwargs):
            def on_press(text_button):
                # TODO: добавить группу в словарь groups.ini.
                field.dismiss()
                toast(str(text_button))

            field = input_dialog(
                title=kwargs['title'],
                hint_text='',
                text_button_ok=self.translation._('Добавить'),
                text_button_cancel=self.translation._('Отмена'),
                events_callback=on_press)
Ejemplo n.º 4
0
 def on_rename_query_tab_clicked(self, button):
     label = self.get_label()
     new_name = dialogs.input_dialog(
         "Rename tab", "Please enter the new name of this tab:", label.get_text(), self.emma.mainwindow
     )
     if new_name is None:
         return
     if new_name == "":
         self.last_auto_name = None
         self.update_db_label()
         return
     self.user_rename(new_name)
Ejemplo n.º 5
0
    def on_host_popup(self, popup, item):
        """
        :param popup:
        :param item:
        :return:
        """
        path, column = self.get_cursor()
        if path:
            _iter = self.connections_model.get_iter(path)
            host = self.connections_model.get_value(_iter, 0)
        else:
            _iter = None
            host = None
        what = item.name

        if what == "refresh_host":
            host.refresh()
            self.redraw_host(host, _iter)
        elif what == "new_database":
            name = dialogs.input_dialog(
                "New database",
                "Please enter the name of the new database:",
                window=self.emma.mainwindow)
            if not name:
                return
            if host.query("Create database `%s`" % name):
                host.refresh()
                self.redraw_host(host, _iter)
        elif what == "modify_connection":
            self.connection_window.host = host
            self.connection_window.show("edit")
        elif what == "delete_connection":
            hostname = host.name.replace('&', '&amp;')
            if not dialogs.confirm(
                    "Delete host",
                    "Do you really want to drop the host <b>%s</b>?" %
                    hostname, self.emma.mainwindow):
                return
            host.close()
            self.connections_model.remove(_iter)
            if self.current_host == host:
                self.current_host = None
            del self.emma.config.config["connection_%s" % host.name]
            del host
            self.emma.config.save()
        elif what == "new_connection":
            self.connection_window.show("new")
        elif what == "show_processes":
            self.emma.main_notebook.add_process_list_tab(host)
Ejemplo n.º 6
0
    def on_db_popup(self, popup, item):
        path, column = self.get_cursor()
        _iter = self.connections_model.get_iter(path)
        what = item.name
        db = self.connections_model.get_value(_iter, 0)

        if what == "refresh_database":
            new_tables = db.refresh()
            self.redraw_db(db, _iter, new_tables)
        elif what == "drop_database":
            if not dialogs.confirm("drop database",
                                   "do you really want to drop the <b>%s</b> database on <b>%s</b>?" % (
                                   db.name, db.host.name), self.emma.mainwindow):
                return
            host = db.host
            if host.query("drop database`%s`" % db.name):
                host.refresh()
                self.redraw_host(host, self.emma.connections_tv.get_host_iter(host))
        elif what == "new_table":
            name = dialogs.input_dialog("New table", "Please enter the name of the new table:",
                                        window=self.emma.mainwindow)
            if not name:
                return
            if db.query("create table `%s` (`%s_id` int primary key auto_increment)" % (name, name)):
                new_tables = db.refresh()
                self.redraw_db(db, self.emma.connections_tv.get_db_iter(db), new_tables)
        elif what == "check_tables":
            self.current_host = db.host
            self.current_host.select_database(db)
            self.emma.current_query.on_execute_query_clicked(
                None,
                "check table %s" % (",".join(map(lambda s: "`%s`" % s, db.tables.keys()))))
        elif what == "repair_tables":
            self.current_host = db.host
            self.current_host.select_database(db)
            self.emma.current_query.on_execute_query_clicked(
                None,
                "repair table %s" % (",".join(map(lambda s: "`%s`" % s, db.tables.keys()))))
        elif what == "list_tables":
            self.emma.main_notebook.add_tables_list_tab()
Ejemplo n.º 7
0
    def on_host_popup(self, popup, item):
        path, column = self.get_cursor()
        if path:
            _iter = self.connections_model.get_iter(path)
            host = self.connections_model.get_value(_iter, 0)
        else:
            _iter = None
            host = None
        what = item.name

        if what == "refresh_host":
            host.refresh()
            self.redraw_host(host, _iter)
        elif what == "new_database":
            name = dialogs.input_dialog("New database", "Please enter the name of the new database:",
                                        window=self.emma.mainwindow)
            if not name:
                return
            if host.query("Create database `%s`" % name):
                host.refresh()
                self.redraw_host(host, _iter)
        elif what == "modify_connection":
            self.connection_window.host = host
            self.connection_window.show("edit")
        elif what == "delete_connection":
            if not dialogs.confirm("Delete host", "Do you really want to drop the host <b>%s</b>?" % host.name,
                                   self.emma.mainwindow):
                return
            host.close()
            self.connections_model.remove(_iter)
            if self.current_host == host:
                self.current_host = None
            del self.emma.config.config["connection_%s" % host.name]
            del host
            self.emma.config.save()
        elif what == "new_connection":
            self.connection_window.show("new")
        elif what == "show_processes":
            self.emma.main_notebook.add_process_list_tab(host)
Ejemplo n.º 8
0
    def on_save_result_sql_clicked(self, button):
        title = "save results as sql insert script"
        d = self.emma.assign_once(
            "save results dialog",
            gtk.FileChooserDialog, title, self.emma.mainwindow, gtk.FILE_CHOOSER_ACTION_SAVE,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))

        d.set_default_response(gtk.RESPONSE_ACCEPT)
        answer = d.run()
        d.hide()
        if not answer == gtk.RESPONSE_ACCEPT:
            return
        filename = d.get_filename()
        if os.path.exists(filename):
            if not os.path.isfile(filename):
                dialogs.show_message(title, "%s already exists and is not a file!" % filename)
                return
            if not dialogs.confirm(
                    "overwrite file?",
                    "%s already exists! do you want to overwrite it?" % filename, self.emma.mainwindow):
                return
        q = self.query
        _iter = q.model.get_iter_first()
        indices = range(q.model.get_n_columns())

        # try to guess target table name from query
        table_name = ""
        query = self.query.last_source
        result = is_query_appendable(query)
        if result:
            table_list = result.group(7)
            table_list = table_list.replace(" join ", ",")
            table_list = re.sub("(?i)(?:order[ \t\r\n]by.*|limit.*|group[ \r\n\t]by.*|order[ \r\n\t]by.*|where.*)", "",
                                table_list)
            table_list = table_list.replace("`", "")
            tables = map(lambda s: s.strip(), table_list.split(","))
            table_name = "_".join(tables)
        table_name = dialogs.input_dialog(title, "Please enter the name of the target table:", table_name,
                                          self.emma.mainwindow)
        if table_name is None:
            return
        table_name = self.emma.current_host.escape_table(table_name)

        output_row = None
        try:
            fp = file(filename, "wb")
            fp.write("insert into %s values" % table_name)
            row_delim = "\n\t"
            while _iter:
                row = q.model.get(_iter, *indices)
                if not output_row:
                    output_row = range(len(row))
                for i, field in enumerate(row):
                    if field is None:
                        field = "NULL"
                    elif not field.isdigit():
                        field = "'%s'" % q.current_host.escape(field.encode(q.encoding))
                    output_row[i] = field
                fp.write("%s(%s)" % (row_delim, ",".join(output_row)))
                row_delim = ",\n\t"
                _iter = q.model.iter_next(_iter)
            fp.write("\n;\n")
            fp.close()
        except:
            dialogs.show_message(title, "error writing to file %s: %s" % (filename, sys.exc_value))