From 64588d4f6d69ce6e9b82335d12fa6c42794c38fa Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Tue, 6 Jun 2017 23:43:54 +0530 Subject: tools/glusterfind: add --field-separator option Problem: Default field separator is a space character. This gets in the way if the file name itself has embedded spaces. Solution: Add --field-separator option to "pre" and "query" commands. The field separator string will be used to separate strings in the output lines that get written to the output file. eg. old output: NEW file1.txt RENAME file2 Copy.txt file3.txt with --field-separator as "===" new output: NEW===file1.txt RENAME===file2 Copy.txt===file3.txt Change-Id: I71e878fed58ba1113d97044ac9f6404ee66227c7 BUG: 1453151 Signed-off-by: Milind Changire Reviewed-on: https://review.gluster.org/17481 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Aravinda VK --- tools/glusterfind/src/brickfind.py | 5 ++++- tools/glusterfind/src/main.py | 35 ++++++++++++++++++++++++++++------- tools/glusterfind/src/utils.py | 5 +++-- 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/glusterfind/src/brickfind.py b/tools/glusterfind/src/brickfind.py index efc840bca70..439c8816f92 100644 --- a/tools/glusterfind/src/brickfind.py +++ b/tools/glusterfind/src/brickfind.py @@ -42,7 +42,8 @@ def brickfind_crawl(brick, args): path = path.strip() path = path[brick_path_len+1:] output_write(fout, path, args.output_prefix, - encode=(not args.no_encode), tag=args.tag) + encode=(not args.no_encode), tag=args.tag, + field_separator=args.field_separator) ignore_dirs = [os.path.join(brick, dirname) for dirname in @@ -73,6 +74,8 @@ def _get_args(): action="store_true") parser.add_argument("--output-prefix", help="File prefix in output", default=".") + parser.add_argument("--field-separator", help="Field separator", + default=" ") return parser.parse_args() diff --git a/tools/glusterfind/src/main.py b/tools/glusterfind/src/main.py index c125f970a83..e6199a17a3c 100644 --- a/tools/glusterfind/src/main.py +++ b/tools/glusterfind/src/main.py @@ -132,6 +132,10 @@ def run_cmd_nodes(task, args, **kwargs): mkdirp(os.path.dirname(node_outfile), exit_on_err=True, logger=logger) + FS = args.field_separator + if not is_host_local(host_uuid): + FS = "'" + FS + "'" + cmd = [change_detector, args.session, args.volume, @@ -143,7 +147,8 @@ def run_cmd_nodes(task, args, **kwargs): (["--debug"] if args.debug else []) + \ (["--no-encode"] if args.no_encode else []) + \ (["--only-namespace-changes"] if args.only_namespace_changes - else []) + else []) + \ + (["--field-separator", FS] if args.full else []) opts["node_outfile"] = node_outfile opts["copy_outfile"] = True @@ -162,6 +167,10 @@ def run_cmd_nodes(task, args, **kwargs): mkdirp(os.path.dirname(node_outfile), exit_on_err=True, logger=logger) + FS = args.field_separator + if not is_host_local(host_uuid): + FS = "'" + FS + "'" + cmd = [change_detector, args.session, args.volume, @@ -174,7 +183,8 @@ def run_cmd_nodes(task, args, **kwargs): (["--debug"] if args.debug else []) + \ (["--no-encode"] if args.no_encode else []) + \ (["--only-namespace-changes"] - if args.only_namespace_changes else []) + if args.only_namespace_changes else []) + \ + (["--field-separator", FS] if args.full else []) opts["node_outfile"] = node_outfile opts["copy_outfile"] = True @@ -341,6 +351,8 @@ def _get_args(): help="Tag prefix for file names emitted during" " a full find operation; default: \"NEW\"", default="NEW") + parser_pre.add_argument("--field-separator", help="Field separator string", + default=" ") # query --since-time # [--output-prefix ] [--full] @@ -366,6 +378,9 @@ def _get_args(): help="Tag prefix for file names emitted during" " a full find operation; default: \"NEW\"", default="NEW") + parser_query.add_argument("--field-separator", + help="Field separator string", + default=" ") # post parser_post = subparsers.add_parser('post') @@ -451,7 +466,7 @@ def enable_volume_options(args): % args.volume) -def write_output(outfile, outfilemerger): +def write_output(outfile, outfilemerger, field_separator): with codecs.open(outfile, "a", encoding="utf-8") as f: for row in outfilemerger.get(): # Multiple paths in case of Hardlinks @@ -468,9 +483,15 @@ def write_output(outfile, outfilemerger): continue if row_2_rep and row_2_rep != "": - f.write(u"{0} {1} {2}\n".format(row[0], p_rep, row_2_rep)) + f.write(u"{0}{1}{2}{3}{4}\n".format(row[0], + field_separator, + p_rep, + field_separator, + row_2_rep)) else: - f.write(u"{0} {1}\n".format(row[0], p_rep)) + f.write(u"{0}{1}{2}\n".format(row[0], + field_separator, + p_rep)) def mode_create(session_dir, args): @@ -580,7 +601,7 @@ def mode_query(session_dir, args): # Read each Changelogs db and generate finaldb create_file(args.outfile, exit_on_err=True, logger=logger) outfilemerger = OutputMerger(args.outfile + ".db", node_outfiles) - write_output(args.outfile, outfilemerger) + write_output(args.outfile, outfilemerger, args.field_separator) try: os.remove(args.outfile + ".db") @@ -639,7 +660,7 @@ def mode_pre(session_dir, args): # Read each Changelogs db and generate finaldb create_file(args.outfile, exit_on_err=True, logger=logger) outfilemerger = OutputMerger(args.outfile + ".db", node_outfiles) - write_output(args.outfile, outfilemerger) + write_output(args.outfile, outfilemerger, args.field_separator) try: os.remove(args.outfile + ".db") diff --git a/tools/glusterfind/src/utils.py b/tools/glusterfind/src/utils.py index 70737be760a..b08233e4a9f 100644 --- a/tools/glusterfind/src/utils.py +++ b/tools/glusterfind/src/utils.py @@ -75,7 +75,8 @@ def find(path, callback_func=lambda x: True, filter_func=lambda x: True, callback_func(full_path, filter_result) -def output_write(f, path, prefix=".", encode=False, tag=""): +def output_write(f, path, prefix=".", encode=False, tag="", + field_separator=" "): if path == "": return @@ -86,7 +87,7 @@ def output_write(f, path, prefix=".", encode=False, tag=""): path = urllib.quote_plus(path) # set the field separator - FS = "" if tag == "" else " " + FS = "" if tag == "" else field_separator f.write("%s%s%s\n" % (tag.strip(), FS, path)) -- cgit