Browse Source

added colored prints

pull/11/head
jrtechs 7 years ago
parent
commit
97ab988d0e
3 changed files with 82 additions and 25 deletions
  1. +28
    -1
      src/module.py
  2. +2
    -2
      src/roosay.py
  3. +52
    -22
      src/ssh_manager.py

+ 28
- 1
src/module.py View File

@ -13,4 +13,31 @@ def input_file(file_name):
with open(file_name) as file: with open(file_name) as file:
for line in file: for line in file:
f.append(line.strip(' \t\n\r')) f.append(line.strip(' \t\n\r'))
return f
return f
def append_file(file_name, append):
"""
Appends text to bottom of a text file
:param file_name: name of file
:param append: message to append on file
:return: None
"""
f = open(file_name, "a+")
f.write(append + "\n")
f.close()
def remove_line_from_file(file_name, remove):
"""
removes a single line of text from a text file
:param file_name:
:param remove:
:return:
"""
lines = input_file(file_name)
f = open(file_name, "w")
for host in lines:
if remove not in host:
f.write(host + "\n")
f.close()

+ 2
- 2
src/roosay.py View File

@ -37,7 +37,7 @@ def print_message(message):
:param message: the message to print :param message: the message to print
:return: None :return: None
""" """
print_list, max_len= convert_to_list(message)
print_list, max_len = convert_to_list(message)
if len(print_list) > 0: if len(print_list) > 0:
"Print top" "Print top"
@ -103,4 +103,4 @@ def print_roo():
If ran from command line, this will call the main which looks for command line arguments If ran from command line, this will call the main which looks for command line arguments
""" """
if __name__ == '__main__': if __name__ == '__main__':
main()
main()

+ 52
- 22
src/ssh_manager.py View File

@ -18,7 +18,7 @@ def print_welcome_message():
Prints defined greeting message to terminal Prints defined greeting message to terminal
:return: None :return: None
""" """
print(WELCOME_MESSAGE)
print(magenta_print(WELCOME_MESSAGE))
def print_menu_option(s): def print_menu_option(s):
@ -28,7 +28,7 @@ def print_menu_option(s):
:return: :return:
""" """
space = " " * (len(WELCOME_MESSAGE) - 3 - len(s)) space = " " * (len(WELCOME_MESSAGE) - 3 - len(s))
print("* " + s + space + "*")
print(magenta_print("*") + s + space + magenta_print("*"))
def main(): def main():
@ -46,73 +46,103 @@ def main():
cmp.append(Computer(line, count)) cmp.append(Computer(line, count))
count += 1 count += 1
print("* SSH manager V 0.2 *")
print(magenta_print("*") + " SSH manager V 0.2 " + magenta_print("*"))
for c in cmp: for c in cmp:
print_menu_option(str(c.menue_id) + ") " + c.host) print_menu_option(str(c.menue_id) + ") " + c.host)
print_menu_option("A/' ') Exit")
print_menu_option("B/' ') Manager tools")
print_menu_option("A) Exit")
print_menu_option("B) Manager tools")
print("*" * len(WELCOME_MESSAGE))
print(magenta_print("*" * len(WELCOME_MESSAGE)))
i = input("Enter number of computer to connect to or enter to exit:") i = input("Enter number of computer to connect to or enter to exit:")
if i == '' or i == 'A' or i == 'a': if i == '' or i == 'A' or i == 'a':
subprocess.call(["clear"])
exit_program()
elif i == 'b' or i == 'B': elif i == 'b' or i == 'B':
subMenu()
sub_menu()
else: else:
for c in cmp: for c in cmp:
if int(i) == c.menue_id: if int(i) == c.menue_id:
subprocess.call(["ssh", c.host]) subprocess.call(["ssh", c.host])
def printSubMenu():
def print_sub_menu():
""" """
prints out a sub help menu for other options prints out a sub help menu for other options
:return: None :return: None
""" """
print("**************************************")
print("* SSH manager V 0.2 Options *")
print(magenta_print("**************************************"))
print(magenta_print("*") + " SSH manager V 0.2 Options " + magenta_print("*"))
print_menu_option("1) Add Host") print_menu_option("1) Add Host")
print_menu_option("2) Copy SSH key to server") print_menu_option("2) Copy SSH key to server")
print_menu_option("3) Remove host name") print_menu_option("3) Remove host name")
print_menu_option("4) Return to ssh manager") print_menu_option("4) Return to ssh manager")
print_menu_option("5) Exit") print_menu_option("5) Exit")
print("*" * len(WELCOME_MESSAGE))
print(magenta_print("*" * len(WELCOME_MESSAGE)))
def subMenu():
def magenta_print(prt): return"\033[95m {}\033[00m" .format(prt)
def sub_menu():
""" """
calls printSubMenu and then gets input from user to make appropriate function calls calls printSubMenu and then gets input from user to make appropriate function calls
:return: None :return: None
""" """
printSubMenu()
input = input("Enter selection:")
print_sub_menu()
i = input("Enter selection:")
if i != '' and int(i) in {1, 2, 3, 4, 5}:
options = {1: add_host,
2: copy_ssh_key,
3: remove_host,
4: main,
5: exit_program,
}
options[int(i)]()
else:
print("Invalid selection!")
sub_menu()
def exit_program():
"""
Exits the program and clears the screen
:return: None
"""
subprocess.call(["clear"])
exit()
def addHost():
def add_host():
""" """
appends an inputted host name to servers.txt appends an inputted host name to servers.txt
:return: None :return: None
""" """
pass
host = input("enter host name or -1 to exit:")
if host != '-1':
module.append_file(INPUT_FILE, host)
def copySSHKey():
def copy_ssh_key():
""" """
calls systems ssh-copy-id with host name calls systems ssh-copy-id with host name
:return: None :return: None
""" """
pass
host = input("enter user@host or -1 to exit:")
if host != '-1':
subprocess.call(["ssh-copy-id " + host])
def removeHost():
def remove_host():
""" """
Removes a host name from servers.txt Removes a host name from servers.txt
:return: None :return: None
""" """
pass
host = input("enter host to remove or -1 to exit:")
if host != '-1':
module.remove_line_from_file(INPUT_FILE, host)
""" """
Makes sure that other programs don't execute the main Makes sure that other programs don't execute the main

Loading…
Cancel
Save