Browse Source

Re-worked the code and fixed glitch in menu

pull/1/head
Jeffery Russell 6 years ago
parent
commit
81ee55de79
3 changed files with 39 additions and 32 deletions
  1. +16
    -0
      src/module.py
  2. +2
    -23
      src/quote.py
  3. +21
    -9
      src/ssh_manager.py

+ 16
- 0
src/module.py View File

@ -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

+ 2
- 23
src/quote.py View File

@ -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()
"""

+ 21
- 9
src/ssh_manager.py View File

@ -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

Loading…
Cancel
Save