]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: Fixe flake8 line too long error
authorVarsha Rao <varao@redhat.com>
Thu, 6 Jun 2019 15:08:15 +0000 (20:38 +0530)
committerPatrick Donnelly <pdonnell@redhat.com>
Thu, 20 Jun 2019 22:39:26 +0000 (15:39 -0700)
Break the line into multiple lines and add new variable wherever necessary, to
fix the line too long error.

Fixes: https://tracker.ceph.com/issues/40191
Signed-off-by: Varsha Rao <varao@redhat.com>
(cherry picked from commit e41d467d4f482665fb09bb00edde7c03d6376b82)

src/tools/cephfs/cephfs-shell

index b55f948ab1702fe2dbbf897fcb397be3b6c37ba8..ae6653e819a8c257ee84b1c24c811cfc5502c9af 100644 (file)
@@ -129,7 +129,8 @@ def glob(dir_name, pattern):
     parent_dir = os.path.dirname(dir_name)
     if parent_dir == '':
         parent_dir = '/'
-    if dir_name == '/' or is_dir_exists(os.path.basename(dir_name), parent_dir):
+    if dir_name == '/' or is_dir_exists(os.path.basename(dir_name),
+                                        parent_dir):
         for i in list_items(dir_name)[2:]:
             if fnmatch.fnmatch(i.d_name, pattern):
                 paths.append(os.path.join(dir_name, i.d_name))
@@ -137,10 +138,11 @@ def glob(dir_name, pattern):
 
 
 def locate_file(name, case_sensitive=True):
+    dir_list = sorted(set(dirwalk(cephfs.getcwd().decode('utf-8'))))
     if not case_sensitive:
-        return [i for i in sorted(set(dirwalk(cephfs.getcwd().decode('utf-8')))) if name.lower() in i.lower()]
+        return [dname for dname in dir_list if name.lower() in dname.lower()]
     else:
-        return [i for i in sorted(set(dirwalk(cephfs.getcwd().decode('utf-8')))) if name in i]
+        return [dname for dname in dir_list if name in dname]
 
 
 def get_all_possible_paths(pattern):
@@ -158,7 +160,8 @@ def get_all_possible_paths(pattern):
     for pattern in patterns:
         for path in paths:
             paths.extend(glob(path, pattern))
-    return [path for path in paths if fnmatch.fnmatch(path, os.path.join(cephfs.getcwd().decode('utf-8'), complete_pattern))]
+    return [path for path in paths if fnmatch.fnmatch(path,
+            os.path.join(cephfs.getcwd().decode('utf-8'), complete_pattern))]
 
 
 suffixes = ['B', 'K', 'M', 'G', 'T', 'P']
@@ -235,12 +238,12 @@ def print_list(words, termwidth=79):
     for row in range(nrows):
         for i in range(row, nwords, nrows):
             word = words[i]
+            print_width = width
             if word[0] == '\x1b':
-                poutput(
-                    '%-*s' % (width + 10, words[i]), end='\n' if i + nrows >= nwords else '')
-            else:
-                poutput(
-                    '%-*s' % (width, words[i]), end='\n' if i + nrows >= nwords else '')
+                print_width = print_width + 10
+
+            poutput('%-*s' % (print_width, words[i]),
+                    end='\n' if i + nrows >= nwords else '')
 
 
 def copy_from_local(local_path, remote_path):
@@ -284,9 +287,10 @@ def copy_to_local(remote_path, local_path):
     fd = None
     if local_path != '-':
         local_dir = os.path.dirname(local_path)
+        dir_list = remote_path.rsplit('/', 1)
         if not os.path.exists(local_dir):
             os.makedirs(local_dir)
-        if len(remote_path.rsplit('/', 1)) > 2 and remote_path.rsplit('/', 1)[1] == '':
+        if len(dir_list) > 2 and dir_list[1] == '':
             return
         fd = open(local_path, 'wb+')
     file_ = cephfs.open(to_bytes(remote_path), 'r')
@@ -334,8 +338,9 @@ class CephFSShell(Cmd):
         self.poutput('Unrecognized command')
 
     def set_prompt(self):
-        self.prompt = ('\033[01;33mCephFS:~' + colorama.Fore.LIGHTCYAN_EX +
-                       self.working_dir + colorama.Style.RESET_ALL + '\033[01;33m>>>\033[00m ')
+        self.prompt = ('\033[01;33mCephFS:~' + colorama.Fore.LIGHTCYAN_EX
+                       + self.working_dir + colorama.Style.RESET_ALL
+                       + '\033[01;33m>>>\033[00m ')
 
     def create_argparser(self, command):
         try:
@@ -363,19 +368,26 @@ class CephFSShell(Cmd):
 
     def complete_filenames(self, text, line, begidx, endidx):
         if not text:
