Exemplo n.º 1
0
class ServerInfoWindow:
    combined_commands = [
        "uptime",
        "users",
        "uname -a",
        "w",
        "who",
        "df -h",
        "cat /etc/hosts",
        "free -h",
        "iostat",
        "vmstat",
    ]

    command_list = [
        "last",
        "ps aux",
        "vmstat -stats",
        "netstat -l",
        "netstat -t",
        "netstat -u",
        "netstat -x",
        "lscpu",
        "ls ~",
    ]

    def __init__(self, name, ssh_connection=None):
        self.name = name
        self.ssh = ssh_connection
        self.window = Toplevel()
        self.window.geometry("800x600")
        self.window.title(name)
        self.window.option_add("*Font", "TkFixedFont")

        self.command_notebook = ttk.Notebook(self.window)
        self.pack_all_command_tabs()
        self.command_notebook.pack(fill=BOTH, expand=1)

    def bring_to_front(self):
        self.window.focus_force()

    def pack_all_command_tabs(self):
        # Combined commands in one tab
        combined_commands_txt = Text(self.command_notebook)
        combined_commands_txt.tag_config("highlight", foreground="blue")
        for command in self.combined_commands:
            stdin, stdout, stderr = self.ssh.exec_command(command)
            combined_commands_txt.insert(END, ("===== " + command + " =====\n").encode("utf-8"), ("highlight",))
            combined_commands_txt.insert(END, stdout.read())
        self.command_notebook.add(combined_commands_txt, text="Info")

        # Individual commands that get their own tab
        for command in self.command_list:
            stdin, stdout, stderr = self.ssh.exec_command(command)
            command_txt = Text(self.command_notebook)
            command_txt.insert(END, stdout.read())
            self.command_notebook.add(command_txt, text=command)
Exemplo n.º 2
0
class ServerInfoWindow:
    combined_commands = [
        'uptime',
        'users',
        'uname -a',
        'w',
        'who',
        'df -h',
        'cat /etc/hosts',
        'free -h',
        'iostat',
        'vmstat',
    ]

    command_list = [
        'last', 'ps aux', 'vmstat -stats', 'netstat -l', 'netstat -t',
        'netstat -u', 'netstat -x', 'lscpu', 'ls ~'
    ]

    def __init__(self, name, ssh_connection=None):
        self.name = name
        self.ssh = ssh_connection
        self.window = Toplevel()
        self.window.geometry('800x600')
        self.window.title(name)
        self.window.option_add("*Font", "TkFixedFont")

        self.command_notebook = ttk.Notebook(self.window)
        self.pack_all_command_tabs()
        self.command_notebook.pack(fill=BOTH, expand=1)

    def bring_to_front(self):
        self.window.focus_force()

    def pack_all_command_tabs(self):
        # Combined commands in one tab
        combined_commands_txt = Text(self.command_notebook)
        combined_commands_txt.tag_config('highlight', foreground='blue')
        for command in self.combined_commands:
            stdin, stdout, stderr = self.ssh.exec_command(command)
            combined_commands_txt.insert(END, ("===== " + command +
                                               " =====\n").encode('utf-8'),
                                         ('highlight', ))
            combined_commands_txt.insert(END, stdout.read())
        self.command_notebook.add(combined_commands_txt, text='Info')

        # Individual commands that get their own tab
        for command in self.command_list:
            stdin, stdout, stderr = self.ssh.exec_command(command)
            command_txt = Text(self.command_notebook)
            command_txt.insert(END, stdout.read())
            self.command_notebook.add(command_txt, text=command)
Exemplo n.º 3
0
def maketoplevel(root, modal=False):
    """
    Make a toplevel window children of root.
    
    :param root: the main window
    :param modal: if the chield window as to be modal
    :returns: the child window
    """
    tl = Toplevel(root)
    try:
        root.tk.call(
            'wm', 'iconphoto', root._w,
            PhotoImage(file=os.path.join(
                os.path.dirname(os.path.realpath(__file__)), 'pwrsup.png')))
    except:
        print('It is not possible to load the application icon')

    if modal:
        tl.grab_set()
        tl.focus_force()

    return tl