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

@@ -368,13 +368,16 @@ def print_rest_api(shares, config, opts):
print_rest_api_direct(config, share, token, opts.filename) print_rest_api_direct(config, share, token, opts.filename)
elif opts.type == "zip": elif opts.type == "zip":
print_rest_api_zip(config, share, token) print_rest_api_zip(config, share, token)
elif opts.type == "client":
print_rest_api_client(config, share, token)
def print_rest_api_list(config, share): def print_rest_api_client(config, share, token):
print("Link to enter the share:") print("Command to run python client:")
print("%s/list/%s"%( print("python <( %s/script/client/%s/%s )"%(
config['public_url'], config['public_url'],
share['name'] share['name'],
token
)) ))
@@ -386,28 +389,11 @@ def print_rest_api_login(config, share, token):
token token
)) ))
def print_rest_api_list(config, share):
def print_rest_api_upload(config, share, token): print("Link to enter the share:")
if 'upload' not in share or not share['upload']: print("%s/list/%s"%(
print("Uploading not allowed to this share")
sys.exit(0)
print("Link to upload file to the share:")
print("\n# curl -F file=@'the_file_name.ext' %s/upload/%s/%s"%(
config['public_url'], config['public_url'],
share['name'], share['name']
token
))
print("\nLink to upload multiple files to the share:")
print("\n# curl -s %s/script/upload/%s/%s | bash /dev/stdin file_to_upload.ext [second.file.ext]"%(
config['public_url'],
share['name'],
token
))
print("\nLink to upload multiple files to the share, splitting large files:")
print("\n# curl -s %s/script/upload_split/%s/%s | python - [-s split_size_in_Mb] file_to_upload.ext [second.file.ext]"%(
config['public_url'],
share['name'],
token
)) ))
@@ -473,6 +459,30 @@ def print_rest_api_direct(config, share, token, show_filename):
)) ))
def print_rest_api_upload(config, share, token):
if 'upload' not in share or not share['upload']:
print("Uploading not allowed to this share")
sys.exit(0)
print("Link to upload file to the share:")
print("\n# curl -F file=@'the_file_name.ext' %s/upload/%s/%s"%(
config['public_url'],
share['name'],
token
))
print("\nLink to upload multiple files to the share:")
print("\n# curl -s %s/script/upload/%s/%s | bash /dev/stdin file_to_upload.ext [second.file.ext]"%(
config['public_url'],
share['name'],
token
))
print("\nLink to upload multiple files to the share, splitting large files:")
print("\n# curl -s %s/script/upload_split/%s/%s | python - [-s split_size_in_Mb] file_to_upload.ext [second.file.ext]"%(
config['public_url'],
share['name'],
token
))
def print_rest_api_zip(config, share, token): def print_rest_api_zip(config, share, token):
print("ZIP download:") print("ZIP download:")
print("%s/zip/%s/%s"%( print("%s/zip/%s/%s"%(

View File

@@ -3,9 +3,19 @@ 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 threading
import readline import readline
from tabulate import tabulate
import glob import glob
from io import StringIO 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 }}" ROOTURL="{{ rooturl }}"
SHARE="{{ name }}" SHARE="{{ name }}"
@@ -138,6 +148,19 @@ def menu_download(opts):
def menu_upload(opts): def menu_upload(opts):
while True: while True:
print_title("Upload") 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 = []) comp = Completer(choices = [])
# we want to treat '/' as part of a word, so override the delimiters # 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): def run_loop(opts):
while True: try:
menu(opts) while True:
menu(opts)
except KeyboardInterrupt:
print("")
return
def upload_file(file, opts): def upload_file(file, opts):