get client without auth
This commit is contained in:
@@ -72,6 +72,22 @@ class Completer(object):
|
||||
return results[state]
|
||||
|
||||
|
||||
def check_connection(opts):
|
||||
p = Popen(
|
||||
[
|
||||
'curl','-s','-f',
|
||||
'%s%s/%s/%s'%(opts.rooturl, "file/list", opts.share, opts.token)
|
||||
],
|
||||
stdout=PIPE,
|
||||
stderr=PIPE
|
||||
)
|
||||
p.communicate()
|
||||
rc = p.returncode
|
||||
if rc != 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def download_file(file, opts, filename = False):
|
||||
print("Download " + file['name'])
|
||||
if not filename:
|
||||
@@ -121,12 +137,17 @@ def edit_file(file):
|
||||
|
||||
|
||||
def menu(opts):
|
||||
commands = {
|
||||
'1': {'name': 'Download', 'cmd': menu_download},
|
||||
'2': {'name': 'Upload', 'cmd': menu_upload},
|
||||
'3': {'name': 'Edit', 'cmd': menu_edit},
|
||||
}
|
||||
print_title("Main menu")
|
||||
commands = {
|
||||
'4': {'name': 'Change login', 'cmd': menu_login}
|
||||
}
|
||||
if check_connection(opts):
|
||||
commands['1'] = {'name': 'Download', 'cmd': menu_download}
|
||||
commands['2'] = {'name': 'Upload', 'cmd': menu_upload}
|
||||
commands['3'] = {'name': 'Edit', 'cmd': menu_edit}
|
||||
else:
|
||||
print(" Not a valid login")
|
||||
|
||||
for command in sorted(commands):
|
||||
print(" %s. %s"%( command, commands[command]['name']))
|
||||
comp = Completer(choices = commands.keys())
|
||||
@@ -134,20 +155,24 @@ def menu(opts):
|
||||
print("\n[Empty to exit]")
|
||||
choice = user_input("Number of action: ").strip()
|
||||
if choice in commands:
|
||||
commands[choice]['cmd'](opts)
|
||||
value = commands[choice]['cmd'](opts)
|
||||
if isinstance(value, dict):
|
||||
opts = value
|
||||
else:
|
||||
sys.exit(0)
|
||||
return opts
|
||||
|
||||
|
||||
def menu_download(opts):
|
||||
while True:
|
||||
print_title("Download files")
|
||||
|
||||
files = json.loads(run_command("file/details", opts))
|
||||
file_table = []
|
||||
for f in files:
|
||||
file_table.append((
|
||||
f['name'],
|
||||
float(f['size'].replace(",","")),
|
||||
f['name'],
|
||||
float(f['size'].replace(",","")),
|
||||
f['mtime']
|
||||
))
|
||||
print(tabulate(file_table, headers = ("Name", "Size [Mb]", "Modified")))
|
||||
@@ -206,6 +231,25 @@ def menu_edit(opts):
|
||||
os.remove(tmp)
|
||||
|
||||
|
||||
def menu_login(opts):
|
||||
print_title("Login")
|
||||
print("\n[Empty to keep previous value]")
|
||||
|
||||
|
||||
choice = user_input('Host [%s]: '%( opts.rooturl, )).strip()
|
||||
if choice != "":
|
||||
opts.rooturl = choice
|
||||
|
||||
choice = user_input('Share name [%s]: '%( opts.share, )).strip()
|
||||
if choice != "":
|
||||
opts.share = choice
|
||||
|
||||
choice = user_input('Token [%s]: '%( opts.token, )).strip()
|
||||
if choice != "":
|
||||
opts.token = choice
|
||||
|
||||
return opts
|
||||
|
||||
def menu_upload(opts):
|
||||
while True:
|
||||
print_title("Upload")
|
||||
@@ -301,7 +345,7 @@ def run_command(command, opts):
|
||||
def run_loop(opts):
|
||||
try:
|
||||
while True:
|
||||
menu(opts)
|
||||
opts = menu(opts)
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user