diff --git a/mc_control.py b/mc_control.py index 7d338f4..f78cfe8 100644 --- a/mc_control.py +++ b/mc_control.py @@ -55,24 +55,22 @@ def create_server(): servers = servers + new_server # Append new array to existing array. write_servers() # Write to the file. +# Used to delete servers from the array and write. def pop_server(): - global servers + global servers # Global so we can write print('\n=== Remove Server ===\nPick a server to delete') - list_servers(2) + list_servers(2) # Lists server ID and Name only. delete = int(input('?: ')) - servers.pop(delete) - write_servers() - initial_choice() - +# Let's send some commands to the servers! def send_commands(): - proceed=True + proceed=True # Used in while loops to determine if we still want to send more commands. print('\n=== Send commands ===') choice = int(input('Single Server (1) or All (2)?: ')) - if(choice==1): - list_servers(2) + if(choice==1): # We only want to interact with one server. + list_servers(2) # Show us which servers we can pick from. server = int(input('Server?: ')) while(proceed): command = input('Input command (None to exit): ') @@ -84,11 +82,10 @@ def send_commands(): else: proceed = False print('No command was entered. Exiting.\n') - initial_choice() elif(choice==2): while(proceed): command = input('Input command (None to exit): ') - for x in servers: + for x in servers: # Run for each server. if(command!=""): with Client(x['address'], int(x['port']), passwd=x['password']) as client: response = client.run(command) @@ -97,8 +94,8 @@ def send_commands(): else: proceed = False print('No command was entered. Exiting.\n') - initial_choice() +# The main menu. def initial_choice(): choose_func = input('=== Choose Function ===\n1. Add servers\n2. Remove servers\n3. List servers\n4. Send commands\n5. Exit\n?: ') @@ -108,11 +105,13 @@ def initial_choice(): initial_choice() case "2": pop_server() + initial_choice() case "3": list_servers() initial_choice() case "4": send_commands() + initial_choice() case "5": exit() case _: