mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-01 04:36:13 +01:00
Allow starting with an empty config if --configfile is either empty or points to /dev/null
This commit is contained in:
parent
b5c8fa75ea
commit
b41afde2c9
44
osc/conf.py
44
osc/conf.py
@ -1824,29 +1824,33 @@ def get_config(override_conffile=None,
|
|||||||
else:
|
else:
|
||||||
conffile = identify_conf()
|
conffile = identify_conf()
|
||||||
|
|
||||||
conffile = os.path.expanduser(conffile)
|
if conffile in ["", "/dev/null"]:
|
||||||
if not os.path.exists(conffile):
|
cp = OscConfigParser.OscConfigParser()
|
||||||
raise oscerr.NoConfigfile(conffile, account_not_configured_text % conffile)
|
cp.add_section("general")
|
||||||
|
else:
|
||||||
|
conffile = os.path.expanduser(conffile)
|
||||||
|
if not os.path.exists(conffile):
|
||||||
|
raise oscerr.NoConfigfile(conffile, account_not_configured_text % conffile)
|
||||||
|
|
||||||
# make sure oscrc is not world readable, it may contain a password
|
# make sure oscrc is not world readable, it may contain a password
|
||||||
conffile_stat = os.stat(conffile)
|
conffile_stat = os.stat(conffile)
|
||||||
if conffile_stat.st_mode != 0o600:
|
if conffile_stat.st_mode != 0o600:
|
||||||
try:
|
try:
|
||||||
os.chmod(conffile, 0o600)
|
os.chmod(conffile, 0o600)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno in (errno.EROFS, errno.EPERM):
|
if e.errno in (errno.EROFS, errno.EPERM):
|
||||||
print(f"Warning: Configuration file '{conffile}' may have insecure file permissions.")
|
print(f"Warning: Configuration file '{conffile}' may have insecure file permissions.")
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
cp = get_configParser(conffile)
|
cp = get_configParser(conffile)
|
||||||
|
|
||||||
if not cp.has_section('general'):
|
if not cp.has_section("general"):
|
||||||
# FIXME: it might be sufficient to just assume defaults?
|
# FIXME: it might be sufficient to just assume defaults?
|
||||||
msg = config_incomplete_text % conffile
|
msg = config_incomplete_text % conffile
|
||||||
defaults = Options().dict()
|
defaults = Options().dict()
|
||||||
msg += new_conf_template % defaults
|
msg += new_conf_template % defaults
|
||||||
raise oscerr.ConfigError(msg, conffile)
|
raise oscerr.ConfigError(msg, conffile)
|
||||||
|
|
||||||
global config
|
global config
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user