changeset 8191:eb6ffd819900

py3: fix kallithea-cli ini parsing after ConfigParser got strict=True ConfigParser in py3 defaults to strict=True and would thus reject our ssh logging hack of renaming config sections ... which cause duplicate section names. Fortunately, fileConfig now also allows passing a ConfigParser, and we can avoid using io.StringIO .
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 25 Dec 2019 01:57:05 +0100
parents 08af13a090e0
children b7caa806cf6e
files kallithea/bin/kallithea_cli_base.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_base.py	Sat Jan 25 19:53:56 2020 +0100
+++ b/kallithea/bin/kallithea_cli_base.py	Wed Dec 25 01:57:05 2019 +0100
@@ -12,8 +12,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import configparser
 import functools
-import io
 import logging.config
 import os
 import re
@@ -45,7 +45,7 @@
         return m.group(0)
 
     with open(ini_file_name) as f:
-        return re.sub(r'^\[([^:]+):(.*)]', repl, f.read().decode(), flags=re.MULTILINE)
+        return re.sub(r'^\[([^:]+):(.*)]', repl, f.read(), flags=re.MULTILINE)
 
 
 # This placeholder is the main entry point for the kallithea-cli command
@@ -72,8 +72,9 @@
             def runtime_wrapper(config_file, *args, **kwargs):
                 path_to_ini_file = os.path.realpath(config_file)
                 kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
-                config_string = read_config(path_to_ini_file, strip_section_prefix=annotated.__name__)
-                logging.config.fileConfig(io.StringIO(config_string),
+                cp = configparser.ConfigParser(strict=False)
+                cp.read_string(read_config(path_to_ini_file, strip_section_prefix=annotated.__name__))
+                logging.config.fileConfig(cp,
                     {'__file__': path_to_ini_file, 'here': os.path.dirname(path_to_ini_file)})
                 if config_file_initialize_app:
                     kallithea.config.middleware.make_app(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)