Skip to content

Commit

Permalink
Merge PR ceph#23537 into master
Browse files Browse the repository at this point in the history
* refs/pull/23537/head:
	tools/cephfs-shell:fixing the issue in using  with_argparse.

Reviewed-by: Patrick Donnelly <[email protected]>
  • Loading branch information
batrick committed Aug 13, 2018
2 parents 2b0cece + 2beb133 commit c1a43ca
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/tools/cephfs/cephfs-shell
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import argparse
import os
import os.path
import sys
from cmd2 import Cmd, with_argparser
from cmd2 import Cmd
import cephfs as libcephfs
import shutil
import traceback
Expand All @@ -14,6 +14,36 @@ import readline
import fnmatch
import math
import re
import shlex

try:
from cmd2 import with_argparser
except ImportError:
def with_argparser(argparser):
import functools
def argparser_decorator(func):
@functools.wraps(func)
def wrapper(thiz, cmdline):
# do not split if it's already a list
if not isinstance(cmdline, list):
arglist = shlex.split(cmdline, posix=False)
# in case user quotes the command args
arglist = [arg.strip('\'""') for arg in arglist]
try:
args = argparser.parse_args(arglist)
except SystemExit:
# argparse exits at seeing bad arguments
return
else:
return func(thiz, args)
argparser.prog = func.__name__[3:]
if argparser.description is None and func.__doc__:
argparser.description = func.__doc__

return wrapper

return argparser_decorator


cephfs = None

Expand Down Expand Up @@ -89,8 +119,7 @@ def glob(dir_name, pattern):
if fnmatch.fnmatch(i.d_name.decode('utf-8'), pattern):
paths.append(os.path.join(dir_name, i.d_name.decode('utf-8')))
return paths



def get_all_possible_paths(pattern):
paths = []
is_rel_path = not os.path.isabs(pattern)
Expand Down Expand Up @@ -448,11 +477,9 @@ exists.')
root_src_dir = cephfs.getcwd().decode('utf-8')
if args.local_path == '-':
copy_to_local(self, root_src_dir, '-')
# any([i for i in list_items() if i.d_name.decode('utf-8') == args.remote_path and not i.is_dir()]):
elif is_file_exists(args.remote_path):
copy_to_local(self, root_src_dir,
root_dst_dir + '/' + root_src_dir)
# any([i for i in list_items() if i.d_name.decode('utf-8') == and not i.is_dir()]):
elif '/'in root_src_dir and is_file_exists(root_src_dir.rsplit('/', 1)[1], root_src_dir.rsplit('/', 1)[0]):
copy_to_local(self, root_src_dir, root_dst_dir)
else:
Expand Down Expand Up @@ -588,11 +615,11 @@ sub-directories, files')
dir_path = '/'
dirs = []
for i in all_items:
for item in list_items(dir_name):
for item in list_items(dir_path):
d_name = item.d_name.decode('utf-8')
if os.path.basename(i) == d_name:
if item.is_dir():
dirs.append(os.path.join(dir_name, d_name))
dirs.append(os.path.join(dir_path, d_name))
directories.extend(dirs)
continue
else:
Expand Down

0 comments on commit c1a43ca

Please sign in to comment.