diff --git a/code/app.py b/code/app.py index 172d701..a692359 100644 --- a/code/app.py +++ b/code/app.py @@ -14,7 +14,7 @@ from utils.utils import * from utils.crypt import * -__FLEES_VERSION__ = "20180911.0" +__FLEES_VERSION__ = "20180918.0" app = Flask(__name__) app.config.from_object(__name__) config_values = read_config(app) diff --git a/code/flees-manager.py b/code/flees-manager.py index 840bb28..6a8b7cb 100755 --- a/code/flees-manager.py +++ b/code/flees-manager.py @@ -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 diff --git a/code/utils/utils.py b/code/utils/utils.py index a5d7ab9..23a54e0 100644 --- a/code/utils/utils.py +++ b/code/utils/utils.py @@ -71,6 +71,15 @@ class Logger: fp.flush() +def bool_short(var): + if type(var) == bool: + if var: + return "Y" + else: + return "N" + return var + + def download_url(url, filename): try: r = requests.get(url, stream=True) @@ -268,6 +277,7 @@ def read_config(app): ) return config_values + def safe_name(s): return safe_string(s, "-_")