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
1111for 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.
1313This gives no real security for storing passwords.
1414If 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
1616large and not to be recognized or remembered easily by an occasional spectator.
1717
1818If 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