Browse Source

Modified the remove host method

pull/11/head
jrtechs 6 years ago
parent
commit
415f9f15d8
1 changed files with 41 additions and 18 deletions
  1. +41
    -18
      src/ssh_manager.py

+ 41
- 18
src/ssh_manager.py View File

@ -9,8 +9,8 @@ import collections
import module
INPUT_FILE = "/home/jeff/scripts/servers.txt"
Computer = collections.namedtuple("Computer", ('host', 'menue_id'))
WELCOME_MESSAGE = "*************Jeff-Tower***************"
Computer = collections.namedtuple("Computer", ('host', 'menu_id'))
WELCOME_MESSAGE = "**************************************"
def print_welcome_message():
@ -18,7 +18,7 @@ def print_welcome_message():
Prints defined greeting message to terminal
:return: None
"""
print(magenta_print(WELCOME_MESSAGE))
print(print_magenta(WELCOME_MESSAGE))
def print_menu_option(s):
@ -27,8 +27,8 @@ def print_menu_option(s):
:param s:
:return:
"""
space = " " * (len(WELCOME_MESSAGE) - 3 - len(s))
print(magenta_print("*") + s + space + magenta_print("*"))
space = " " * (len(WELCOME_MESSAGE) - 4 - len(s))
print(print_magenta("* ") + s + space + print_magenta("*"))
def main():
@ -46,14 +46,14 @@ def main():
cmp.append(Computer(line, count))
count += 1
print(magenta_print("*") + " SSH manager V 0.2 " + magenta_print("*"))
print(print_magenta("*") + " " + print_green("SSH manager V 0.2") + " " + print_magenta("*"))
for c in cmp:
print_menu_option(str(c.menue_id) + ") " + c.host)
print_menu_option(str(c.menu_id) + ") " + c.host)
print_menu_option("A) Exit")
print_menu_option("B) Manager tools")
print(magenta_print("*" * len(WELCOME_MESSAGE)))
print(print_magenta("*" * len(WELCOME_MESSAGE)))
i = input("Enter number of computer to connect to or enter to exit:")
if i == '' or i == 'A' or i == 'a':
@ -62,8 +62,9 @@ def main():
sub_menu()
else:
for c in cmp:
if int(i) == c.menue_id:
if int(i) == c.menu_id:
subprocess.call(["ssh", c.host])
exit_program()
def print_sub_menu():
@ -71,17 +72,23 @@ def print_sub_menu():
prints out a sub help menu for other options
:return: None
"""
print(magenta_print("**************************************"))
print(magenta_print("*") + " SSH manager V 0.2 Options " + magenta_print("*"))
print(print_magenta("**************************************"))
print(print_magenta("*") + print_green("Options") + " " + print_magenta("*"))
print_menu_option("1) Add Host")
print_menu_option("2) Copy SSH key to server")
print_menu_option("3) Remove host name")
print_menu_option("4) Return to ssh manager")
print_menu_option("5) Exit")
print(magenta_print("*" * len(WELCOME_MESSAGE)))
print(print_magenta("*" * len(WELCOME_MESSAGE)))
def magenta_print(prt): return"\033[95m {}\033[00m" .format(prt)
def print_magenta(prt): return"\033[95m {}\033[00m" .format(prt)
def print_green(prt): return "\033[92m {}\033[00m" .format(prt)
def print_red(prt): return "\033[91m {}\033[00m" .format(prt)
def sub_menu():
@ -120,7 +127,7 @@ def add_host():
appends an inputted host name to servers.txt
:return: None
"""
host = input("enter host name or -1 to exit:")
host = input("Enter 'user@host' or -1 to exit:")
if host != '-1':
module.append_file(INPUT_FILE, host)
@ -130,9 +137,9 @@ def copy_ssh_key():
calls systems ssh-copy-id with host name
:return: None
"""
host = input("enter user@host or -1 to exit:")
host = input("Enter user@host or -1 to exit:")
if host != '-1':
subprocess.call(["ssh-copy-id " + host])
subprocess.call(["ssh-copy-id", host])
def remove_host():
@ -140,9 +147,25 @@ def remove_host():
Removes a host name from servers.txt
:return: None
"""
host = input("enter host to remove or -1 to exit:")
file = module.input_file(INPUT_FILE)
cmp = []
count = 1
print(print_red("*" * len(WELCOME_MESSAGE)))
for line in file:
cmp.append(Computer(line, count))
count += 1
for c in cmp:
space = " " * (len(WELCOME_MESSAGE) - 3 - len(str(c.menu_id) + ") " + c.host))
print(print_red("*") + str(c.menue_id) + ") " + c.host + space + print_red("*"))
print(print_red("*" * len(WELCOME_MESSAGE)))
host = input("Enter number of host -1 to exit:")
if host != '-1':
module.remove_line_from_file(INPUT_FILE, host)
for c in cmp:
if c.menu_id == int(host):
module.remove_line_from_file(INPUT_FILE, c.host)
"""
Makes sure that other programs don't execute the main

Loading…
Cancel
Save