-            completions = [x.d_name.decode(
-                'utf-8') + '/' * int(x.is_dir()) for x in list_items(cephfs.getcwd())[2:]]
+            completions = [x.d_name.decode('utf-8') + '/' * int(x.is_dir())
+                           for x in list_items(cephfs.getcwd())[2:]]
         else:
             if text.count('/') > 0:
-                completions = [text.rsplit('/', 1)[0] + '/' + x.d_name.decode('utf-8') + '/'*int(x.is_dir()) for x in list_items(
-                    '/' + text.rsplit('/', 1)[0])[2:] if x.d_name.decode('utf-8').startswith(text.rsplit('/', 1)[1])]
+                completions = [text.rsplit('/', 1)[0] + '/'
+                               + x.d_name.decode('utf-8') + '/'
+                               * int(x.is_dir()) for x in list_items('/'
+                               + text.rsplit('/', 1)[0])[2:]
+                               if x.d_name.decode('utf-8').startswith(
+                                   text.rsplit('/', 1)[1])]
             else:
-                completions = [x.d_name.decode('utf-8') + '/' * int(x.is_dir()) for x in list_items()[
-                    2:] if x.d_name.decode('utf-8').startswith(text)]
+                completions = [x.d_name.decode('utf-8') + '/'
+                               * int(x.is_dir()) for x in list_items()[2:]
+                               if x.d_name.decode('utf-8').startswith(text)]
             if len(completions) == 1 and completions[0][-1] == '/':
                 dir_, file_ = completions[0].rsplit('/', 1)
-                completions.extend([dir_ + '/' + x.d_name.decode('utf-8') + '/' * int(x.is_dir())
-                                    for x in list_items('/' + dir_)[2:] if x.d_name.decode('utf-8').startswith(file_)])
+                completions.extend([dir_ + '/' + x.d_name.decode('utf-8')
+                                    + '/' * int(x.is_dir()) for x in
+                                    list_items('/' + dir_)[2:]
+                                    if x.d_name.decode('utf-8').startswith(file_)])
             return self.delimiter_complete(text, line, begidx, endidx, completions, '/')
         return completions
 
@@ -516,8 +528,9 @@ exists.')
         description='Copy a file/directory to Ceph File System from Local File System.')
     put_parser.add_argument('local_path', type=str,
                             help='Path of the file in the local system')
-    put_parser.add_argument(
-        'remote_path', type=str, help='Path of the file in the remote system.', nargs='?', default='.')
+    put_parser.add_argument('remote_path', type=str,
+                            help='Path of the file in the remote system.',
+                            nargs='?', default='.')
     put_parser.add_argument('-f', '--force', action='store_true',
                             help='Overwrites the destination if it already exists.')
 
@@ -570,22 +583,26 @@ exists.')
         else:
             for src_dir, dirs, files in os.walk(root_src_dir):
                 dst_dir = src_dir.replace(root_src_dir, root_dst_dir, 1)
-                dst_dir = re.sub(r'\/+', '/', cephfs.getcwd().decode('utf-8') + dst_dir)
-                if args.force and dst_dir != '/' and not is_dir_exists(dst_dir[:-1]) and len(locate_file(dst_dir)) == 0:
+                dst_dir = re.sub(r'\/+', '/', cephfs.getcwd().decode('utf-8')
+                                 + dst_dir)
+                if args.force and dst_dir != '/' and not is_dir_exists(
+                        dst_dir[:-1]) and not locate_file(dst_dir):
                     try:
                         cephfs.mkdirs(to_bytes(dst_dir), 0o777)
                     except:
                         pass
-                if (not args.force) and dst_dir != '/' and not is_dir_exists(dst_dir) and not os.path.isfile(root_src_dir):
+                if (not args.force) and dst_dir != '/' and not is_dir_exists(
+                        dst_dir) and not os.path.isfile(root_src_dir):
                     try:
                         cephfs.mkdirs(to_bytes(dst_dir), 0o777)
                     except:
                         pass
 
                 for dir_ in dirs:
-                    if not is_dir_exists(os.path.join(dst_dir, dir_)):
+                    dir_name = os.path.join(dst_dir, dir_)
+                    if not is_dir_exists(dir_name):
                         try:
-                            cephfs.mkdirs(to_bytes(os.path.join(dst_dir, dir_)), 0o777)
+                            cephfs.mkdirs(to_bytes(dir_name), 0o777)
                         except:
                             pass
 
@@ -607,8 +624,9 @@ exists.')
         description='Copy a file from Ceph File System from Local Directory.')
     get_parser.add_argument('remote_path', type=str,
                             help='Path of the file in the remote system')
