From edb6724fabbcd3446f882f3a5040a9fbb35abdd6 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Fri, 23 Aug 2019 18:20:04 +0530 Subject: [PATCH] cephfs-shell: handle du's arguments elsewhere outside do_du() Create new action class for do_du()'s args.paths and push the code that handles arguments for do_du() in there. The intention is to keep only the code that does some disk usage stuff in do_du(). Signed-off-by: Rishabh Dave --- src/tools/cephfs/cephfs-shell | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 031aee86367..8cb3260c2b5 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -417,6 +417,20 @@ class CephFSShell(Cmd): values = to_bytes(values) setattr(namespace, self.dest, values) + # TODO: move the necessary contents from here to `class path_to_bytes`. + class get_list_of_bytes_path(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + values = to_bytes(values) + + if values == b'.': + values = cephfs.getcwd() + else: + for i in values: + if i == b'.': + values[values.index(i)] = cephfs.getcwd() + + setattr(namespace, self.dest, values) + def complete_mkdir(self, text, line, begidx, endidx): """ auto complete of file name. @@ -1132,7 +1146,7 @@ sub-directories, files') du_parser = argparse.ArgumentParser( description='Disk Usage of a Directory') - du_parser.add_argument('paths', type=str, action=path_to_bytes, + du_parser.add_argument('paths', type=str, action=get_list_of_bytes_path, help='Name of the directory.', nargs='*', default=[b'.']) du_parser.add_argument('-r', action='store_true', -- 2.39.5