From e202e2fe47995713e88ba2779e9fc3d993d152d0 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Mon, 2 Jul 2018 16:37:03 +0300 Subject: [PATCH] some beautification for client --- code/templates/client.py | 43 +++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/code/templates/client.py b/code/templates/client.py index 9af161c..b8955ab 100644 --- a/code/templates/client.py +++ b/code/templates/client.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import argparse, sys, os, subprocess, time, re, json from subprocess import call, Popen, PIPE, STDOUT -import threading import readline import glob from io import StringIO @@ -73,7 +72,7 @@ class Completer(object): def download_file(file, opts): - print("Download "+file['name']) + print("Download " + file['name']) cmd = [ 'curl','--create-dirs', '-o', file['name'], @@ -102,11 +101,12 @@ def menu(opts): 'Download', 'Upload' ] - print_title("Main") + print_title("Main menu") for i,command in enumerate(commands): print(" %d. %s"%( i+1, command, )) comp = Completer(choices = ["1","2"]) readline.set_completer(comp.complete) + print("\n[Empty to exit]") choice = user_input("Number of action: ").strip() if choice == "1": menu_download(opts) @@ -122,7 +122,11 @@ def menu_download(opts): files = json.loads(run_command("file/details", opts)) file_table = [] for f in files: - file_table.append((f['name'], float(f['size'].replace(",","")), f['mtime'])) + file_table.append(( + f['name'], + float(f['size'].replace(",","")), + f['mtime'] + )) print(tabulate(file_table, headers = ("Name", "Size [Mb]", "Modified"))) name_list = [x['name'] for x in files] comp = Completer(choices = name_list) @@ -201,10 +205,18 @@ def parse_options(): def print_title(title): - print("%s\n%s\n"%( - title, - "="*len(title) - )) + status = "Share: %s, Server: %s"%( + opts.share, + opts.rooturl + ) + pad = " "*((len(status) - len(title))/2) + print("\n".join(( + "", + "="*len(status), + status, + pad + title + pad, + "="*len(status) + ))) def read_output(stream): @@ -291,20 +303,6 @@ def upload_file(file, opts): sys.stderr.write(char) sys.stderr.flush() - #~ read_output(p2.stdout) - #~ tin = threading.Thread( - #~ target=write_input, args=(p2.stdin, script) - #~ ) - #~ tout = threading.Thread( - #~ target=read_output, args=(p2.stdout,) - #~ ) - #~ terr = threading.Thread( - #~ target=read_output, args=(p2.stderr,) - #~ ) - #~ for t in (tin, tout, terr): - #~ t.daemon = True - #~ t.start() - #~ p2.wait() return @@ -325,4 +323,3 @@ if __name__ == "__main__": readline.parse_and_bind("tab: complete") opts = parse_options() run_loop(opts) -