-    get_parser.add_argument(
-        'local_path', type=str, help='Path of the file in the local system',  nargs='?', default='.')
+    get_parser.add_argument('local_path', type=str,
+                            help='Path of the file in the local system',
+                            nargs='?', default='.')
     get_parser.add_argument('-f', '--force', action='store_true',
                             help='Overwrites the destination if it already exists.')
 
@@ -619,6 +637,7 @@ exists.')
         """
         root_src_dir = args.remote_path
         root_dst_dir = args.local_path
+        fname = root_src_dir.rsplit('/', 1)
         if args.local_path == '.':
             root_dst_dir = os.getcwd()
         if args.remote_path == '.':
@@ -631,7 +650,7 @@ exists.')
         elif is_file_exists(args.remote_path):
             copy_to_local(root_src_dir,
                           root_dst_dir + '/' + root_src_dir)
-        elif '/'in root_src_dir and is_file_exists(root_src_dir.rsplit('/', 1)[1], root_src_dir.rsplit('/', 1)[0]):
+        elif '/'in root_src_dir and is_file_exists(fname[1], fname[0]):
             copy_to_local(root_src_dir, root_dst_dir)
         else:
             files = list(reversed(sorted(dirwalk(root_src_dir))))
@@ -719,7 +738,8 @@ exists.')
                     self.poutput(dir_name, ':\n')
                 items = sorted(items, key=lambda item: item.d_name)
             else:
-                if dir_name != '' and dir_name != cephfs.getcwd().decode('utf-8') and len(directories) > 1:
+                if dir_name != '' and dir_name != cephfs.getcwd().decode(
+                        'utf-8') and len(directories) > 1:
                     self.poutput(dir_name, ':\n')
                 items = sorted(list_items(dir_name),
                                key=lambda item: item.d_name)
@@ -727,8 +747,8 @@ exists.')
                 items = [i for i in items if not i.d_name.startswith(b'.')]
 
             if args.S:
-                items = sorted(items, key=lambda item: cephfs.stat(
-                    to_bytes(dir_name + '/' + item.d_name.decode('utf-8'))).st_size)
+                items = sorted(items, key=lambda item: cephfs.stat(to_bytes(
+                    dir_name + '/' + item.d_name.decode('utf-8'))).st_size)
 
             if args.reverse:
                 items = reversed(items)
@@ -1057,8 +1077,8 @@ sub-directories, files')
     locate_parser = argparse.ArgumentParser(
         description='Find file within file system')
     locate_parser.add_argument('name', help='name', type=str)
-    locate_parser.add_argument(
-        '-c', '--count', action='store_true', help='Count list of items located.')
+    locate_parser.add_argument('-c', '--count', action='store_true',
+                               help='Count list of items located.')
     locate_parser.add_argument(
         '-i', '--ignorecase', action='store_true', help='Ignore case')
 
@@ -1114,8 +1134,9 @@ sub-directories, files')
                         continue
             else:
                 dir_ = os.path.normpath(dir_)
-                self.poutput('{:10s} {}'.format(humansize(int(cephfs.getxattr(to_bytes(
-                    dir_), 'ceph.dir.rbytes').decode('utf-8'))), '.' + dir_))
+                self.poutput('{:10s} {}'.format(humansize(int(cephfs.getxattr(
+                    to_bytes(dir_), 'ceph.dir.rbytes').decode('utf-8'))), '.'
+                    + dir_))
 
     quota_parser = argparse.ArgumentParser(
         description='Quota management for a Directory')
@@ -1215,7 +1236,8 @@ sub-directories, files')
 
     stat_parser = argparse.ArgumentParser(
                   description='Display file or file system status')
-    stat_parser.add_argument('name', type=str, help='Name of the file', nargs='+')
+    stat_parser.add_argument('name', type=str, help='Name of the file',
+                             nargs='+')
 
     @with_argparser(stat_parser)
     def do_stat(self, args):
@@ -1244,12 +1266,13 @@ if __name__ == '__main__':
     config_file = ''
     exe = sys.argv[0]
     main_parser = argparse.ArgumentParser(description='')
-    main_parser.add_argument(
-        '-c', '--config', action='store', help='Configuration file_path', type=str)
+    main_parser.add_argument('-c', '--config', action='store',
+                             help='Configuration file_path', type=str)
     main_parser.add_argument(
         '-b', '--batch', action='store', help='Batch File path.', type=str)
     main_parser.add_argument('-t', '--test', action='store',
-                             help='Test against transcript(s) in FILE', nargs='+')
+                             help='Test against transcript(s) in FILE',
+                             nargs='+')
     main_parser.add_argument('commands', nargs='*',
                              help='comma delimited commands', default=[])
     args = main_parser.parse_args()