1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-29 11:16:14 +01:00

Warn about ignoring XDG_CONFIG_HOME and ~/.config/osc/oscrc if ~/.oscrc exists

This commit is contained in:
Daniel Mach 2024-02-21 09:23:29 +01:00
parent 8e7f8fd415
commit 8fc1ad5220

View File

@ -65,6 +65,7 @@ from urllib.parse import urlsplit
from . import credentials
from . import OscConfigParser
from . import oscerr
from .output import tty
from .util import xdg
from .util.helper import raw_input
from .util.models import *
@ -2056,11 +2057,17 @@ def identify_conf():
if 'OSC_CONFIG' in os.environ:
return os.environ.get('OSC_CONFIG')
if os.path.exists(os.path.expanduser('~/.oscrc')):
return '~/.oscrc'
conffile = os.path.join(xdg.XDG_CONFIG_HOME, "osc", "oscrc")
if os.path.exists(os.path.expanduser("~/.oscrc")) or os.path.islink(os.path.expanduser("~/.oscrc")):
if "XDG_CONFIG_HOME" in os.environ:
print(f"{tty.colorize('WARNING', 'yellow,bold')}: Ignoring XDG_CONFIG_HOME env, loading an existing config from '~/.oscrc' instead", file=sys.stderr)
print(" To fix this, move the existing '~/.oscrc' to XDG location such as '~/.config/osc/oscrc'", file=sys.stderr)
elif os.path.exists(os.path.expanduser(conffile)):
print(f"{tty.colorize('WARNING', 'yellow,bold')}: Ignoring config '{conffile}' in XDG location, loading an existing config from ~/.oscrc instead", file=sys.stderr)
print(" To fix this, remove '~/.oscrc'", file=sys.stderr)
return '~/.oscrc'
return conffile