diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-05-26 21:09:17 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-05-26 21:09:17 -0400 |
commit | 369e468e2994371193e0c71684fc0c6ef6929418 (patch) | |
tree | ea53d82ceee6af84bfd0e8e5140b0fda101d5537 /htc_utils/CLI/batch.py | |
parent | 1c1988ec76d531c7fbd6adcaaacbcb6be2143b77 (diff) | |
download | htc_utils-369e468e2994371193e0c71684fc0c6ef6929418.tar.gz |
Add automatic grouping of unique commands in input file.
Diffstat (limited to 'htc_utils/CLI/batch.py')
-rw-r--r-- | htc_utils/CLI/batch.py | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/htc_utils/CLI/batch.py b/htc_utils/CLI/batch.py index fe75408..179489d 100644 --- a/htc_utils/CLI/batch.py +++ b/htc_utils/CLI/batch.py @@ -74,14 +74,52 @@ if args.logging: if args.infile: warnings = [] - for index, line in enumerate(args.infile.readlines()): - in_args = line.rstrip() - in_args = line.split() - if len(in_args) < 2: - warnings.append('# Warning: No argument(s) defined for: "{0}", in "{1}", line {2}'.format(''.join(in_args), args.infile.name, index + 1)) - job.subattr('executable', in_args[0]) - job.subattr('arguments', in_args[1:]) - job.subattr('queue') + cmd_groups = [] + uniques = [] + lines = args.infile.readlines() + lines = [ x.rstrip() for x in lines ] + + # Generate set of unique commands in the input file + for line in lines: + if line.startswith('#'): + continue + if not line: + continue + + cmd = line.split() + uniques.append(cmd[0]) + + uniques = set(uniques) + + # Generate cmd_groups list to separate unique group records + for unique in uniques: + temp_group = [] + for index, line in enumerate(lines): + if line.startswith(unique): + cmd = line.rstrip().split() + if not cmd[1:]: + warnings.append('#{0}:{1}:{2} - Warning, executable has no argument. Skipping...'.format(args.infile.name, index + 1, ''.join(line))) + continue + temp_group.append(cmd) + if temp_group: + cmd_groups.append(temp_group) + + # Generate job data + for unique in uniques: + job.subattr('executable', unique) + for group in cmd_groups: + for cmd in group: + if unique in cmd: + cmd_args = cmd[1:] + + if not cmd_args: + continue + + job.subattr('arguments', cmd_args) + job.subattr('queue') + + if args.infile: + args.infile.close() for warning in warnings: print(warning) |