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



commit 1f5848b16522de6a29e5119eacca86a4fd266935
Author: Craig Keogh <cskeogh adam com au>
Date:   Tue Aug 30 09:51:36 2011 +0930

    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

 examples/sample.jhbuildrc         |    2 +-
 jhbuild/config.py                 |   63 ++++++++++++++++++++++++++----------
 jhbuild/defaults.jhbuildrc        |    4 +-
 jhbuild/main.py                   |    3 +-
 jhbuild/moduleset.py              |    2 +-
 jhbuild/versioncontrol/bzr.py     |    4 ++-
 jhbuild/versioncontrol/darcs.py   |    4 ++-
 jhbuild/versioncontrol/fossil.py  |    4 ++-
 jhbuild/versioncontrol/hg.py      |    4 ++-
 jhbuild/versioncontrol/mtn.py     |    4 ++-
 jhbuild/versioncontrol/tarball.py |    4 ++-
 11 files changed, 69 insertions(+), 29 deletions(-)
---
diff --git a/examples/sample.jhbuildrc b/examples/sample.jhbuildrc
index a1179cd..ef398c9 100644
--- a/examples/sample.jhbuildrc
+++ b/examples/sample.jhbuildrc
@@ -1,7 +1,7 @@
 # -*- 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/'
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 6c3f03d..5b5b26b 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -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 = []
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index 6df6238..1b0cff6 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -1,6 +1,6 @@
 # -*- 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
 
diff --git a/jhbuild/main.py b/jhbuild/main.py
index d34c3f2..e0927cd 100644
--- a/jhbuild/main.py
+++ b/jhbuild/main.py
@@ -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,
diff --git a/jhbuild/moduleset.py b/jhbuild/moduleset.py
index 9fc45a3..1403756 100644
--- a/jhbuild/moduleset.py
+++ b/jhbuild/moduleset.py
@@ -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))
 
diff --git a/jhbuild/versioncontrol/bzr.py b/jhbuild/versioncontrol/bzr.py
index 5df28f3..9a43d3b 100644
--- a/jhbuild/versioncontrol/bzr.py
+++ b/jhbuild/versioncontrol/bzr.py
@@ -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
diff --git a/jhbuild/versioncontrol/darcs.py b/jhbuild/versioncontrol/darcs.py
index ed61975..1e08456 100644
--- a/jhbuild/versioncontrol/darcs.py
+++ b/jhbuild/versioncontrol/darcs.py
@@ -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
diff --git a/jhbuild/versioncontrol/fossil.py b/jhbuild/versioncontrol/fossil.py
index 20dcb09..172072c 100644
--- a/jhbuild/versioncontrol/fossil.py
+++ b/jhbuild/versioncontrol/fossil.py
@@ -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
diff --git a/jhbuild/versioncontrol/hg.py b/jhbuild/versioncontrol/hg.py
index cab5ecf..2ac47ee 100644
--- a/jhbuild/versioncontrol/hg.py
+++ b/jhbuild/versioncontrol/hg.py
@@ -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
diff --git a/jhbuild/versioncontrol/mtn.py b/jhbuild/versioncontrol/mtn.py
index 8d5bf1b..9126bfa 100644
--- a/jhbuild/versioncontrol/mtn.py
+++ b/jhbuild/versioncontrol/mtn.py
@@ -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
diff --git a/jhbuild/versioncontrol/tarball.py b/jhbuild/versioncontrol/tarball.py
index f4733d8..0a3ebf0 100644
--- a/jhbuild/versioncontrol/tarball.py
+++ b/jhbuild/versioncontrol/tarball.py
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]