Skip to content

Commit

Permalink
Merge branch 'config_replace_issue_313' of https://github.com/lethlie…
Browse files Browse the repository at this point in the history
…l/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")
  • Loading branch information
marcus-h committed Nov 8, 2017
2 parents 516d031 + 6bc2d3f commit cb376a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion osc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def check_trusted_projects(apiurl, projects):
print("Note that malicious packages can compromise the build result or even your system.")
r = raw_input(trustprompt % { 'project': prj })
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)
elif r != '2':
print("Well, good good bye then :-)")
Expand Down
12 changes: 6 additions & 6 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5631,7 +5631,7 @@ def do_buildinfo(self, subcmd, opts, *args):
The arguments REPOSITORY and ARCH are optional. They can be taken from
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.
usage:
Expand Down Expand Up @@ -6014,7 +6014,7 @@ def parse_repoarchdescr(self, args, noinit = False, alternative_project = None,
@cmdln.option('--nochecks', '--no-checks', action='store_true',
help='Do not run build checks on the resulting packages.')
@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',
help='Skip run of local source services as specified in _service file.')
@cmdln.option('-p', '--prefer-pkgs', metavar='DIR', action='append',
Expand Down Expand Up @@ -6099,8 +6099,8 @@ def do_build(self, subcmd, opts, *args):
Debian dsc file.
The command honours packagecachedir, build-root and build-uid
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.
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.
If neither --clean nor --noinit is given, build will reuse an existing
build-root again, removing unneeded packages and add missing ones. This
Expand Down Expand Up @@ -8073,7 +8073,7 @@ def do_whois(self, subcmd, opts, *usernames):
apiurl = self.get_api_url()
if len(usernames) < 1:
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'],)
for name in usernames:
user = get_user_data(apiurl, name, 'login', 'realname', 'email')
Expand Down Expand Up @@ -8593,7 +8593,7 @@ def do_vc(self, subcmd, opts, *args):
be in the cwd or in path.
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/]
user = login
pass = password
Expand Down
33 changes: 25 additions & 8 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

"""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'.
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.
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.
If information is missing, it asks the user questions.
Expand Down Expand Up @@ -638,7 +638,9 @@ def get_configParser(conffile=None, force_read=False):
ConfigParser object is stored in a method attribute and this attribute
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)
if 'conffile' not in get_configParser.__dict__:
get_configParser.conffile = conffile
Expand All @@ -654,6 +656,8 @@ def write_config(fname, cp):
if os.path.exists(fname) and not os.path.isfile(fname):
# only write to a regular file
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:
cp.write(f, comments=True)
try:
Expand Down Expand Up @@ -818,14 +822,17 @@ def get_config(override_conffile=None,
"""do the actual work (see module documentation)"""
global config

conffile = override_conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
conffile = os.path.expanduser(conffile)
if not override_conffile:
conffile = identify_conf()
else:
conffile = override_conffile

conffile = os.path.expanduser(conffile)
if not os.path.exists(conffile):
raise oscerr.NoConfigfile(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.
os.chmod(conffile, 0o600)
Expand Down Expand Up @@ -997,7 +1004,7 @@ def get_config(override_conffile=None,
scheme = config.get('scheme', 'https')
config['apiurl'] = urljoin(scheme, apisrv)
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)
if 'build_platform' in config:
print('Warning: Use of \'build_platform\' config option is deprecated! (use \'build_repository\' instead)', file=sys.stderr)
Expand Down Expand Up @@ -1037,5 +1044,15 @@ def get_config(override_conffile=None,
# finally, initialize urllib2 for to use the credentials for Basic Authentication
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

0 comments on commit cb376a1

Please sign in to comment.