From a0ffa6727b00a4000ed1340ff106bcf0e6bfc866 Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Mon, 12 Jun 2017 14:03:07 +0530 Subject: [PATCH 496/509] 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 mainline: > BUG: 1453151 > 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 (cherry picked from commit 64588d4f6d69ce6e9b82335d12fa6c42794c38fa) Change-Id: I71e878fed58ba1113d97044ac9f6404ee66227c7 BUG: 1450722 Signed-off-by: Milind Changire Reviewed-on: https://code.engineering.redhat.com/gerrit/108767 Reviewed-by: Atin Mukherjee --- 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(-) diff --git a/tools/glusterfind/src/brickfind.py b/tools/glusterfind/src/brickfind.py index efc840b..439c881 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 d146354..8e31a07 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 @@ -332,6 +342,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] @@ -357,6 +369,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') @@ -442,7 +457,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 @@ -459,9 +474,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): @@ -571,7 +592,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") @@ -630,7 +651,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 70737be..b08233e 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)) -- 1.8.3.1