# HG changeset patch # User Radek Brich # Date 1399394078 -7200 # Node ID 245646538743df803e7925cc64c87b4e02fe9690 # Parent 0242997020874f64631b9df29827a3bfe40251f8 Update runquery tool: Add --one-query-per-line parameter. diff -r 024299702087 -r 245646538743 runquery.py --- a/runquery.py Tue Apr 29 17:50:15 2014 +0200 +++ b/runquery.py Tue May 06 18:34:38 2014 +0200 @@ -23,6 +23,7 @@ self.parser.add_argument('-c', dest='config', type=str, help='Additional config file (besides pgtoolkit.conf).') self.parser.add_argument('-q', dest='queries', metavar='QUERY', nargs='*', help='Queries to run.') self.parser.add_argument('-f', dest='file', metavar='FILE', help='Read query from file.') + self.parser.add_argument('--one-query-per-line', action='store_true', help='When reading queries from file, consider each line as separate query.') self.parser.add_argument('-p', '--parameter', dest='parameters', metavar='PARAM=VALUE', nargs='*', help="If query should be used as format template, these parameters will be substituted.") self.parser.add_argument('--output-file', dest='output_file', metavar='OUTPUT_FILE', help='Write query result in specified file.') @@ -45,6 +46,10 @@ if self.args.file: with open(self.args.file, 'r', encoding='utf8') as f: data = f.read() + if self.args.one_query_per_line: + file_queries = [ln for ln in data.splitlines() if not ln.lstrip().startswith('--')] + self.queries = file_queries + self.queries + else: self.queries.insert(0, data) # prepare parameters self._prepare_parameters(self.args.parameters)