client in api, slightl more robust client

This commit is contained in:
Ville Rantanen
2018-04-18 10:02:59 +03:00
parent 7edab27351
commit 5201f215b5
2 changed files with 65 additions and 28 deletions

View File

@@ -3,9 +3,19 @@ import argparse, sys, os, subprocess, time, re, json
from subprocess import call, Popen, PIPE, STDOUT
import threading
import readline
from tabulate import tabulate
import glob
from io import StringIO
try:
from tabulate import tabulate
except ImportError:
print("Install tabulate with: pip install --user tabulate")
def tabulate(table, headers):
value = []
value.append("\t".join(headers))
for row in table:
value.append("\t".join([str(c) for c in row]))
value.append("\n\nGet nicer tables by installing 'tabulate' package!\n")
return "\n".join(value)
ROOTURL="{{ rooturl }}"
SHARE="{{ name }}"
@@ -138,6 +148,19 @@ def menu_download(opts):
def menu_upload(opts):
while True:
print_title("Upload")
files = sorted(os.listdir("."))
file_table = []
for f in files:
if f.startswith("."):
continue
if os.path.isfile(f):
file_size = round(os.path.getsize(f) / 1024 / 1024, 2)
else:
file_size = "[DIR]"
f += "/"
file_table.append((f, file_size))
print(tabulate(file_table, headers = ("Name", "Size [Mb]")))
comp = Completer(choices = [])
# we want to treat '/' as part of a word, so override the delimiters
@@ -207,8 +230,12 @@ def run_command(command, opts):
def run_loop(opts):
while True:
menu(opts)
try:
while True:
menu(opts)
except KeyboardInterrupt:
print("")
return
def upload_file(file, opts):