flees manager list shares and folders
This commit is contained in:
@@ -134,6 +134,9 @@ def download_direct(name,password,filename):
|
|||||||
(ok,share) = get_share(name, require_auth = False)
|
(ok,share) = get_share(name, require_auth = False)
|
||||||
if not ok:
|
if not ok:
|
||||||
return share
|
return share
|
||||||
|
allow_direct = get_or_none(share,'direct_links')
|
||||||
|
if allow_direct != True:
|
||||||
|
return 'Direct download not allowed', 403
|
||||||
token = get_direct_token(share, filename)
|
token = get_direct_token(share, filename)
|
||||||
if token == None:
|
if token == None:
|
||||||
return 'Cannot generate token', 400
|
return 'Cannot generate token', 400
|
||||||
|
|||||||
@@ -1,17 +1,58 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import argparse,json,sys,os
|
import argparse,json,sys,os
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
from tabulate import tabulate
|
||||||
|
|
||||||
|
def get_folder_size(path):
|
||||||
|
|
||||||
|
total_size = 0
|
||||||
|
for dirpath, dirnames, filenames in os.walk(path):
|
||||||
|
for f in filenames:
|
||||||
|
fp = os.path.join(dirpath, f)
|
||||||
|
total_size += os.path.getsize(fp)
|
||||||
|
return total_size
|
||||||
|
|
||||||
|
def get_or_no(key,d,no):
|
||||||
|
if key in d:
|
||||||
|
return d[key]
|
||||||
|
return no
|
||||||
|
|
||||||
|
|
||||||
|
def file_size_human(num):
|
||||||
|
for x in ['B','KB','MB','GB','TB']:
|
||||||
|
if num < 1024.0:
|
||||||
|
if x=='B':
|
||||||
|
return "%d %s" % (num, x)
|
||||||
|
return "%3.1f %s" % (num, x)
|
||||||
|
num /= 1024.0
|
||||||
|
|
||||||
def list_shares(shares):
|
def list_shares(shares):
|
||||||
print("\t".join( ('Name', 'Path') ))
|
table = []
|
||||||
|
table.append(('Name', 'Path','Public','Password','Upload','Overwrite','Direct','Expire'))
|
||||||
for share in shares:
|
for share in shares:
|
||||||
print("\t".join( (share['name'], share['path']) ))
|
public = get_or_no('public',share, False)
|
||||||
|
password = 'pass_hash' in share or 'pass_plain' in share
|
||||||
|
upload = get_or_no('upload',share, False)
|
||||||
|
overwrite = get_or_no('overwrite',share, True)
|
||||||
|
direct = get_or_no('direct_links',share, False) if password else False
|
||||||
|
expire = get_or_no('expire',share, "-")
|
||||||
|
table.append((
|
||||||
|
share['name'],
|
||||||
|
share['path']+"/",
|
||||||
|
public,
|
||||||
|
password,
|
||||||
|
upload,
|
||||||
|
overwrite,
|
||||||
|
direct,
|
||||||
|
expire
|
||||||
|
))
|
||||||
|
print(tabulate(table, headers = "firstrow"))
|
||||||
|
|
||||||
|
|
||||||
def list_folders(shares,config):
|
def list_folders(shares,config):
|
||||||
folders = sorted(os.listdir(config['data_folder']))
|
folders = sorted(os.listdir(config['data_folder']))
|
||||||
print("\t".join( ('Path','Share') ))
|
table = []
|
||||||
|
table.append( ('Path','Share','Size','Unit') )
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
full_path = os.path.join(config['data_folder'], folder)
|
full_path = os.path.join(config['data_folder'], folder)
|
||||||
if not os.path.isdir(full_path):
|
if not os.path.isdir(full_path):
|
||||||
@@ -22,7 +63,16 @@ def list_folders(shares,config):
|
|||||||
if os.path.samefile(full_path, share_path):
|
if os.path.samefile(full_path, share_path):
|
||||||
share_name = share['name']
|
share_name = share['name']
|
||||||
break
|
break
|
||||||
print("\t".join( (folder, share_name) ))
|
(size_num, size_unit) = file_size_human(get_folder_size(
|
||||||
|
full_path
|
||||||
|
)).split(" ")
|
||||||
|
table.append((
|
||||||
|
folder,
|
||||||
|
share_name,
|
||||||
|
size_num,
|
||||||
|
size_unit
|
||||||
|
))
|
||||||
|
print(tabulate(table, headers = "firstrow"))
|
||||||
|
|
||||||
def remove_share(name,shares,config):
|
def remove_share(name,shares,config):
|
||||||
share = [share for share in shares if share['name'] == name]
|
share = [share for share in shares if share['name'] == name]
|
||||||
|
|||||||
1
utils/requirements.txt
Normal file
1
utils/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
tabulate
|
||||||
Reference in New Issue
Block a user