fail if user specified config is absent
https://fedorahosted.org/koji/ticket/256
This commit is contained in:
parent
e41a2d94c4
commit
04430f81cb
1 changed files with 35 additions and 25 deletions
60
cli/koji
60
cli/koji
|
|
@ -118,8 +118,7 @@ def get_options():
|
|||
parser = OptionParser(usage=usage)
|
||||
parser.disable_interspersed_args()
|
||||
parser.add_option("-c", "--config", dest="configFile",
|
||||
help=_("use alternate configuration file"), metavar="FILE",
|
||||
default="~/.koji/config")
|
||||
help=_("use alternate configuration file"), metavar="FILE")
|
||||
parser.add_option("--keytab", help=_("specify a Kerberos keytab to use"), metavar="FILE")
|
||||
parser.add_option("--principal", help=_("specify a Kerberos principal to use"))
|
||||
parser.add_option("--runas", help=_("run as the specified user (requires special privileges)"))
|
||||
|
|
@ -205,29 +204,40 @@ def get_options():
|
|||
# grab settings from /etc/koji.conf first, and allow them to be
|
||||
# overridden by user config
|
||||
progname = os.path.basename(sys.argv[0]) or 'koji'
|
||||
for configFile in ('/etc/koji.conf', os.path.expanduser(options.configFile)):
|
||||
if os.access(configFile, os.F_OK):
|
||||
f = open(configFile)
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.readfp(f)
|
||||
f.close()
|
||||
if config.has_section(progname):
|
||||
for name, value in config.items(progname):
|
||||
#note the defaults dictionary also serves to indicate which
|
||||
#options *can* be set via the config file. Such options should
|
||||
#not have a default value set in the option parser.
|
||||
if defaults.has_key(name):
|
||||
if name in ('anon_retry', 'offline_retry', 'keepalive', 'use_fast_upload'):
|
||||
defaults[name] = config.getboolean(progname, name)
|
||||
elif name in ('max_retries', 'retry_interval',
|
||||
'offline_retry_interval', 'poll_interval', 'timeout'):
|
||||
try:
|
||||
defaults[name] = int(value)
|
||||
except ValueError:
|
||||
parser.error("value for %s config option must be a valid integer" % name)
|
||||
assert False
|
||||
else:
|
||||
defaults[name] = value
|
||||
configs = []
|
||||
if os.access('/etc/koji.conf', os.F_OK):
|
||||
configs.append('/etc/koji.conf')
|
||||
if options.configFile:
|
||||
fn = os.path.expanduser(options.configFile)
|
||||
if not os.access(fn, os.F_OK):
|
||||
parser.error("No such file: %s" % fn)
|
||||
configs.append(fn)
|
||||
else:
|
||||
fn = os.path.expanduser("~/.koji/config")
|
||||
if os.access(fn, os.F_OK):
|
||||
configs.append(fn)
|
||||
for configFile in configs:
|
||||
f = open(configFile)
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.readfp(f)
|
||||
f.close()
|
||||
if config.has_section(progname):
|
||||
for name, value in config.items(progname):
|
||||
#note the defaults dictionary also serves to indicate which
|
||||
#options *can* be set via the config file. Such options should
|
||||
#not have a default value set in the option parser.
|
||||
if defaults.has_key(name):
|
||||
if name in ('anon_retry', 'offline_retry', 'keepalive', 'use_fast_upload'):
|
||||
defaults[name] = config.getboolean(progname, name)
|
||||
elif name in ('max_retries', 'retry_interval',
|
||||
'offline_retry_interval', 'poll_interval', 'timeout'):
|
||||
try:
|
||||
defaults[name] = int(value)
|
||||
except ValueError:
|
||||
parser.error("value for %s config option must be a valid integer" % name)
|
||||
assert False
|
||||
else:
|
||||
defaults[name] = value
|
||||
for name, value in defaults.iteritems():
|
||||
if getattr(options, name, None) is None:
|
||||
setattr(options, name, value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue