]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: handle du's arguments elsewhere outside do_du() 28560/head
authorRishabh Dave <ridave@redhat.com>
Fri, 23 Aug 2019 12:50:04 +0000 (18:20 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 13 Sep 2019 05:15:46 +0000 (10:45 +0530)
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 <ridave@redhat.com>
src/tools/cephfs/cephfs-shell

index 031aee86367b984f8d86e81217a679380e9e9b1d..8cb3260c2b52c0e60efc65aea46bb4d68d16a964 100755 (executable)
@@ -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',