Skip to content

Commit 6bc2d3f

Browse files
committed
use XDG_CONFIG_HOME/osc/oscrc as default config
write oscrc to the default location for user-specific configuration. If XDG_CONFIG_HOME is not set use ~/.config/osc/oscrc which is basically the same. If there is already a ~/.oscrc use this one (for compat reasons). Existing user installations should not get affected by this commit. The order is the following: Given config with -c config defined in OSC_CONFIG existing ~/.oscrc default XDG_CONFIG_HOME/osc/oscrc
1 parent b52edb6 commit 6bc2d3f

3 files changed

Lines changed: 32 additions & 15 deletions

File tree

‎osc/build.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def check_trusted_projects(apiurl, projects):
491491
print("Note that malicious packages can compromise the build result or even your system.")
492492
r = raw_input(trustprompt % { 'project': prj })
493493
if r == '1':
494-
print("adding '%s' to ~/.oscrc: ['%s']['trusted_prj']" % (prj, apiurl))
494+
print("adding '%s' to oscrc: ['%s']['trusted_prj']" % (prj, apiurl))
495495
trusted.append(prj)
496496
elif r != '2':
497497
print("Well, good good bye then :-)")

‎osc/commandline.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5631,7 +5631,7 @@ def do_buildinfo(self, subcmd, opts, *args):
56315631
56325632
The arguments REPOSITORY and ARCH are optional. They can be taken from
56335633
the first two columns of the 'osc repos' output. If not specified,
5634-
REPOSITORY defaults to the 'build_repositoy' config entry in your '.oscrc'
5634+
REPOSITORY defaults to the 'build_repositoy' config entry in your 'oscrc'
56355635
and ARCH defaults to your host architecture.
56365636
56375637
usage:
@@ -6014,7 +6014,7 @@ def parse_repoarchdescr(self, args, noinit = False, alternative_project = None,
60146014
@cmdln.option('--nochecks', '--no-checks', action='store_true',
60156015
help='Do not run build checks on the resulting packages.')
60166016
@cmdln.option('--no-verify', '--noverify', action='store_true',
6017-
help='Skip signature verification (via pgp keys) of packages used for build. (Global config in .oscrc: no_verify)')
6017+
help='Skip signature verification (via pgp keys) of packages used for build. (Global config in oscrc: no_verify)')
60186018
@cmdln.option('--noservice', '--no-service', action='store_true',
60196019
help='Skip run of local source services as specified in _service file.')
60206020
@cmdln.option('-p', '--prefer-pkgs', metavar='DIR', action='append',
@@ -6099,8 +6099,8 @@ def do_build(self, subcmd, opts, *args):
60996099
Debian dsc file.
61006100
61016101
The command honours packagecachedir, build-root and build-uid
6102-
settings in .oscrc, if present. You may want to set su-wrapper = 'sudo'
6103-
in .oscrc, and configure sudo with option NOPASSWD for /usr/bin/build.
6102+
settings in oscrc, if present. You may want to set su-wrapper = 'sudo'
6103+
in oscrc, and configure sudo with option NOPASSWD for /usr/bin/build.
61046104
61056105
If neither --clean nor --noinit is given, build will reuse an existing
61066106
build-root again, removing unneeded packages and add missing ones. This
@@ -8073,7 +8073,7 @@ def do_whois(self, subcmd, opts, *usernames):
80738073
apiurl = self.get_api_url()
80748074
if len(usernames) < 1:
80758075
if 'user' not in conf.config['api_host_options'][apiurl]:
8076-
raise oscerr.WrongArgs('your .oscrc does not have your user name.')
8076+
raise oscerr.WrongArgs('your oscrc does not have your user name.')
80778077
usernames = (conf.config['api_host_options'][apiurl]['user'],)
80788078
for name in usernames:
80798079
user = get_user_data(apiurl, name, 'login', 'realname', 'email')
@@ -8593,7 +8593,7 @@ def do_vc(self, subcmd, opts, *args):
85938593
be in the cwd or in path.
85948594
85958595
The email address used in .changes file is read from BuildService
8596-
instance, or should be defined in ~/.oscrc
8596+
instance, or should be defined in oscrc
85978597
[https://api.opensuse.org/]
85988598
user = login
85998599
pass = password

‎osc/conf.py‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
"""Read osc configuration and store it in a dictionary
99
10-
This module reads and parses ~/.oscrc. The resulting configuration is stored
10+
This module reads and parses oscrc. The resulting configuration is stored
1111
for later usage in a dictionary named 'config'.
12-
The .oscrc is kept mode 0600, so that it is not publically readable.
12+
The oscrc is kept mode 0600, so that it is not publically readable.
1313
This gives no real security for storing passwords.
1414
If in doubt, use your favourite keyring.
15-
Password is stored on ~/.oscrc as bz2 compressed and base64 encoded, so that is fairly
15+
Password is stored on ~/.config/osc/oscrc as bz2 compressed and base64 encoded, so that is fairly
1616
large and not to be recognized or remembered easily by an occasional spectator.
1717
1818
If information is missing, it asks the user questions.
@@ -638,7 +638,9 @@ def get_configParser(conffile=None, force_read=False):
638638
ConfigParser object is stored in a method attribute and this attribute
639639
is returned unless you pass force_read=True.
640640
"""
641-
conffile = conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
641+
if not conffile:
642+
conffile = identify_conf()
643+
642644
conffile = os.path.expanduser(conffile)
643645
if 'conffile' not in get_configParser.__dict__:
644646
get_configParser.conffile = conffile
@@ -654,6 +656,8 @@ def write_config(fname, cp):
654656
if os.path.exists(fname) and not os.path.isfile(fname):
655657
# only write to a regular file
656658
return
659+
if not os.path.exists(os.path.dirname(fname)):
660+
os.makedirs(os.path.dirname(fname), mode=0o700)
657661
with open(fname + '.new', 'w') as f:
658662
cp.write(f, comments=True)
659663
try:
@@ -818,14 +822,17 @@ def get_config(override_conffile=None,
818822
"""do the actual work (see module documentation)"""
819823
global config
820824

821-
conffile = override_conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
822-
conffile = os.path.expanduser(conffile)
825+
if not override_conffile:
826+
conffile = identify_conf()
827+
else:
828+
conffile = override_conffile
823829

830+
conffile = os.path.expanduser(conffile)
824831
if not os.path.exists(conffile):
825832
raise oscerr.NoConfigfile(conffile, \
826833
account_not_configured_text % conffile)
827834

828-
# okay, we made sure that .oscrc exists
835+
# okay, we made sure that oscrc exists
829836

830837
# make sure it is not world readable, it may contain a password.
831838
os.chmod(conffile, 0o600)
@@ -997,7 +1004,7 @@ def get_config(override_conffile=None,
9971004
scheme = config.get('scheme', 'https')
9981005
config['apiurl'] = urljoin(scheme, apisrv)
9991006
if 'apisrc' in config or 'scheme' in config:
1000-
print('Warning: Use of the \'scheme\' or \'apisrv\' in ~/.oscrc is deprecated!\n' \
1007+
print('Warning: Use of the \'scheme\' or \'apisrv\' in oscrc is deprecated!\n' \
10011008
'Warning: See README for migration details.', file=sys.stderr)
10021009
if 'build_platform' in config:
10031010
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,
10371044
# finally, initialize urllib2 for to use the credentials for Basic Authentication
10381045
init_basicauth(config, os.stat(conffile).st_mtime)
10391046

1047+
def identify_conf():
1048+
# needed for compat reasons(users may have their oscrc still in ~
1049+
if 'OSC_CONFIG' in os.environ:
1050+
return os.environ.get('OSC_CONFIG')
1051+
if os.path.exists(os.path.expanduser('~/.oscrc')):
1052+
conffile = '~/.oscrc'
1053+
else:
1054+
conffile = os.environ.get('XDG_CONFIG_HOME', '~/.config') + '/osc/oscrc'
1055+
1056+
return conffile
10401057

10411058
# vim: sw=4 et

0 commit comments

Comments
 (0)