config: Deprecate legacy config sections
authorGuido Günther <agx@sigxcpu.org>
Tue, 18 Feb 2014 21:55:45 +0000 (22:55 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sun, 25 Jan 2015 14:15:02 +0000 (15:15 +0100)
We deprecate sections starting with git- and gbp- to reduce the
confusion about what gets parsed first.

gbp/config.py
tests/18_test_Config.py

index 9469f0b82224056490059da424cc7a61952e5d1d..2ca722782835c0579b399a4eee073e570285d7ea 100644 (file)
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """handles command line and config file option parsing for the gbp commands"""
 
+import sys
 from optparse import OptionParser, OptionGroup, Option, OptionValueError
 from ConfigParser import SafeConfigParser, NoSectionError
 from copy import copy
 import os.path
+
 try:
     from gbp.version import gbp_version
 except ImportError:
     gbp_version = "[Unknown version]"
 import gbp.tristate
+import gbp.log
 from gbp.git import GitRepositoryError, GitRepository
 
 no_upstream_branch_msg = """
@@ -385,16 +388,20 @@ class GbpOptionParser(OptionParser):
         # section i.e. read [gbp-pull] prior to [pull]
         if (self.command.startswith('gbp-') or
             self.command.startswith('git-')):
+            cmd = self.command[4:]
             oldcmd = self.command
             if parser.has_section(oldcmd):
                 self.config.update(dict(parser.items(oldcmd, raw=True)))
-            cmd = self.command[4:]
+                gbp.log.warn("Old style config section [%s] found "
+                             "please rename to [%s]" % (oldcmd, cmd))
         else:
+            cmd = self.command
             for prefix in ['gbp', 'git']:
                 oldcmd = '%s-%s' % (prefix, self.command)
                 if parser.has_section(oldcmd):
                     self.config.update(dict(parser.items(oldcmd, raw=True)))
-            cmd = self.command
+                    gbp.log.warn("Old style config section [%s] found "
+                                 "please rename to [%s]" % (oldcmd, cmd))
 
         # Update with command specific settings
         if parser.has_section(cmd):
index f7ba8c9c629cb530b7a2fe82c09cfc2b5f9b6263..1560ece4f10aacfcbe3d292be6e61153de5597d0 100644 (file)
@@ -1,20 +1,27 @@
 # vim: set fileencoding=utf-8 :
 
 import os
+import sys
 import unittest
 from gbp.config import GbpOptionParser, GbpOptionGroup
-from . import context
+from . testutils import GbpLogTester
+
+class TestConfigParser(unittest.TestCase, GbpLogTester):
+    def __init__(self, methodName='runTest'):
+        unittest.TestCase.__init__(self, methodName)
+        GbpLogTester.__init__(self)
 
-class TestConfigParser(unittest.TestCase):
     def setUp(self):
         self.conffiles_save = os.environ.get('GBP_CONF_FILES')
         self.confname = 'tests/data/test1.conf'
         self.assertTrue(os.stat(self.confname))
         os.environ['GBP_CONF_FILES'] = self.confname
+        self._capture_log(True)
 
     def tearDown(self):
         if self.conffiles_save:
             os.environ['GBP_CONF_FILES'] = self.conffiles_save
+        self._capture_log(False)
 
     def test_default(self):
         """
@@ -32,6 +39,8 @@ class TestConfigParser(unittest.TestCase):
         for prefix in [ '', 'git-', 'gbp-' ]:
             parser = GbpOptionParser('%scmd1' % prefix)
             self.assertEqual(parser.config['single_override_option1'], 'single_override_value1')
+        # No deprecation warning since we test1.conf section is [cmd1]
+        self.assertEqual(self._get_log(), [])
 
     def test_single_git_override(self):
         """
@@ -40,6 +49,8 @@ class TestConfigParser(unittest.TestCase):
         for prefix in [ '', 'git-' ]:
             parser = GbpOptionParser('%scmd2' % prefix)
             self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1')
+        for line in range(0,2):
+            self._check_log(line, ".*Old style config section \[git-cmd2\] found please rename to \[cmd2\]")
 
     def test_single_gbp_override(self):
         """
@@ -48,7 +59,9 @@ class TestConfigParser(unittest.TestCase):
         for prefix in [ '', 'gbp-' ]:
             parser = GbpOptionParser('%scmd3' % prefix)
             self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1')
-        # FIXME: for all prefixes
+        for line in range(0,2):
+            self._check_log(line, ".*Old style config section \[gbp-cmd3\] found please rename to \[cmd3\]")
+
 
     def test_new_overrides_git(self):
         """
@@ -65,7 +78,7 @@ class TestConfigParser(unittest.TestCase):
 
     def test_get_config_file_value(self):
         """
-        Read a single value from the parse config
+        Read a single value from the parsed config
         """
         parser = GbpOptionParser('cmd4')
         self.assertEqual(parser.get_config_file_value('new_overrides_git_option1'),