Merge pull request #310 from mattrose/xdg-config-dirs
load config from XDG_CONFIG_DIRS if user config file doesn't exist
This commit is contained in:
commit
8feee50581
@ -76,7 +76,7 @@ from copy import copy
|
||||
from configobj import ConfigObj, flatten_errors
|
||||
from validate import Validator
|
||||
from .borg import Borg
|
||||
from .util import dbg, err, DEBUG, get_config_dir, dict_diff
|
||||
from .util import dbg, err, DEBUG, get_system_config_dir, get_config_dir, dict_diff
|
||||
|
||||
from gi.repository import Gio
|
||||
|
||||
@ -606,13 +606,12 @@ class ConfigBase(Borg):
|
||||
dbg('ConfigBase::load: config already loaded')
|
||||
return
|
||||
|
||||
if self.command_line_options:
|
||||
if not self.command_line_options.config:
|
||||
self.command_line_options.config = os.path.join(get_config_dir(), 'config')
|
||||
if self.command_line_options and self.command_line_options.config:
|
||||
filename = self.command_line_options.config
|
||||
else:
|
||||
filename = os.path.join(get_config_dir(), 'config')
|
||||
|
||||
if not os.path.exists(filename):
|
||||
filename = os.path.join(get_system_config_dir(), 'config')
|
||||
dbg('looking for config file: %s' % filename)
|
||||
try:
|
||||
configfile = open(filename, 'r')
|
||||
@ -730,14 +729,18 @@ class ConfigBase(Borg):
|
||||
os.makedirs(config_dir)
|
||||
|
||||
try:
|
||||
if not os.path.isfile(self.command_line_options.config):
|
||||
open(self.command_line_options.config, 'a').close()
|
||||
if self.command_line_options.config:
|
||||
filename = self.command_line_options.config
|
||||
else:
|
||||
filename = os.path.join(config_dir,'config')
|
||||
|
||||
backup_file = self.command_line_options.config + '~'
|
||||
if not os.path.isfile(filename):
|
||||
open(filename, 'a').close()
|
||||
|
||||
shutil.copy2(self.command_line_options.config, backup_file)
|
||||
backup_file = filename + '~'
|
||||
shutil.copy2(filename, backup_file)
|
||||
|
||||
with open(self.command_line_options.config, 'wb') as fh:
|
||||
with open(filename, 'wb') as fh:
|
||||
parser.write(fh)
|
||||
|
||||
os.remove(backup_file)
|
||||
|
@ -185,6 +185,15 @@ def widget_pixbuf(widget, maxsize=None):
|
||||
|
||||
return(scaledpixbuf)
|
||||
|
||||
def get_system_config_dir():
|
||||
system_config_dir = '/etc/xdg'
|
||||
if 'XDG_CONFIG_DIRS' in os.environ.keys():
|
||||
for sysconfdir in os.environ['XDG_CONFIG_DIRS'].split(":"):
|
||||
if os.path.isdir(sysconfdir):
|
||||
system_config_dir = sysconfdir
|
||||
break
|
||||
return(os.path.join(system_config_dir,'terminator'))
|
||||
|
||||
def get_config_dir():
|
||||
"""Expand all the messy nonsense for finding where ~/.config/terminator
|
||||
really is"""
|
||||
|
Loading…
Reference in New Issue
Block a user