mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-30 19:56:14 +01:00
Merge branch 'config_replace_issue_313' of https://github.com/lethliel/osc
Store a newly created config file in $XDG_CONFIG_HOME/osc/. For backward compatibility, ~/.oscrc is used, if present. Fixes: #313 ("oscrc should be stored in $XDG_CONFIG_HOME on linux")
This commit is contained in:
commit
cb376a1a34
@ -491,7 +491,7 @@ def check_trusted_projects(apiurl, projects):
|
|||||||
print("Note that malicious packages can compromise the build result or even your system.")
|
print("Note that malicious packages can compromise the build result or even your system.")
|
||||||
r = raw_input(trustprompt % { 'project': prj })
|
r = raw_input(trustprompt % { 'project': prj })
|
||||||
if r == '1':
|
if r == '1':
|
||||||
print("adding '%s' to ~/.oscrc: ['%s']['trusted_prj']" % (prj, apiurl))
|
print("adding '%s' to oscrc: ['%s']['trusted_prj']" % (prj, apiurl))
|
||||||
trusted.append(prj)
|
trusted.append(prj)
|
||||||
elif r != '2':
|
elif r != '2':
|
||||||
print("Well, good good bye then :-)")
|
print("Well, good good bye then :-)")
|
||||||
|
@ -5631,7 +5631,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
|
|
||||||
The arguments REPOSITORY and ARCH are optional. They can be taken from
|
The arguments REPOSITORY and ARCH are optional. They can be taken from
|
||||||
the first two columns of the 'osc repos' output. If not specified,
|
the first two columns of the 'osc repos' output. If not specified,
|
||||||
REPOSITORY defaults to the 'build_repositoy' config entry in your '.oscrc'
|
REPOSITORY defaults to the 'build_repositoy' config entry in your 'oscrc'
|
||||||
and ARCH defaults to your host architecture.
|
and ARCH defaults to your host architecture.
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
@ -6014,7 +6014,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
@cmdln.option('--nochecks', '--no-checks', action='store_true',
|
@cmdln.option('--nochecks', '--no-checks', action='store_true',
|
||||||
help='Do not run build checks on the resulting packages.')
|
help='Do not run build checks on the resulting packages.')
|
||||||
@cmdln.option('--no-verify', '--noverify', action='store_true',
|
@cmdln.option('--no-verify', '--noverify', action='store_true',
|
||||||
help='Skip signature verification (via pgp keys) of packages used for build. (Global config in .oscrc: no_verify)')
|
help='Skip signature verification (via pgp keys) of packages used for build. (Global config in oscrc: no_verify)')
|
||||||
@cmdln.option('--noservice', '--no-service', action='store_true',
|
@cmdln.option('--noservice', '--no-service', action='store_true',
|
||||||
help='Skip run of local source services as specified in _service file.')
|
help='Skip run of local source services as specified in _service file.')
|
||||||
@cmdln.option('-p', '--prefer-pkgs', metavar='DIR', action='append',
|
@cmdln.option('-p', '--prefer-pkgs', metavar='DIR', action='append',
|
||||||
@ -6099,8 +6099,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
Debian dsc file.
|
Debian dsc file.
|
||||||
|
|
||||||
The command honours packagecachedir, build-root and build-uid
|
The command honours packagecachedir, build-root and build-uid
|
||||||
settings in .oscrc, if present. You may want to set su-wrapper = 'sudo'
|
settings in oscrc, if present. You may want to set su-wrapper = 'sudo'
|
||||||
in .oscrc, and configure sudo with option NOPASSWD for /usr/bin/build.
|
in oscrc, and configure sudo with option NOPASSWD for /usr/bin/build.
|
||||||
|
|
||||||
If neither --clean nor --noinit is given, build will reuse an existing
|
If neither --clean nor --noinit is given, build will reuse an existing
|
||||||
build-root again, removing unneeded packages and add missing ones. This
|
build-root again, removing unneeded packages and add missing ones. This
|
||||||
@ -8073,7 +8073,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
apiurl = self.get_api_url()
|
apiurl = self.get_api_url()
|
||||||
if len(usernames) < 1:
|
if len(usernames) < 1:
|
||||||
if 'user' not in conf.config['api_host_options'][apiurl]:
|
if 'user' not in conf.config['api_host_options'][apiurl]:
|
||||||
raise oscerr.WrongArgs('your .oscrc does not have your user name.')
|
raise oscerr.WrongArgs('your oscrc does not have your user name.')
|
||||||
usernames = (conf.config['api_host_options'][apiurl]['user'],)
|
usernames = (conf.config['api_host_options'][apiurl]['user'],)
|
||||||
for name in usernames:
|
for name in usernames:
|
||||||
user = get_user_data(apiurl, name, 'login', 'realname', 'email')
|
user = get_user_data(apiurl, name, 'login', 'realname', 'email')
|
||||||
@ -8593,7 +8593,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
be in the cwd or in path.
|
be in the cwd or in path.
|
||||||
|
|
||||||
The email address used in .changes file is read from BuildService
|
The email address used in .changes file is read from BuildService
|
||||||
instance, or should be defined in ~/.oscrc
|
instance, or should be defined in oscrc
|
||||||
[https://api.opensuse.org/]
|
[https://api.opensuse.org/]
|
||||||
user = login
|
user = login
|
||||||
pass = password
|
pass = password
|
||||||
|
33
osc/conf.py
33
osc/conf.py
@ -7,12 +7,12 @@ from __future__ import print_function
|
|||||||
|
|
||||||
"""Read osc configuration and store it in a dictionary
|
"""Read osc configuration and store it in a dictionary
|
||||||
|
|
||||||
This module reads and parses ~/.oscrc. The resulting configuration is stored
|
This module reads and parses oscrc. The resulting configuration is stored
|
||||||
for later usage in a dictionary named 'config'.
|
for later usage in a dictionary named 'config'.
|
||||||
The .oscrc is kept mode 0600, so that it is not publically readable.
|
The oscrc is kept mode 0600, so that it is not publically readable.
|
||||||
This gives no real security for storing passwords.
|
This gives no real security for storing passwords.
|
||||||
If in doubt, use your favourite keyring.
|
If in doubt, use your favourite keyring.
|
||||||
Password is stored on ~/.oscrc as bz2 compressed and base64 encoded, so that is fairly
|
Password is stored on ~/.config/osc/oscrc as bz2 compressed and base64 encoded, so that is fairly
|
||||||
large and not to be recognized or remembered easily by an occasional spectator.
|
large and not to be recognized or remembered easily by an occasional spectator.
|
||||||
|
|
||||||
If information is missing, it asks the user questions.
|
If information is missing, it asks the user questions.
|
||||||
@ -638,7 +638,9 @@ def get_configParser(conffile=None, force_read=False):
|
|||||||
ConfigParser object is stored in a method attribute and this attribute
|
ConfigParser object is stored in a method attribute and this attribute
|
||||||
is returned unless you pass force_read=True.
|
is returned unless you pass force_read=True.
|
||||||
"""
|
"""
|
||||||
conffile = conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
|
if not conffile:
|
||||||
|
conffile = identify_conf()
|
||||||
|
|
||||||
conffile = os.path.expanduser(conffile)
|
conffile = os.path.expanduser(conffile)
|
||||||
if 'conffile' not in get_configParser.__dict__:
|
if 'conffile' not in get_configParser.__dict__:
|
||||||
get_configParser.conffile = conffile
|
get_configParser.conffile = conffile
|
||||||
@ -654,6 +656,8 @@ def write_config(fname, cp):
|
|||||||
if os.path.exists(fname) and not os.path.isfile(fname):
|
if os.path.exists(fname) and not os.path.isfile(fname):
|
||||||
# only write to a regular file
|
# only write to a regular file
|
||||||
return
|
return
|
||||||
|
if not os.path.exists(os.path.dirname(fname)):
|
||||||
|
os.makedirs(os.path.dirname(fname), mode=0o700)
|
||||||
with open(fname + '.new', 'w') as f:
|
with open(fname + '.new', 'w') as f:
|
||||||
cp.write(f, comments=True)
|
cp.write(f, comments=True)
|
||||||
try:
|
try:
|
||||||
@ -818,14 +822,17 @@ def get_config(override_conffile=None,
|
|||||||
"""do the actual work (see module documentation)"""
|
"""do the actual work (see module documentation)"""
|
||||||
global config
|
global config
|
||||||
|
|
||||||
conffile = override_conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
|
if not override_conffile:
|
||||||
conffile = os.path.expanduser(conffile)
|
conffile = identify_conf()
|
||||||
|
else:
|
||||||
|
conffile = override_conffile
|
||||||
|
|
||||||
|
conffile = os.path.expanduser(conffile)
|
||||||
if not os.path.exists(conffile):
|
if not os.path.exists(conffile):
|
||||||
raise oscerr.NoConfigfile(conffile, \
|
raise oscerr.NoConfigfile(conffile, \
|
||||||
account_not_configured_text % conffile)
|
account_not_configured_text % conffile)
|
||||||
|
|
||||||
# okay, we made sure that .oscrc exists
|
# okay, we made sure that oscrc exists
|
||||||
|
|
||||||
# make sure it is not world readable, it may contain a password.
|
# make sure it is not world readable, it may contain a password.
|
||||||
os.chmod(conffile, 0o600)
|
os.chmod(conffile, 0o600)
|
||||||
@ -997,7 +1004,7 @@ def get_config(override_conffile=None,
|
|||||||
scheme = config.get('scheme', 'https')
|
scheme = config.get('scheme', 'https')
|
||||||
config['apiurl'] = urljoin(scheme, apisrv)
|
config['apiurl'] = urljoin(scheme, apisrv)
|
||||||
if 'apisrc' in config or 'scheme' in config:
|
if 'apisrc' in config or 'scheme' in config:
|
||||||
print('Warning: Use of the \'scheme\' or \'apisrv\' in ~/.oscrc is deprecated!\n' \
|
print('Warning: Use of the \'scheme\' or \'apisrv\' in oscrc is deprecated!\n' \
|
||||||
'Warning: See README for migration details.', file=sys.stderr)
|
'Warning: See README for migration details.', file=sys.stderr)
|
||||||
if 'build_platform' in config:
|
if 'build_platform' in config:
|
||||||
print('Warning: Use of \'build_platform\' config option is deprecated! (use \'build_repository\' instead)', file=sys.stderr)
|
print('Warning: Use of \'build_platform\' config option is deprecated! (use \'build_repository\' instead)', file=sys.stderr)
|
||||||
@ -1037,5 +1044,15 @@ def get_config(override_conffile=None,
|
|||||||
# finally, initialize urllib2 for to use the credentials for Basic Authentication
|
# finally, initialize urllib2 for to use the credentials for Basic Authentication
|
||||||
init_basicauth(config, os.stat(conffile).st_mtime)
|
init_basicauth(config, os.stat(conffile).st_mtime)
|
||||||
|
|
||||||
|
def identify_conf():
|
||||||
|
# needed for compat reasons(users may have their oscrc still in ~
|
||||||
|
if 'OSC_CONFIG' in os.environ:
|
||||||
|
return os.environ.get('OSC_CONFIG')
|
||||||
|
if os.path.exists(os.path.expanduser('~/.oscrc')):
|
||||||
|
conffile = '~/.oscrc'
|
||||||
|
else:
|
||||||
|
conffile = os.environ.get('XDG_CONFIG_HOME', '~/.config') + '/osc/oscrc'
|
||||||
|
|
||||||
|
return conffile
|
||||||
|
|
||||||
# vim: sw=4 et
|
# vim: sw=4 et
|
||||||
|
Loading…
Reference in New Issue
Block a user