|
@@ -8,6 +8,8 @@ import ssl
|
|
|
import string
|
|
|
import sys
|
|
|
|
|
|
+import utilities
|
|
|
+
|
|
|
|
|
|
class Client:
|
|
|
def __init__(self, host='localhost', port=3001,
|
|
@@ -425,14 +427,17 @@ def main():
|
|
|
token = None
|
|
|
|
|
|
# If import fails, prompt user for host or port
|
|
|
+ new_settings = {} # After getting these settings, offer to store them
|
|
|
while host is None:
|
|
|
host = input("Enter host:\t\t\t\t\t\t")
|
|
|
+ new_settings['host'] = host
|
|
|
while port is None:
|
|
|
try:
|
|
|
port = int(input("Enter port:\t\t\t\t\t\t"))
|
|
|
except ValueError:
|
|
|
logging.info("Invalid port. Enter a valid port number!")
|
|
|
port = None
|
|
|
+ new_settings['port'] = port
|
|
|
while action is None:
|
|
|
action = get_action(
|
|
|
input("Do you want to (R)eceive or (S)end a file?\t\t")
|
|
@@ -459,6 +464,7 @@ def main():
|
|
|
)
|
|
|
if file_path and not os.path.isdir(os.path.abspath(file_path)):
|
|
|
file_path = None
|
|
|
+ new_settings['file_path'] = file_path
|
|
|
if password is None:
|
|
|
logging.warning(
|
|
|
"You have provided no password for file encryption.\n"
|
|
@@ -482,6 +488,28 @@ def main():
|
|
|
)
|
|
|
while token is None or not (6 <= len(token) <= 10):
|
|
|
token = input("Please enter a 6-10 chars token.\t\t\t\t")
|
|
|
+ if new_settings:
|
|
|
+ answer = utilities.timed_input(
|
|
|
+ "Do you want to store the following configuration values in "
|
|
|
+ "`config.py`?\n\n" + '\n'.join(
|
|
|
+ '\t\t'.join(map(str, item))
|
|
|
+ for item in new_settings.items()
|
|
|
+ ),
|
|
|
+ timeout=3
|
|
|
+ )
|
|
|
+ if answer:
|
|
|
+ with open('config.py', 'a') as configuration_file:
|
|
|
+ configuration_file.writelines(
|
|
|
+ [
|
|
|
+ f'{name} = "{value}"'
|
|
|
+ if type(value) is str
|
|
|
+ else f'{name} = {value}'
|
|
|
+ for name, value in new_settings.items()
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ logging.info("Configuration values stored.")
|
|
|
+ else:
|
|
|
+ logging.info("Proceeding without storing values...")
|
|
|
loop = asyncio.get_event_loop()
|
|
|
client = Client(
|
|
|
host=host,
|