mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-01 04:36:13 +01:00
Merge pull request #1485 from dmach/xdg
Honor XDG_CONFIG_HOME and XDG_CACHE_HOME env vars
This commit is contained in:
commit
64760193ca
27
osc/conf.py
27
osc/conf.py
@ -65,6 +65,7 @@ from urllib.parse import urlsplit
|
|||||||
from . import credentials
|
from . import credentials
|
||||||
from . import OscConfigParser
|
from . import OscConfigParser
|
||||||
from . import oscerr
|
from . import oscerr
|
||||||
|
from .output import tty
|
||||||
from .util import xdg
|
from .util import xdg
|
||||||
from .util.helper import raw_input
|
from .util.helper import raw_input
|
||||||
from .util.models import *
|
from .util.models import *
|
||||||
@ -1605,14 +1606,14 @@ def get_configParser(conffile=None, force_read=False):
|
|||||||
|
|
||||||
def write_config(fname, cp):
|
def write_config(fname, cp):
|
||||||
"""write new configfile in a safe way"""
|
"""write new configfile in a safe way"""
|
||||||
if os.path.exists(fname) and not os.path.isfile(fname):
|
|
||||||
# only write to a regular file
|
|
||||||
return
|
|
||||||
|
|
||||||
# config file is behind a symlink
|
# config file is behind a symlink
|
||||||
# resolve the symlink and continue writing the config as usual
|
# resolve the symlink and continue writing the config as usual
|
||||||
if os.path.islink(fname):
|
if os.path.islink(fname):
|
||||||
fname = os.readlink(fname)
|
fname = os.path.realpath(fname)
|
||||||
|
|
||||||
|
if os.path.exists(fname) and not os.path.isfile(fname):
|
||||||
|
# only write to a regular file
|
||||||
|
return
|
||||||
|
|
||||||
# create directories to the config file (if they don't exist already)
|
# create directories to the config file (if they don't exist already)
|
||||||
fdir = os.path.dirname(fname)
|
fdir = os.path.dirname(fname)
|
||||||
@ -2055,13 +2056,17 @@ def identify_conf():
|
|||||||
# needed for compat reasons(users may have their oscrc still in ~
|
# needed for compat reasons(users may have their oscrc still in ~
|
||||||
if 'OSC_CONFIG' in os.environ:
|
if 'OSC_CONFIG' in os.environ:
|
||||||
return os.environ.get('OSC_CONFIG')
|
return os.environ.get('OSC_CONFIG')
|
||||||
if os.path.exists(os.path.expanduser('~/.oscrc')):
|
|
||||||
return '~/.oscrc'
|
|
||||||
|
|
||||||
if os.environ.get('XDG_CONFIG_HOME', '') != '':
|
conffile = os.path.join(xdg.XDG_CONFIG_HOME, "osc", "oscrc")
|
||||||
conffile = f"{os.environ.get('XDG_CONFIG_HOME')}/osc/oscrc"
|
|
||||||
else:
|
if os.path.exists(os.path.expanduser("~/.oscrc")) or os.path.islink(os.path.expanduser("~/.oscrc")):
|
||||||
conffile = '~/.config/osc/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
|
return conffile
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ from . import oscerr
|
|||||||
from . import store as osc_store
|
from . import store as osc_store
|
||||||
from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE
|
from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE
|
||||||
from .store import Store
|
from .store import Store
|
||||||
|
from .util import xdg
|
||||||
from .util.helper import decode_list, decode_it, raw_input, _html_escape
|
from .util.helper import decode_list, decode_it, raw_input, _html_escape
|
||||||
from .util.xml import xml_indent_compat as xmlindent
|
from .util.xml import xml_indent_compat as xmlindent
|
||||||
|
|
||||||
@ -4512,7 +4513,7 @@ def _edit_message_open_editor(filename, data, orig_mtime):
|
|||||||
if os.stat(filename).st_mtime != orig_mtime:
|
if os.stat(filename).st_mtime != orig_mtime:
|
||||||
# file has changed
|
# file has changed
|
||||||
|
|
||||||
cache_dir = os.path.expanduser("~/.cache/osc/edited-messages")
|
cache_dir = os.path.expanduser(os.path.join(xdg.XDG_CACHE_HOME, "osc", "edited-messages"))
|
||||||
try:
|
try:
|
||||||
os.makedirs(cache_dir, mode=0o700)
|
os.makedirs(cache_dir, mode=0o700)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
|
@ -13,6 +13,7 @@ from cryptography.hazmat.primitives import serialization
|
|||||||
from urllib3.util.ssl_ import create_urllib3_context
|
from urllib3.util.ssl_ import create_urllib3_context
|
||||||
|
|
||||||
from . import oscerr
|
from . import oscerr
|
||||||
|
from .util import xdg
|
||||||
|
|
||||||
|
|
||||||
# based on openssl's include/openssl/x509_vfy.h.in
|
# based on openssl's include/openssl/x509_vfy.h.in
|
||||||
@ -55,7 +56,7 @@ class TrustedCertStore:
|
|||||||
if not self.host:
|
if not self.host:
|
||||||
raise ValueError("Empty `host`")
|
raise ValueError("Empty `host`")
|
||||||
|
|
||||||
self.dir_path = os.path.expanduser("~/.config/osc/trusted-certs")
|
self.dir_path = os.path.expanduser(os.path.join(xdg.XDG_CONFIG_HOME, "osc", "trusted-certs"))
|
||||||
if not os.path.isdir(self.dir_path):
|
if not os.path.isdir(self.dir_path):
|
||||||
try:
|
try:
|
||||||
os.makedirs(self.dir_path, mode=0o700)
|
os.makedirs(self.dir_path, mode=0o700)
|
||||||
@ -103,7 +104,7 @@ class TrustedCertStore:
|
|||||||
Temporarily trust the certificate.
|
Temporarily trust the certificate.
|
||||||
"""
|
"""
|
||||||
self.cert = cert
|
self.cert = cert
|
||||||
tmp_dir = os.path.expanduser("~/.config/osc")
|
tmp_dir = os.path.expanduser(os.path.join(xdg.XDG_CONFIG_HOME, "osc"))
|
||||||
data = self.cert.public_bytes(serialization.Encoding.PEM)
|
data = self.cert.public_bytes(serialization.Encoding.PEM)
|
||||||
with tempfile.NamedTemporaryFile(mode="wb+", dir=tmp_dir, prefix="temp_trusted_cert_") as f:
|
with tempfile.NamedTemporaryFile(mode="wb+", dir=tmp_dir, prefix="temp_trusted_cert_") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user