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

@@ -20,7 +20,8 @@ def get_root_path(opts):
def list_shares(shares,opts):
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:
public = get_or_none('public',share, False)
password = 'pass_hash' in share
@@ -31,6 +32,8 @@ def list_shares(shares,opts):
overwrite = get_or_none('overwrite',share, True)
direct = get_or_none('direct_links',share, False) if password else False
expire = get_or_none('expire',share, "-")
if not opts.verbose:
expire = "N" if expire == "-" else "Y"
description = get_or_none('description',share, "")[0:20]
table.append((
share['name'],
@@ -45,7 +48,18 @@ def list_shares(shares,opts):
get_or_none('recipient', share, "")[0:20],
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):
@@ -54,7 +68,6 @@ def list_folders(shares,config):
sys.exit(1)
data_folder = os.path.join(config['__root_path__'], config['data_folder'])
table = []
table.append( ('Path','Share','Size','Unit') )
for path, folders, files in os.walk(data_folder):
full_path = os.path.join(data_folder, path)
share_name = None
@@ -90,7 +103,13 @@ def list_folders(shares,config):
size_num,
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):
@@ -104,7 +123,6 @@ def list_versions(shares, config, opts):
header.append('Age')
else:
header.append('Delete')
table.append(header)
now = datetime.now()
for share in shares:
if opts.name:
@@ -152,7 +170,8 @@ def list_versions(shares, config, opts):
size_unit,
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):
@@ -589,7 +608,6 @@ def print_token():
print(random_token())
def parse_options():
config_default = os.path.realpath(
os.path.join(
@@ -611,6 +629,8 @@ def parse_options():
subparsers = parser.add_subparsers(help='sub-command help', dest='subparser_name')
## 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
parser_folders = subparsers.add_parser('folders', help = "List the subfolders in data folder, and their disk usage")
## list versions