Commit 43de8af2 authored by André Anjos's avatar André Anjos

Merge branch 'unique' into 'master'

Add an option to make the aggregate output unique

See merge request !14
parents 7bae9c12 9c107f73
Pipeline #14600 passed with stages
in 16 minutes and 23 seconds
......@@ -89,6 +89,7 @@ def main(command_line_options = None):
help = "Increase the verbosity level from 0 (only error messages) to 1 (warnings), 2 (log messages), 3 (debug information) by adding the --verbose option as often as desired (e.g. '-vvv' for debug).")
parser.add_argument('-V', '--version', action='version',
version='GridTk version %s' % __version__)
parser.add_argument('-u', '--unique-aggregate', dest='unique', action="store_true", help="It will make sure the output lines in aggout are unique while ignoring the empty lines and comment lines.")
# parse
......@@ -129,7 +130,19 @@ def main(command_line_options = None):
data = generator.aggregate(args.variables, args.aggtmpl)
dirname = os.path.dirname(args.aggout)
if dirname: tools.makedirs_safe(dirname)
with open(args.aggout, 'wt') as f: f.write(data)
with open(args.aggout, 'wt') as f:
if args.unique:
unique_lines = []
for line in data.split('\n'):
if not line.strip():
f.write(line + '\n')
elif line.strip()[0] == '#':
f.write(line + '\n')
elif line not in unique_lines:
f.write(line + '\n')
f.write(data)'Wrote `%s\'', args.aggout)
return 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment