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 configobj import ConfigObj, flatten_errors
|
||||||
from validate import Validator
|
from validate import Validator
|
||||||
from .borg import Borg
|
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
|
from gi.repository import Gio
|
||||||
|
|
||||||
|
@ -606,13 +606,12 @@ class ConfigBase(Borg):
|
||||||
dbg('ConfigBase::load: config already loaded')
|
dbg('ConfigBase::load: config already loaded')
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.command_line_options:
|
if self.command_line_options and self.command_line_options.config:
|
||||||
if not self.command_line_options.config:
|
|
||||||
self.command_line_options.config = os.path.join(get_config_dir(), 'config')
|
|
||||||
filename = self.command_line_options.config
|
filename = self.command_line_options.config
|
||||||
else:
|
else:
|
||||||
filename = os.path.join(get_config_dir(), 'config')
|
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)
|
dbg('looking for config file: %s' % filename)
|
||||||
try:
|
try:
|
||||||
configfile = open(filename, 'r')
|
configfile = open(filename, 'r')
|
||||||
|
@ -730,14 +729,18 @@ class ConfigBase(Borg):
|
||||||
os.makedirs(config_dir)
|
os.makedirs(config_dir)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.isfile(self.command_line_options.config):
|
if self.command_line_options.config:
|
||||||
open(self.command_line_options.config, 'a').close()
|
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)
|
parser.write(fh)
|
||||||
|
|
||||||
os.remove(backup_file)
|
os.remove(backup_file)
|
||||||
|
|
|
@ -185,6 +185,15 @@ def widget_pixbuf(widget, maxsize=None):
|
||||||
|
|
||||||
return(scaledpixbuf)
|
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():
|
def get_config_dir():
|
||||||
"""Expand all the messy nonsense for finding where ~/.config/terminator
|
"""Expand all the messy nonsense for finding where ~/.config/terminator
|
||||||
really is"""
|
really is"""
|
||||||
|
|
Loading…
Reference in New Issue