def copyInsertTemplateToClipboard(table): code = "INSERT INTO `" + table.owner.name + "`.`" + table.name + "` (" first = 1 for col in table.columns: if first == 0: code += "`, `" + col.name else: code += "`" + col.name first = 0 code += "`) VALUES (" first = 1 for col in table.columns: if first == 0: code += ", " + "NULL" else: code += "NULL" first = 0 code += ");" grt.modules.Workbench.copyToClipboard(code) App.get().set_status_text("Ready") return 0
def handle_on_close(self): App.get().set_status_text("Closing Administator.") self.configuration.shutdown() if not self.configuration.closing: return False self.ctrl_be.shutdown() tab_references.remove(self) self.release() return True
def handle_on_close(self): App.get().set_status_text("Closing Administator.") self.shutdown() if not self.closing: return False self.ctrl_be.shutdown() self.release() self.owner.handle_close() return True
def copyInsertToClipboard(table): inserts = table.inserts() if inserts != "": grt.modules.Workbench.copyToClipboard(table.inserts()) App.get().set_status_text("Ready") else: App.get().set_status_text("The table " + table.owner.name + "." + table.name + " has no records for insert statements") return 0
def do_open_administrator(server_instance): validate_setting( server_instance.serverInfo, "sys.usesudo", norm_to_switch, None ) # "Server profile has no indication of sudo usage") validate_setting(server_instance.serverInfo, "sys.usesudostatus", norm_to_switch, None) if server_instance.serverInfo["sys.system"] != "Windows": # validate_setting(server_instance.serverInfo, "sys.sudo", make_str_existing, "Server profile has no privileges elevation command defined") # if server_instance.serverInfo.has_key("sys.sudo") and server_instance.serverInfo["sys.sudo"].strip(" \r\t\n") == "": # Utilities.show_warning("WB Administrator", "Server profile has empty privileges elevation command defined. Some functionality maybe unavailable", "OK", "", "") try: if not server_instance.serverInfo["sys.sudo"]: # don't break settings that were working perfectly before, assume a valid default server_instance.serverInfo["sys.sudo"] = "/usr/bin/sudo -p EnterPasswordHere /bin/bash -c" except: server_instance.serverInfo["sys.sudo"] = "/usr/bin/sudo -p EnterPasswordHere /bin/bash -c" app = App.get() try: adminTab = AdministratorTab(server_instance) except wb_admin_ssh.ConnectionError, exc: Utilities.show_error( "Error Connecting to Server (%s@%s)" % (server_instance.loginInfo["ssh.userName"], server_instance.loginInfo["ssh.hostName"]), str(exc), "OK", "", "", ) app.set_status_text("Could not Open WB Admin") return None
def handle_on_close(self): log_debug("Closing admin\n") if self._timeout_tm: Utilities.cancel_timeout(self._timeout_tm) self._timeout_tm = None nc.remove_observer(self.handle_server_state_changed) App.get().set_status_text("Closing Administator.") self.shutdown() if not self.closing: log_debug("Admin close cancelled\n") return False self.ctrl_be.shutdown() self.release() self.owner.handle_close() return True
def __init__(self, ctrl_be, server_profile, running, cpu_widget, mem_widget): self.mtx = threading.Lock() self.cpu = 0 self.mem = 0 self.running = running self.cpu_widget = cpu_widget self.mem_widget = mem_widget self.ctrl_be = ctrl_be script_path = App.get().get_resource_path("mysql_system_status.vbs") self.read_thread = threading.Thread(target=self.read_from_script) self.read_thread.setDaemon(True) self.ctrl_be.add_me_for_event("shutdown", self) su = subprocess.STARTUPINFO() su.dwFlags |= _subprocess.STARTF_USESHOWWINDOW su.wShowWindow = _subprocess.SW_HIDE self.ch = subprocess.Popen("cscript //NoLogo " + script_path + " /DoStdIn", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=su) self.read_thread.start()
def do_open_administrator(server_instance): validate_setting(server_instance.serverInfo, "sys.usesudo", norm_to_switch, None) #"Server profile has no indication of sudo usage") validate_setting(server_instance.serverInfo, "sys.usesudostatus", norm_to_switch, None) if server_instance.serverInfo["sys.system"] != "Windows": #validate_setting(server_instance.serverInfo, "sys.sudo", make_str_existing, "Server profile has no privileges elevation command defined") #if server_instance.serverInfo.has_key("sys.sudo") and server_instance.serverInfo["sys.sudo"].strip(" \r\t\n") == "": # Utilities.show_warning("WB Administrator", "Server profile has empty privileges elevation command defined. Some functionality maybe unavailable", "OK", "", "") try: if not server_instance.serverInfo["sys.sudo"]: # don't break settings that were working perfectly before, assume a valid default server_instance.serverInfo[ "sys.sudo"] = "/usr/bin/sudo -p EnterPasswordHere /bin/bash -c" except: server_instance.serverInfo[ "sys.sudo"] = "/usr/bin/sudo -p EnterPasswordHere /bin/bash -c" app = App.get() try: adminTab = AdministratorTab(server_instance) except wb_admin_ssh.ConnectionError, exc: Utilities.show_error( "Error Connecting to Server (%s@%s)" % (server_instance.loginInfo["ssh.userName"], server_instance.loginInfo["ssh.hostName"]), str(exc), "OK", "", "") app.set_status_text("Could not Open WB Admin") return None
def openDocLib(): global docLibTab global server_port if docLibTab: if docLibTab is True: # this will be True if an external browser is used Utilities.open_url("http://localhost:%i"%server_port) return 1 App.get().select_view("wb.doclib") return 1 app = App.get() try: import mysqldoclib except ImportError: Utilities.show_error("Cannot Open Documentation Library", '''pysqlite2 is not installed, please install python-sqlite2 or pysqlite2 to be able to use this feature. Try running "easy_install pysqlite" with superuser privileges in the command line shell or, if using Ubuntu, enable the Universe repository and install the python-pysqlite2 package from there.''', "OK", "", "") return 0 if server_port is None: ready_event = Event() #datadir = "./modules/data/DocLibrary/" datadir = os.path.join(app.get_resource_path(""), "modules/data/DocLibrary") thread.start_new_thread(run_server, (datadir, ready_event)) # wait up to 1s for the doclib server to start ready_event.wait(1) if platform.system() == "Linux": docLibTab = True Utilities.open_url("http://localhost:%i"%server_port) return 1 docLibTab = DocLibTab(server_port) docLibTab.set_identifier("wb.doclib") app.dock_view(docLibTab, "maintab") app.set_view_title(docLibTab, "Doc Library (loading)") app.set_status_text("Opening Doc Library...") return 1
def openDocLib(): global docLibTab global server_port if docLibTab: if docLibTab is True: # this will be True if an external browser is used Utilities.open_url("http://localhost:%i" % server_port) return 1 App.get().select_view("wb.doclib") return 1 app = App.get() try: import mysqldoclib except ImportError: Utilities.show_error( "Cannot Open Documentation Library", "pysqlite2 is not installed, please install python-sqlite2 or pysqlite2 to be able to use this feature.", "OK", "", "") return 0 if server_port is None: ready_event = Event() #datadir = "./modules/data/DocLibrary/" datadir = os.path.join(app.get_resource_path(""), "modules/data/DocLibrary") thread.start_new_thread(run_server, (datadir, ready_event)) # wait up to 1s for the doclib server to start ready_event.wait(1) if platform.system() == "Linux": docLibTab = True Utilities.open_url("http://localhost:%i" % server_port) return 1 docLibTab = DocLibTab(server_port) docLibTab.set_identifier("wb.doclib") app.dock_view(docLibTab, "maintab") app.set_view_title(docLibTab, "Doc Library (loading)") app.set_status_text("Opening Doc Library...") return 1
def openDocLib(): global docLibTab global server_port app = App.get() # if docs datafiles are not installed, just open the docs home page datafile = os.path.join(app.get_resource_path(""), "modules/data/DocLibrary/mysqldoclib.sqlite") if not os.path.exists(datafile): Utilities.open_url("http://dev.mysql.com/doc/") return 1 if docLibTab: if docLibTab is True: # this will be True if an external browser is used Utilities.open_url("http://localhost:%i" % server_port) return 1 app.select_view(docLibTab) return 1 try: import mysqldoclib except ImportError: Utilities.show_error( "Cannot Open Documentation Library", '''pysqlite2 is not installed, please install python-sqlite2 or pysqlite2 to be able to use this feature. Try running "easy_install pysqlite" with superuser privileges in the command line shell or, if using Ubuntu, enable the Universe repository and install the python-pysqlite2 package from there.''', "OK", "", "") return 0 if server_port is None: ready_event = Event() #datadir = "./modules/data/DocLibrary/" datadir = os.path.join(app.get_resource_path(""), "modules/data/DocLibrary") thread.start_new_thread(run_server, (datadir, ready_event)) # wait up to 1s for the doclib server to start ready_event.wait(1) if platform.system() == "Linux": docLibTab = True Utilities.open_url("http://localhost:%i" % server_port) return 1 docLibTab = DocLibTab(server_port) docLibTab.set_identifier("wb.doclib") app.dock_view(docLibTab, "maintab") app.set_view_title(docLibTab, "Doc Library (loading)") app.set_status_text("Opening Doc Library...") return 1
def __init__(self, ctrl_be, server_profile, running, cpu_widget, mem_widget): self.mtx = threading.Lock() self.cpu = 0 self.mem = 0 self.running = running self.cpu_widget = cpu_widget self.mem_widget = mem_widget self.ctrl_be = ctrl_be script_path = App.get().get_resource_path("mysql_system_status.vbs") self.read_thread = threading.Thread(target=self.read_from_script) self.read_thread.setDaemon(True) self.ctrl_be.add_me_for_event("shutdown", self) su = subprocess.STARTUPINFO() su.dwFlags |= _subprocess.STARTF_USESHOWWINDOW su.wShowWindow = _subprocess.SW_HIDE self.ch = subprocess.Popen("cscript //NoLogo " + script_path + " /DoStdIn", stdin = subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=su) self.read_thread.start()
def handle_on_close(self): global docLibTab App.get().set_status_text("Closed Doc Library") docLibTab = None return True
def __init__(self, ctrl_be, server_profile, running, cpu_widget, mem_widget): self.ctrl_be = ctrl_be self.ssh = None self.cpu = 0 self.mem = 0 self.mtx = threading.Lock() self.running = running self.cpu_widget = cpu_widget self.mem_widget = mem_widget self.settings = server_profile self.remote_admin_enabled = self.settings.uses_ssh if not self.remote_admin_enabled: return self.ctrl_be.add_me_for_event("shutdown", self) #upload script. Get local name, open ftp session and upload to the directory # where mysql.ini is. self.script = None self.ssh = ctrl_be.open_ssh_session_for_monitoring() (dirpath, code) = self.ssh.exec_cmd("cmd /C echo %USERPROFILE%") # %APPDATA% is n/a for LocalService # which is a user sshd can be run dirpath = dirpath.strip(" \r\t\n") if code == 0 and dirpath is not None and dirpath != "%USERPROFILE%": script_path = App.get().get_resource_path("mysql_system_status_rmt.vbs") filename = "\"" + dirpath + "\\mysql_system_status_rmt.vbs\"" dprint_ex(1, "script local path is ", script_path, ". Will be uploaded to", filename) if script_path is not None and script_path != "": #print "Uploading file to ", filename try: f = open(script_path) self.ssh.exec_cmd("cmd /C echo. > " + filename) maxsize = 1800 cmd = "" for line in f: line = line.strip("\r\n") tline = line.strip(" \t") if len(tline) > 0: if tline[0] != "'": if len(cmd) > maxsize: self.ssh.exec_cmd("cmd /C " + cmd.strip(" &")) self.ssh.exec_cmd("cmd /C echo " + line + " >> " + filename) cmd = "" else: cmd += "echo " + line + " >> " + filename cmd += " && " if len(cmd) > 0: self.ssh.exec_cmd("cmd /C " + cmd.strip(" &")) cmd = "" self.script = "cscript //NoLogo " + filename + " /DoStdIn" #run ssh in a thread dprint_ex(2, "About to run", self.script) self.chan = None self.out = "" self.read_thread = threading.Thread(target=self.ssh.exec_cmd, args=(self.script, 0, None, self.reader, 1, self.save_channel)) self.read_thread.setDaemon(True) self.read_thread.start() except IOError, e: self.ssh.close() self.ssh = None raise e
def __init__(self, owner): mforms.Box.__init__(self, True) self.set_managed() self.owner = owner self._selected_user = None self._selected_user_original = None self.suspend_layout() self.set_spacing(8) self.set_padding(8) schema_list_box = newBox(False) schema_list_box.set_spacing(8) schema_list_box.set_size(150, -1) self.add(schema_list_box, False, True) #searchbox = TextEntry(SearchEntry) #schema_list_box.add(searchbox, False, True) self.user_list = newTreeView(mforms.TreeDefault) self.user_list.add_column(mforms.StringColumnType, "Users", 140, False) self.user_list.end_columns() self.user_list.add_changed_callback(self.user_selected) self.user_list.set_allow_sorting(True) schema_list_box.add(self.user_list, True, True) self.schema_rights_checks = {} self.content_box = priv_vbox = newBox(False) priv_vbox.set_spacing(8) self.add(priv_vbox, True, True) priv_vbox.add( newLabel( "Select a user and pick the privileges it has for a given Schema and Host combination." ), False, True) self.privs_list = newTreeView(mforms.TreeDefault) self.privs_list.add_column(mforms.StringColumnType, "Host", 100, True) self.privs_list.add_column(mforms.StringColumnType, "Schema", 100, True) self.privs_list.add_column(mforms.StringColumnType, "Privileges", 800, False) self.privs_list.end_columns() self.privs_list.add_changed_callback(self.schema_priv_selected) priv_vbox.add(self.privs_list, True, True) bbox = newBox(True) bbox.set_spacing(8) bbox.add( dLabel( "Schema and Host fields may use % and _ wildcards. The server will match specific entries before wildcarded ones." ), False, True) self.add_entry_button = newButton() self.add_entry_button.set_text("Add Entry...") bbox.add_end(self.add_entry_button, False, True) self.add_entry_button.add_clicked_callback(self.add_entry) self.del_entry_button = newButton() self.del_entry_button.set_text("Delete Entry") bbox.add_end(self.del_entry_button, False, True) self.del_entry_button.add_clicked_callback(self.del_entry) priv_vbox.add(bbox, False, True) self.schema_priv_label = newLabel("") priv_vbox.add(self.schema_priv_label, False, True) hbox = newBox(True) hbox.set_homogeneous(True) hbox.set_spacing(8) priv_vbox.add(hbox, False, True) self.schema_object_privs_panel = panel = newPanel( mforms.TitledBoxPanel) panel.set_title("Object Rights") box = newBox(False) box.set_padding(8) for name in SCHEMA_OBJECT_RIGHTS: cb = newCheckBox() label, desc = PrivilegeInfo.get(name, ("", None)) cb.set_text(label) if desc: cb.set_tooltip(desc) cb.add_clicked_callback(self.schema_priv_checked) box.add(cb, False, False) self.schema_rights_checks[name] = cb panel.add(box) hbox.add(panel, False, True) self.schema_ddl_privs_panel = panel = newPanel(mforms.TitledBoxPanel) panel.set_title("DDL Rights") box = newBox(False) box.set_padding(8) for name in SCHEMA_DDL_RIGHTS: cb = newCheckBox() label, desc = PrivilegeInfo.get(name, ("", None)) cb.set_text(label) if desc: cb.set_tooltip(desc) cb.add_clicked_callback(self.schema_priv_checked) box.add(cb, False, False) self.schema_rights_checks[name] = cb panel.add(box) hbox.add(panel, False, True) self.schema_other_privs_panel = panel = newPanel(mforms.TitledBoxPanel) panel.set_title("Other Rights") box = newBox(False) box.set_padding(8) for name in SCHEMA_OTHER_RIGHTS: cb = newCheckBox() label, desc = PrivilegeInfo.get(name, ("", None)) cb.set_text(label) if desc: cb.set_tooltip(desc) cb.add_clicked_callback(self.schema_priv_checked) box.add(cb, False, False) self.schema_rights_checks[name] = cb panel.add(box) hbox.add(panel, False, True) bottom_box = newBox(True) bottom_box.set_spacing(8) if 0: img = newImageBox() if App.get().get_resource_path("task_warning_mac.png"): img.set_image("task_warning_mac.png") else: img.set_image("task_warning.png") bottom_box.add(img, False, True) bottom_box.add( dLabel( "There are %i schema privilege entries for accounts that don't exist" ), False, True) purge = newButton() purge.set_text("Purge") bottom_box.add(purge, False, True) self.grant_all = newButton() self.grant_all.set_text('Select "ALL"') bottom_box.add(self.grant_all, False, True) self.grant_all.add_clicked_callback(self.grant_all_schema_privs) self.revoke_all = newButton() self.revoke_all.set_text("Unselect All") bottom_box.add(self.revoke_all, False, True) self.revoke_all.add_clicked_callback(self.revoke_all_schema_privs) self.save_button = newButton() self.save_button.set_text("Save Changes") bottom_box.add_end(self.save_button, False, True) self.save_button.add_clicked_callback(self.commit) self.revert_button = newButton() self.revert_button.set_text("Revert") bottom_box.add_end(self.revert_button, False, True) self.revert_button.add_clicked_callback(self.revert) priv_vbox.add(bottom_box, False, True) self.resume_layout()
def loaded(self, url): App.get().set_view_title(self, "Doc Library") App.get().set_status_text("Doc Library Opened")
def __init__(self, ctrl_be, server_profile, running, cpu_widget): self.ctrl_be = ctrl_be self.ssh = None self.cpu = 0 self.mtx = threading.Lock() self.running = running self.cpu_widget = cpu_widget self.settings = server_profile self.remote_admin_enabled = self.settings.uses_ssh if not self.remote_admin_enabled: return self.ctrl_be.add_me_for_event("shutdown", self) #upload script. Get local name, open ftp session and upload to the directory # where mysql.ini is. self.script = None self.ssh = ctrl_be.open_ssh_session_for_monitoring() (dirpath, code) = self.ssh.exec_cmd("cmd /C echo %USERPROFILE%") # %APPDATA% is n/a for LocalService # which is a user sshd can be run dirpath = dirpath.strip(" \r\t\n") if code == 0 and dirpath is not None and dirpath != "%USERPROFILE%": script_path = App.get().get_resource_path("mysql_system_status_rmt.vbs") filename = "\"" + dirpath + "\\mysql_system_status_rmt.vbs\"" log_debug('%s:%s.__init__()' % (_this_file, self.__class__.__name__), 'Script local path is "%s". Will be uploaded to "%s"\n' % (script_path, filename) ) if script_path is not None and script_path != "": #print "Uploading file to ", filename try: f = open(script_path) self.ssh.exec_cmd("cmd /C echo. > " + filename) maxsize = 1800 cmd = "" for line in f: line = line.strip("\r\n") tline = line.strip(" \t") if len(tline) > 0: if tline[0] != "'": if len(cmd) > maxsize: self.ssh.exec_cmd("cmd /C " + cmd.strip(" &")) self.ssh.exec_cmd("cmd /C echo " + line + " >> " + filename) cmd = "" else: cmd += "echo " + line + " >> " + filename cmd += " && " if len(cmd) > 0: self.ssh.exec_cmd("cmd /C " + cmd.strip(" &")) cmd = "" self.script = "cscript //NoLogo " + filename + " /DoStdIn" #run ssh in a thread log_debug2('%s:%s.__init__()' % (_this_file, self.__class__.__name__), 'About to run "%s"\n' % self.script) self.chan = None self.out = "" self.read_thread = threading.Thread(target=self.ssh.exec_cmd, args=(self.script, Users.CURRENT, None, self.reader, 1, self.save_channel)) self.read_thread.setDaemon(True) self.read_thread.start() except IOError, e: self.ssh.close() self.ssh = None raise e
def handle_on_close(self): App.get().set_status_text("Closing Administator.") self.configuration.shutdown() self.ctrl_be.shutdown() tab_references.remove(self) return True
def __init__(self, ctrl_be, server_profile, running, cpu_widget): self.ctrl_be = ctrl_be self.ssh = None self.cpu = 0 self.mtx = threading.Lock() self.running = running self.cpu_widget = cpu_widget self.settings = server_profile self.remote_admin_enabled = self.settings.uses_ssh if not self.remote_admin_enabled: return self.ctrl_be.add_me_for_event("shutdown", self) #upload script. Get local name, open ftp session and upload to the directory # where mysql.ini is. self.script = None if self.ctrl_be.server_profile.uses_ssh: if self.ctrl_be.editor.sshConnection.isConnected() == 0: if self.ctrl_be.editor.sshConnection.connect() != 0: raise OperationCancelledError("Could not connect to SSH server") self.ssh = sshConnection if self.ssh is not None: # %APPDATA% is n/a for LocalService # which is a user sshd can be run dirpath = handle_ssh_command_output(self.ssh.executeCommand("cmd /C echo %USERPROFILE%")) dirpath = dirpath.strip(" \r\t\n") if dirpath is not None and dirpath != "%USERPROFILE%": script_path = App.get().get_resource_path("mysql_system_status_rmt.vbs") filename = "\"" + dirpath + "\\mysql_system_status_rmt.vbs\"" log_debug('Script local path is "%s". Will be uploaded to "%s"\n' % (script_path, filename) ) if script_path is not None and script_path != "": #print "Uploading file to ", filename try: f = open(script_path) handle_ssh_command_output(self.ssh.executeCommand("cmd /C echo. > " + filename)) maxsize = 1800 cmd = "" for line in f: line = line.strip("\r\n") tline = line.strip(" \t") if len(tline) > 0: if tline[0] != "'": if len(cmd) > maxsize: handle_ssh_command_output(self.ssh.executeCommand("cmd /C " + cmd.strip(" &"))) handle_ssh_command_output(self.ssh.executeCommand("cmd /C echo " + line + " >> " + filename)) cmd = "" else: cmd += "echo " + line + " >> " + filename cmd += " && " if len(cmd) > 0: handle_ssh_command_output(self.ssh.executeCommand("cmd /C " + cmd.strip(" &"))) cmd = "" self.script = "cscript //NoLogo " + filename + " /DoStdIn" #run ssh in a thread log_debug2('About to run "%s"\n' % self.script) self.chan = None self.out = "" self.read_thread = threading.Thread(target=self.ssh.executeCommand, args=(self.script, Users.CURRENT, None, self.reader, 1, self.save_channel)) self.read_thread.setDaemon(True) self.read_thread.start() except IOError as e: self.ssh.disconnect() self.ssh = None raise e else: print("Can't find a place to upload script dirpath='%s'"%dirpath)