11#!/usr/bin/env python
22import sys
3+ import os
34from optparse import OptionParser
4- from .. import configfile as pg_cf
5+ from .. import configfile
56
67__all__ = ['command' ]
78
@@ -10,20 +11,20 @@ def command(args):
1011 pg_dotconf script entry point.
1112 """
1213 op = OptionParser (
13- "%prog [--stdout] [-f settings] config_file_src ([param=val]|[param])+ " ,
14- version = '0'
14+ "%prog [--stdout] [-f settings] postgresql.conf ([param=val]|[param])* " ,
15+ version = '1. 0'
1516 )
1617 op .add_option (
1718 '-f' , '--file' ,
1819 dest = 'settings' ,
19- help = 'The file of settings to push; parameter arguments may override ' ,
20+ help = 'A file of settings to *apply* to the given "postgresql.conf" ' ,
2021 default = [],
2122 action = 'append' ,
2223 )
2324 op .add_option (
2425 '--stdout' ,
2526 dest = 'stdout' ,
26- help = 'Redirect the changed file to standard output' ,
27+ help = 'Redirect the product to standard output instead of writing back to the "postgresql.conf" file ' ,
2728 action = 'store_true' ,
2829 default = False
2930 )
@@ -35,22 +36,35 @@ def command(args):
3536 for sfp in co .settings :
3637 with open (sfp ) as sf :
3738 for line in sf :
38- pl = pg_cf .parse_line (line )
39+ pl = configfile .parse_line (line )
3940 if pl is not None :
4041 if comment not in line [pl [0 ].start ]:
4142 settings [line [pl [0 ]]] = unquote (line [pl [1 ]])
4243
44+ prev = None
4345 for p in ca [1 :]:
4446 if '=' not in p :
4547 k = p
4648 v = None
4749 else :
4850 k , v = p .split ('=' , 1 )
51+ k = k .strip ()
52+ if not k :
53+ sys .stderr .write ("ERROR: invalid setting, %r after %r%s" % (
54+ p , prev , os .linesep
55+ ))
56+ sys .stderr .write (
57+ "HINT: Settings must take the form 'setting=value' " \
58+ "or 'setting_name_to_comment'. Settings must also be received " \
59+ "as a single argument." + os .linesep
60+ )
61+ sys .exit (1 )
62+ prev = p
4963 settings [k ] = v
5064
5165 fp = ca [0 ]
5266 with open (fp , 'r' ) as fr :
53- lines = pg_cf .alter_config (settings , fr )
67+ lines = configfile .alter_config (settings , fr )
5468
5569 if co .stdout or fp == '/dev/stdin' :
5670 for l in lines :
0 commit comments