client in api, slightl more robust client
This commit is contained in:
@@ -368,13 +368,16 @@ def print_rest_api(shares, config, opts):
|
||||
print_rest_api_direct(config, share, token, opts.filename)
|
||||
elif opts.type == "zip":
|
||||
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):
|
||||
print("Link to enter the share:")
|
||||
print("%s/list/%s"%(
|
||||
def print_rest_api_client(config, share, token):
|
||||
print("Command to run python client:")
|
||||
print("python <( %s/script/client/%s/%s )"%(
|
||||
config['public_url'],
|
||||
share['name']
|
||||
share['name'],
|
||||
token
|
||||
))
|
||||
|
||||
|
||||
@@ -386,28 +389,11 @@ def print_rest_api_login(config, share, token):
|
||||
token
|
||||
))
|
||||
|
||||
|
||||
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"%(
|
||||
def print_rest_api_list(config, share):
|
||||
print("Link to enter the share:")
|
||||
print("%s/list/%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
|
||||
share['name']
|
||||
))
|
||||
|
||||
|
||||
@@ -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):
|
||||
print("ZIP download:")
|
||||
print("%s/zip/%s/%s"%(
|
||||
|
||||
@@ -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):
|
||||
try:
|
||||
while True:
|
||||
menu(opts)
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
def upload_file(file, opts):
|
||||
|
||||
Reference in New Issue
Block a user