Commit 1f5848b1 authored by Craig Scott Keogh's avatar Craig Scott Keogh
Browse files

Use XDG_CONFIG_HOME & no config file (GNOME bug 646510, bug 655763)

Based on patch by Thomas Hindoe Paaboel Andersen
Based on patch by William Jon McCann
parent 27bd6824
# -*- mode: python -*-
# -*- coding: utf-8 -*-
# edit this file to match your settings and copy it to ~/.jhbuildrc
# edit this file to match your settings and copy it to ~/.config/jhbuildrc
# if you have a GNOME git account, uncomment this line
# repos['git.gnome.org'] = 'ssh://user@git.gnome.org/git/'
......
......@@ -38,7 +38,6 @@ if sys.platform.startswith('win'):
__all__ = [ 'Config' ]
_defaults_file = os.path.join(os.path.dirname(__file__), 'defaults.jhbuildrc')
_default_jhbuildrc = os.path.join(os.environ['HOME'], '.jhbuildrc')
_known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
'partial_build', 'checkoutroot', 'buildroot', 'top_builddir',
......@@ -151,7 +150,7 @@ def parse_relative_time(s):
class Config:
_orig_environ = None
def __init__(self, filename=_default_jhbuildrc):
def __init__(self, filename):
self._config = {
'__file__': _defaults_file,
'addpath': addpath,
......@@ -196,12 +195,39 @@ class Config:
except:
traceback.print_exc()
raise FatalError(_('could not load config defaults'))
self._config['__file__'] = filename
self.filename = filename
if not os.path.exists(filename):
raise FatalError(_('could not load config file, %s is missing') % filename)
self.load()
old_config = os.path.join(os.path.expanduser('~'), '.jhbuildrc')
new_config = os.path.join \
(os.environ.get \
('XDG_CONFIG_HOME',
os.path.join(os.path.expanduser('~'), '.config')),
'jhbuildrc')
if filename:
if not os.path.exists(filename):
raise FatalError(_('could not load config file, %s is missing') % filename)
else:
if os.path.isfile(old_config) \
and not os.path.islink(old_config) \
and os.path.isfile(new_config) \
and not os.path.islink(new_config):
raise FatalError(_('The default location of the configuration '
'file has changed. Please move %(old_path)s'
' to %(new_path)s.' \
% {'old_path': old_config,
'new_path': new_config}))
if os.path.exists(new_config):
filename = new_config
elif os.path.exists(old_config):
filename = old_config
if filename:
self._config['__file__'] = filename
self.filename = filename
else:
self._config['__file__'] = new_config
self.filename = new_config
self.load(filename)
self.setup_env()
def reload(self):
......@@ -217,18 +243,19 @@ class Config:
traceback.print_exc()
raise FatalError(_('Could not include config file (%s)') % filename)
def load(self):
def load(self, filename):
config = self._config
try:
execfile(self.filename, config)
except Exception, e:
if isinstance(e, FatalError):
# raise FatalErrors back, as it means an error in include()
# and it will print a traceback, and provide a meaningful
# message.
raise e
traceback.print_exc()
raise FatalError(_('could not load config file'))
if filename:
try:
execfile(filename, config)
except Exception, e:
if isinstance(e, FatalError):
# raise FatalErrors back, as it means an error in include()
# and it will print a traceback, and provide a meaningful
# message.
raise e
traceback.print_exc()
raise FatalError(_('could not load config file'))
if not config.get('quiet_mode'):
unknown_keys = []
......
# -*- mode: python -*-
# This file holds the default values for the ~/.jhbuildrc file.
# Do not copy this to ~/.jhbuildrc
# This file holds the default values for the ~/.config/jhbuildrc file.
# Do not copy this to ~/.config/jhbuildrc
import os, sys, tempfile
......
......@@ -107,6 +107,7 @@ def main(args):
add_help_option=False,
description=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).'))
parser.disable_interspersed_args()
parser.add_option('-h', '--help', action='callback',
callback=lambda *args: print_help(parser),
help=_("Display this help and exit"))
......@@ -115,7 +116,7 @@ def main(args):
help=optparse.SUPPRESS_HELP)
parser.add_option('-f', '--file', action='store', metavar='CONFIG',
type='string', dest='configfile',
default=os.environ.get("JHBUILDRC", os.path.join(os.environ['HOME'], '.jhbuildrc')),
default=os.environ.get("JHBUILDRC"),
help=_('use a non default configuration file'))
parser.add_option('-m', '--moduleset', action='store', metavar='URI',
type='string', dest='moduleset', default=None,
......
......@@ -497,5 +497,5 @@ def warn_local_modulesets(config):
logging.info(
_('Modulesets were edited locally but JHBuild is configured '\
'to get them from the network, perhaps you need to add '\
'use_local_modulesets = True to your .jhbuildrc.'))
'use_local_modulesets = True to your %s.' % config.filename))
......@@ -71,7 +71,9 @@ class BzrRepository(Repository):
if name in self.config.branches:
module_href = self.config.branches[name]
if not module_href:
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
raise FatalError(_('branch for %(name)s has wrong override, check your %(filename)s') % \
{'name' : name,
'filename' : self.config.filename})
if module is None:
module = name
......
......@@ -52,7 +52,9 @@ class DarcsRepository(Repository):
if name in self.config.branches:
module = self.config.branches[name]
if not module:
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
raise FatalError(_('branch for %(name)s has wrong override, check your %(filename)s') % \
{'name' : name,
'filename' : self.config.filename})
else:
if module is None:
module = name
......
......@@ -46,7 +46,9 @@ class FossilRepository(Repository):
if name in self.config.branches:
module = self.config.branches[name]
if not module:
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
raise FatalError(_('branch for %(name)s has wrong override, check your %(filename)s') % \
{'name' : name,
'filename' : self.config.filename})
else:
if module is None:
module = name
......
......@@ -50,7 +50,9 @@ class HgRepository(Repository):
if name in self.config.branches:
module = self.config.branches[name]
if not module:
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
raise FatalError(_('branch for %(name)s has wrong override, check your %(filename)s') % \
{'name' : name,
'filename' : self.config.filename})
else:
if module is None:
module = name
......
......@@ -49,7 +49,9 @@ class MonotoneRepository(Repository):
if name in self.config.branches:
module = self.config.branches[module]
if not module:
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
raise FatalError(_('branch for %(name)s has wrong override, check your %(filename)s') % \
{'name' : name,
'filename' : self.config.filename})
if not branch:
branch = self.defbranch
......
......@@ -64,7 +64,9 @@ class TarballRepository(Repository):
if name in self.config.branches:
module = self.config.branches[name]
if not module:
raise FatalError(_('branch for %s has wrong override, check your .jhbuildrc') % name)
raise FatalError(_('branch for %(name)s has wrong override, check your %(filename)s') % \
{'name' : name,
'filename' : self.config.filename})
else:
if module is None:
module = name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment