diff options
author | Shwetha K Acharya <sacharya@redhat.com> | 2018-12-31 10:55:21 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2019-01-23 03:16:52 +0000 |
commit | d193ed84ae2886d89b899e02e9642e61bdab462a (patch) | |
tree | 6c7836d3271680e9201203bcbbf6521fcd357952 /tools/glusterfind | |
parent | 86d4eac6c6f2d774a579ef134f6526f75504c46e (diff) |
tools/glusterfind: option to display only files/directories
Updated full find to filter for files and directories.
--full --type f lists only the files,
--full --type d lists only the directories,
--full (by default) lists both files and directories.
fixes: #579
Change-Id: If2c91a21a131667d5de34635c1846013e8fa20b7
Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
Diffstat (limited to 'tools/glusterfind')
-rw-r--r-- | tools/glusterfind/src/brickfind.py | 19 | ||||
-rw-r--r-- | tools/glusterfind/src/changelog.py | 1 | ||||
-rw-r--r-- | tools/glusterfind/src/main.py | 13 | ||||
-rw-r--r-- | tools/glusterfind/src/utils.py | 7 |
4 files changed, 33 insertions, 7 deletions
diff --git a/tools/glusterfind/src/brickfind.py b/tools/glusterfind/src/brickfind.py index 6597aa1ba7c..95b7a3d991d 100644 --- a/tools/glusterfind/src/brickfind.py +++ b/tools/glusterfind/src/brickfind.py @@ -41,12 +41,20 @@ def brickfind_crawl(brick, args): with open(args.outfile, "a+") as fout: brick_path_len = len(brick) - def output_callback(path, filter_result): + def output_callback(path, filter_result, is_dir): path = path.strip() path = path[brick_path_len+1:] - output_write(fout, path, args.output_prefix, - encode=(not args.no_encode), tag=args.tag, - field_separator=args.field_separator) + + if args.type == "both": + output_write(fout, path, args.output_prefix, + encode=(not args.no_encode), tag=args.tag, + field_separator=args.field_separator) + else: + if (is_dir and args.type == "d") or ( + (not is_dir) and args.type == "f"): + output_write(fout, path, args.output_prefix, + encode=(not args.no_encode), tag=args.tag, + field_separator=args.field_separator) ignore_dirs = [os.path.join(brick, dirname) for dirname in @@ -77,6 +85,9 @@ def _get_args(): action="store_true") parser.add_argument("--output-prefix", help="File prefix in output", default=".") + parser.add_argument('--type', help="type: f, f-files only" + " d, d-directories only, by default = both", + default='both') parser.add_argument("--field-separator", help="Field separator", default=" ") diff --git a/tools/glusterfind/src/changelog.py b/tools/glusterfind/src/changelog.py index feef2aebdef..437612ff0a4 100644 --- a/tools/glusterfind/src/changelog.py +++ b/tools/glusterfind/src/changelog.py @@ -374,6 +374,7 @@ def _get_args(): action="store_true") parser.add_argument("--output-prefix", help="File prefix in output", default=".") + parser.add_argument("--type",default="both") parser.add_argument("-N", "--only-namespace-changes", help="List only namespace changes", action="store_true") diff --git a/tools/glusterfind/src/main.py b/tools/glusterfind/src/main.py index dd44cfbfb74..8719b786127 100644 --- a/tools/glusterfind/src/main.py +++ b/tools/glusterfind/src/main.py @@ -165,6 +165,7 @@ def run_cmd_nodes(task, args, **kwargs): (["--no-encode"] if args.no_encode else []) + \ (["--only-namespace-changes"] if args.only_namespace_changes else []) + \ + (["--type", args.type]) + \ (["--field-separator", FS] if args.full else []) opts["node_outfile"] = node_outfile @@ -203,6 +204,7 @@ def run_cmd_nodes(task, args, **kwargs): (["--no-encode"] if args.no_encode else []) + \ (["--only-namespace-changes"] if args.only_namespace_changes else []) + \ + (["--type", args.type]) + \ (["--field-separator", FS] if args.full else []) opts["node_outfile"] = node_outfile @@ -370,6 +372,9 @@ def _get_args(): help="Tag prefix for file names emitted during" " a full find operation; default: \"NEW\"", default="NEW") + parser_pre.add_argument('--type', help="type: f, f-files only" + " d, d-directories only, by default = both", + default='both', choices=["f", "d", "both"]) parser_pre.add_argument("--field-separator", help="Field separator string", default=" ") @@ -399,6 +404,9 @@ def _get_args(): help="Tag prefix for file names emitted during" " a full find operation; default: \"NEW\"", default="NEW") + parser_query.add_argument('--type', help="type: f, f-files only" + " d, d-directories only, by default = both", + default='both', choices=["f", "d", "both"]) parser_query.add_argument("--field-separator", help="Field separator string", default=" ") @@ -589,6 +597,8 @@ def mode_query(session_dir, args): enable_volume_options(args) # Test options + if not args.full and args.type in ["f", "d"]: + fail("--type can only be used with --full") if not args.since_time and not args.end_time and not args.full: fail("Please specify either {--since-time and optionally --end-time} " "or --full", logger=logger) @@ -656,6 +666,9 @@ def mode_pre(session_dir, args): mkdirp(os.path.dirname(args.outfile), exit_on_err=True, logger=logger) + if not args.full and args.type in ["f", "d"]: + fail("--type can only be used with --full") + # If Pre status file exists and running pre command again if os.path.exists(status_file_pre) and not args.regenerate_outfile: fail("Post command is not run after last pre, " diff --git a/tools/glusterfind/src/utils.py b/tools/glusterfind/src/utils.py index b376241820b..cc099031ef8 100644 --- a/tools/glusterfind/src/utils.py +++ b/tools/glusterfind/src/utils.py @@ -58,12 +58,13 @@ def find(path, callback_func=lambda x: True, filter_func=lambda x: True, # Capture filter_func output and pass it to callback function filter_result = filter_func(path) if filter_result is not None: - callback_func(path, filter_result) + callback_func(path, filter_result, os.path.isdir(path)) for p in os.listdir(path): full_path = os.path.join(path, p) - if os.path.isdir(full_path): + is_dir = os.path.isdir(full_path) + if is_dir: if subdirs_crawl: find(full_path, callback_func, filter_func, ignore_dirs) else: @@ -73,7 +74,7 @@ def find(path, callback_func=lambda x: True, filter_func=lambda x: True, else: filter_result = filter_func(full_path) if filter_result is not None: - callback_func(full_path, filter_result) + callback_func(full_path, filter_result, is_dir) def output_write(f, path, prefix=".", encode=False, tag="", |