flees manager list shares and folders
This commit is contained in:
@@ -1,17 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
import argparse,json,sys,os
|
||||
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):
|
||||
print("\t".join( ('Name', 'Path') ))
|
||||
table = []
|
||||
table.append(('Name', 'Path','Public','Password','Upload','Overwrite','Direct','Expire'))
|
||||
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):
|
||||
folders = sorted(os.listdir(config['data_folder']))
|
||||
print("\t".join( ('Path','Share') ))
|
||||
table = []
|
||||
table.append( ('Path','Share','Size','Unit') )
|
||||
for folder in folders:
|
||||
full_path = os.path.join(config['data_folder'], folder)
|
||||
if not os.path.isdir(full_path):
|
||||
@@ -22,7 +63,16 @@ def list_folders(shares,config):
|
||||
if os.path.samefile(full_path, share_path):
|
||||
share_name = share['name']
|
||||
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):
|
||||
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