[jhbuild] Use XDG_CONFIG_DIR



commit b5685fc12a5faf1bf5124a6b63104284efda4edb
Author: William Jon McCann <jmccann redhat com>
Date:   Sat Apr 2 12:38:56 2011 -0400

    Use XDG_CONFIG_DIR
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646510

 jhbuild/config.py |    9 ++++++++-
 jhbuild/main.py   |    8 +++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 4e093c4..1864fb1 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -37,7 +37,12 @@ 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')
+if os.environ.has_key('XDG_CONFIG_HOME'):
+    _default_jhbuildrc = os.path.join(os.environ['XDG_CONFIG_HOME'], '.jhbuildrc')
+else:
+    _default_jhbuildrc = os.path.join(os.environ['HOME'], '.config', 'jhbuildrc')
+
+_old_default_jhbuildrc = os.path.join(os.environ['HOME'], '.jhbuildrc')
 
 _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'checkoutroot', 'buildroot', 'autogenargs', 'makeargs',
@@ -188,6 +193,8 @@ class Config:
         self._config['__file__'] = filename
         self.filename = filename
         if not os.path.exists(filename):
+            if os.path.exists(_old_default_jhbuildrc):
+                logging.warning(_('You may wish to move %s to %s'), _old_default_jhbuildrc, filename)
             raise FatalError(_('could not load config file, %s is missing') % filename)
 
         self.load()
diff --git a/jhbuild/main.py b/jhbuild/main.py
index 1ecc9c1..5e93f76 100644
--- a/jhbuild/main.py
+++ b/jhbuild/main.py
@@ -107,6 +107,12 @@ 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()
+
+    if os.environ.has_key('XDG_CONFIG_HOME'):
+        _default_jhbuildrc = os.path.join(os.environ['XDG_CONFIG_HOME'], '.jhbuildrc')
+    else:
+        _default_jhbuildrc = os.path.join(os.environ['HOME'], '.config', 'jhbuildrc')
+
     parser.add_option('-h', '--help', action='callback',
                       callback=lambda *args: print_help(parser),
                       help=_("Display this help and exit"))
@@ -115,7 +121,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", _default_jhbuildrc),
                       help=_('use a non default configuration file'))
     parser.add_option('-m', '--moduleset', action='store', metavar='URI',
                       type='string', dest='moduleset', default=None,



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