From 81ee55de796b758117d70b06d93af6458abd5708 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Fri, 29 Sep 2017 11:04:37 -0400 Subject: [PATCH] Re-worked the code and fixed glitch in menu --- src/module.py | 16 ++++++++++++++++ src/quote.py | 25 ++----------------------- src/ssh_manager.py | 30 +++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 src/module.py diff --git a/src/module.py b/src/module.py new file mode 100644 index 0000000..94ba8cb --- /dev/null +++ b/src/module.py @@ -0,0 +1,16 @@ +""" +Jeffery Russell +9/29/17 +""" + + +def input_file(file_name): + """ + This file inputs the file defined by INPUT_FILE into a string line and returns it + :return: a string array containing the lines of INPUT_FILE + """ + f = [] + with open(file_name) as file: + for line in file: + f.append(line.strip(' \t\n\r')) + return f \ No newline at end of file diff --git a/src/quote.py b/src/quote.py index ae254e1..c364595 100644 --- a/src/quote.py +++ b/src/quote.py @@ -8,9 +8,9 @@ Jeffery Russell import subprocess import random +import module INPUT_FILE = "/home/jeff/scripts/quotes.txt" -WELCOME_MESSAGE = "***************Jeff-Laptop***************" def print_cowsay_message(message): @@ -22,36 +22,15 @@ def print_cowsay_message(message): subprocess.call(["cowsay", message]) -def print_welcome_message(): - """ - Prints defined greeting message to terminal - :return: None - """ - print(WELCOME_MESSAGE) - - -def input_file(): - """ - This file inputs the file defined by INPUT_FILE into a string line and returns it - :return: a string array containing the lines of INPUT_FILE - """ - quotes = [] - with open(INPUT_FILE) as file: - for line in file: - quotes.append(line.strip(' \t\n\r')) - return quotes - def main(): """ This function calls the welcome function, then it calls the cowsay function with a random quote. :return: None """ - quotes = input_file() - + quotes = module.input_file(INPUT_FILE) print_cowsay_message(quotes[random.randint(0,(len(quotes) -1))]) - print_welcome_message() """ diff --git a/src/ssh_manager.py b/src/ssh_manager.py index f015654..8bb7fe0 100644 --- a/src/ssh_manager.py +++ b/src/ssh_manager.py @@ -6,11 +6,20 @@ Jeffery Russell import subprocess import collections -import quote +import module INPUT_FILE = "/home/jeff/scripts/servers.txt" Computer = collections.namedtuple("Computer", ('host', 'menue_id')) -WELCOME_MESSAGE = "***************Jeff-Laptop***************" +WELCOME_MESSAGE = "*************Jeff-Laptop***************" + + +def print_welcome_message(): + """ + Prints defined greeting message to terminal + :return: None + """ + print(WELCOME_MESSAGE) + def print_menu_option(s): """ @@ -18,23 +27,26 @@ def print_menu_option(s): :param s: :return: """ - space = " " * len(quote) - 4 - len(s) + space = " " * (len(WELCOME_MESSAGE) - 3 - len(s)) print("* " + s + space + "*") + def main(): """ This function inputs all the available hosts from a text file and prompts the user to connect to them :return: """ + print_welcome_message() + file = module.input_file(INPUT_FILE) cmp = [] count = 1 - with open(INPUT_FILE) as file: - for line in file: - cmp.append(Computer(line, count)) - count += 1 - print("* SSH manager V 0.1 *") + for line in file: + cmp.append(Computer(line, count)) + count += 1 + + print("* SSH manager V 0.1 *") for c in cmp: print_menu_option(str(c.menue_id) + ") " + c.host) @@ -43,7 +55,7 @@ def main(): for c in cmp: if i != '' and int(i) == c.menue_id: - subprocess.call(["ssh", c.host.strip(' \t\n\r')]) + subprocess.call(["ssh", c.host]) """ Makes sure that other programs don't execute the main