From: Kefu Chai Date: Mon, 18 Feb 2019 09:32:42 +0000 (+0800) Subject: pybind: move FLAGS into Flag class X-Git-Tag: v14.1.0~59^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a0ce76f5f6485ff1822b20bc2938f64de9c0b763;p=ceph.git pybind: move FLAGS into Flag class so we have shorter names, and don't need to import ceph_argparse only for accessing the flags Signed-off-by: Kefu Chai --- diff --git a/src/ceph.in b/src/ceph.in index eb02c60511a..97cb44706be 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -138,11 +138,10 @@ import signal import string import subprocess -import ceph_argparse from ceph_argparse import \ concise_sig, descsort_key, parse_json_funcsigs, \ validate_command, find_cmd_target, \ - json_command, run_in_thread + json_command, run_in_thread, Flag from ceph_daemon import admin_socket, DaemonWatcher, Termsize @@ -472,7 +471,7 @@ def format_help(cmddict, partial=None): if not cmd['help']: continue flags = cmd.get('flags', 0) - if flags & (ceph_argparse.FLAG_OBSOLETE | ceph_argparse.FLAG_DEPRECATED | ceph_argparse.FLAG_HIDDEN): + if flags & (Flag.OBSOLETE | Flag.DEPRECATED | Flag.HIDDEN): continue concise = concise_sig(cmd['sig']) if partial and not concise.startswith(partial): diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 4f6e1d87f50..aedbcb02e20 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -24,12 +24,13 @@ import threading import uuid # Flags are from MonCommand.h -FLAG_NOFORWARD = (1 << 0) -FLAG_OBSOLETE = (1 << 1) -FLAG_DEPRECATED = (1 << 2) -FLAG_MGR = (1<<3) -FLAG_POLL = (1 << 4) -FLAG_HIDDEN = (1 << 5) +class Flag: + NOFORWARD = (1 << 0) + OBSOLETE = (1 << 1) + DEPRECATED = (1 << 2) + MGR = (1<<3) + POLL = (1 << 4) + HIDDEN = (1 << 5) KWARG_EQUALS = "--([^=]+)=(.+)" KWARG_SPACE = "--([^=]+)" @@ -1095,10 +1096,10 @@ def validate(args, signature, flags=0, partial=False): print(save_exception[0], 'not valid: ', save_exception[1], file=sys.stderr) raise ArgumentError("unused arguments: " + str(myargs)) - if flags & FLAG_MGR: + if flags & Flag.MGR: d['target'] = ('mgr','') - if flags & FLAG_POLL: + if flags & Flag.POLL: d['poll'] = True # Finally, success @@ -1133,7 +1134,7 @@ def validate_command(sigdict, args, verbose=False): bestcmds = [] for cmd in sigdict.values(): flags = cmd.get('flags', 0) - if flags & FLAG_OBSOLETE: + if flags & Flag.OBSOLETE: continue sig = cmd['sig'] matched = matchnum(args, sig, partial=True) @@ -1199,7 +1200,8 @@ def validate_command(sigdict, args, verbose=False): print("Invalid command:", ex, file=sys.stderr) print(concise_sig(sig), ': ', cmd['help'], file=sys.stderr) else: - bestcmds = [c for c in bestcmds if not c.get('flags', 0) & (FLAG_DEPRECATED | FLAG_HIDDEN)] + bestcmds = [c for c in bestcmds + if not c.get('flags', 0) & (Flag.DEPRECATED | Flag.HIDDEN)] bestcmds = bestcmds[:10] # top 10 print('no valid command found; {0} closest matches:'.format(len(bestcmds)), file=sys.stderr) for cmd in bestcmds: