some beautification for client

This commit is contained in:
ville rantanen
2018-07-02 16:37:03 +03:00
parent 913de10f8c
commit e202e2fe47

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse, sys, os, subprocess, time, re, json import argparse, sys, os, subprocess, time, re, json
from subprocess import call, Popen, PIPE, STDOUT from subprocess import call, Popen, PIPE, STDOUT
import threading
import readline import readline
import glob import glob
from io import StringIO from io import StringIO
@@ -102,11 +101,12 @@ def menu(opts):
'Download', 'Download',
'Upload' 'Upload'
] ]
print_title("Main") print_title("Main menu")
for i,command in enumerate(commands): for i,command in enumerate(commands):
print(" %d. %s"%( i+1, command, )) print(" %d. %s"%( i+1, command, ))
comp = Completer(choices = ["1","2"]) comp = Completer(choices = ["1","2"])
readline.set_completer(comp.complete) readline.set_completer(comp.complete)
print("\n[Empty to exit]")
choice = user_input("Number of action: ").strip() choice = user_input("Number of action: ").strip()
if choice == "1": if choice == "1":
menu_download(opts) menu_download(opts)
@@ -122,7 +122,11 @@ def menu_download(opts):
files = json.loads(run_command("file/details", opts)) files = json.loads(run_command("file/details", opts))
file_table = [] file_table = []
for f in files: 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"))) print(tabulate(file_table, headers = ("Name", "Size [Mb]", "Modified")))
name_list = [x['name'] for x in files] name_list = [x['name'] for x in files]
comp = Completer(choices = name_list) comp = Completer(choices = name_list)
@@ -201,10 +205,18 @@ def parse_options():
def print_title(title): def print_title(title):
print("%s\n%s\n"%( status = "Share: %s, Server: %s"%(
title, opts.share,
"="*len(title) opts.rooturl
)) )
pad = " "*((len(status) - len(title))/2)
print("\n".join((
"",
"="*len(status),
status,
pad + title + pad,
"="*len(status)
)))
def read_output(stream): def read_output(stream):
@@ -291,20 +303,6 @@ def upload_file(file, opts):
sys.stderr.write(char) sys.stderr.write(char)
sys.stderr.flush() 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 return
@@ -325,4 +323,3 @@ if __name__ == "__main__":
readline.parse_and_bind("tab: complete") readline.parse_and_bind("tab: complete")
opts = parse_options() opts = parse_options()
run_loop(opts) run_loop(opts)