make lists shorter, add verbose switch

This commit is contained in:
2018-09-18 10:34:51 +03:00
parent 2766a54fa7
commit f8cb467dcb
3 changed files with 38 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ from utils.utils import *
from utils.crypt import * from utils.crypt import *
__FLEES_VERSION__ = "20180911.0" __FLEES_VERSION__ = "20180918.0"
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(__name__) app.config.from_object(__name__)
config_values = read_config(app) config_values = read_config(app)

View File

@@ -20,7 +20,8 @@ def get_root_path(opts):
def list_shares(shares,opts): def list_shares(shares,opts):
table = [] table = []
table.append(('Name', 'Path','Public','Password','APIToken','Upload','Overwrite','Direct','Expire','Recipient','Description')) header = ('Name', 'Path','Public','Password','Token','Upload','Overwrite','Direct','Expire','Recipient','Description')
short_header = ('Name', 'Path','Pub','Pwd','Up','Drct','Exp')
for share in shares: for share in shares:
public = get_or_none('public',share, False) public = get_or_none('public',share, False)
password = 'pass_hash' in share password = 'pass_hash' in share
@@ -31,6 +32,8 @@ def list_shares(shares,opts):
overwrite = get_or_none('overwrite',share, True) overwrite = get_or_none('overwrite',share, True)
direct = get_or_none('direct_links',share, False) if password else False direct = get_or_none('direct_links',share, False) if password else False
expire = get_or_none('expire',share, "-") expire = get_or_none('expire',share, "-")
if not opts.verbose:
expire = "N" if expire == "-" else "Y"
description = get_or_none('description',share, "")[0:20] description = get_or_none('description',share, "")[0:20]
table.append(( table.append((
share['name'], share['name'],
@@ -45,7 +48,18 @@ def list_shares(shares,opts):
get_or_none('recipient', share, "")[0:20], get_or_none('recipient', share, "")[0:20],
description description
)) ))
print(tabulate(table, headers = "firstrow")) table.sort(key = lambda x: x[0])
if not opts.verbose:
short_table_indices = [0,1,2,3,5,7,8]
header = short_header
table = [[bool_short(row[col]) for col in short_table_indices] for row in table]
print(
tabulate(
table,
headers = header
)
)
def list_folders(shares,config): def list_folders(shares,config):
@@ -54,7 +68,6 @@ def list_folders(shares,config):
sys.exit(1) sys.exit(1)
data_folder = os.path.join(config['__root_path__'], config['data_folder']) data_folder = os.path.join(config['__root_path__'], config['data_folder'])
table = [] table = []
table.append( ('Path','Share','Size','Unit') )
for path, folders, files in os.walk(data_folder): for path, folders, files in os.walk(data_folder):
full_path = os.path.join(data_folder, path) full_path = os.path.join(data_folder, path)
share_name = None share_name = None
@@ -90,7 +103,13 @@ def list_folders(shares,config):
size_num, size_num,
size_unit size_unit
)) ))
print(tabulate(table, headers = "firstrow")) table.sort(key = lambda x: x[0])
print(
tabulate(
table,
headers = ('Path','Share','Size','Unit')
)
)
def list_versions(shares, config, opts): def list_versions(shares, config, opts):
@@ -104,7 +123,6 @@ def list_versions(shares, config, opts):
header.append('Age') header.append('Age')
else: else:
header.append('Delete') header.append('Delete')
table.append(header)
now = datetime.now() now = datetime.now()
for share in shares: for share in shares:
if opts.name: if opts.name:
@@ -152,7 +170,8 @@ def list_versions(shares, config, opts):
size_unit, size_unit,
age_str age_str
)) ))
print(tabulate(table, headers = "firstrow")) table.sort(key = lambda x: x[0])
print(tabulate(table, headers = header))
def add_share(shares, config, opts): def add_share(shares, config, opts):
@@ -589,7 +608,6 @@ def print_token():
print(random_token()) print(random_token())
def parse_options(): def parse_options():
config_default = os.path.realpath( config_default = os.path.realpath(
os.path.join( os.path.join(
@@ -611,6 +629,8 @@ def parse_options():
subparsers = parser.add_subparsers(help='sub-command help', dest='subparser_name') subparsers = parser.add_subparsers(help='sub-command help', dest='subparser_name')
## list shares ## list shares
parser_list = subparsers.add_parser('list', help = "List shares") parser_list = subparsers.add_parser('list', help = "List shares")
parser_list.add_argument('--verbose', '-v', action="store_true", dest="verbose", default = False,
help = "Verbose listing")
## list folders ## list folders
parser_folders = subparsers.add_parser('folders', help = "List the subfolders in data folder, and their disk usage") parser_folders = subparsers.add_parser('folders', help = "List the subfolders in data folder, and their disk usage")
## list versions ## list versions

View File

@@ -71,6 +71,15 @@ class Logger:
fp.flush() fp.flush()
def bool_short(var):
if type(var) == bool:
if var:
return "Y"
else:
return "N"
return var
def download_url(url, filename): def download_url(url, filename):
try: try:
r = requests.get(url, stream=True) r = requests.get(url, stream=True)
@@ -268,6 +277,7 @@ def read_config(app):
) )
return config_values return config_values
def safe_name(s): def safe_name(s):
return safe_string(s, "-_") return safe_string(s, "-_")