diff options
author | Milind Changire <mchangir@redhat.com> | 2017-06-06 23:43:54 +0530 |
---|---|---|
committer | Aravinda VK <avishwan@redhat.com> | 2017-06-12 04:48:55 +0000 |
commit | 64588d4f6d69ce6e9b82335d12fa6c42794c38fa (patch) | |
tree | c1bcc51f49e5a44328da86a8bff31684bc83abae /tools/glusterfind/src/main.py | |
parent | 33b426aa9f62f6c8abb2b537b7a784c5b8090fb3 (diff) |
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 <mchangir@redhat.com>
Reviewed-on: https://review.gluster.org/17481
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Aravinda VK <avishwan@redhat.com>
Diffstat (limited to 'tools/glusterfind/src/main.py')
-rw-r--r-- | tools/glusterfind/src/main.py | 35 |
1 files changed, 28 insertions, 7 deletions
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 <VOLUME> <OUTFILE> --since-time <SINCE_TIME> # [--output-prefix <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 <SESSION> <VOLUME> 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") |