From 0dc6de81e3a29a64703c9dbd0ec4eb0ad1ec394c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Sat, 17 Oct 2020 22:21:49 +0200
Subject: [PATCH 1/2] misc: remove auto-tenant configuration support (#47823)

---
 tests/test_ctl.py          |  2 +-
 wcs/ctl/check_hobos.py     |  1 -
 wcs/ctl/export_settings.py | 43 -----------------
 wcs/qommon/publisher.py    | 95 --------------------------------------
 4 files changed, 1 insertion(+), 140 deletions(-)
 delete mode 100644 wcs/ctl/export_settings.py

diff --git a/tests/test_ctl.py b/tests/test_ctl.py
index 0cbe61b42..2ef3859f5 100644
--- a/tests/test_ctl.py
+++ b/tests/test_ctl.py
@@ -51,7 +51,7 @@ def teardown_module(module):
 def test_loading():
     ctl = wcs.qommon.ctl.Ctl(cmd_prefixes=['wcs.ctl'])
     ctl.load_all_commands(ignore_errors=False)
-    assert 'export_settings' in ctl.get_commands().keys()
+    assert 'shell' in ctl.get_commands().keys()
     # call all __init__() methods
     for cmd in ctl.get_commands().values():
         cmd()
diff --git a/wcs/ctl/check_hobos.py b/wcs/ctl/check_hobos.py
index f79d90a5b..5cc57e86b 100644
--- a/wcs/ctl/check_hobos.py
+++ b/wcs/ctl/check_hobos.py
@@ -123,7 +123,6 @@ class CmdCheckHobos(Command):
         if not os.path.exists(pub.app_dir):
             print('initializing instance in', pub.app_dir)
             os.mkdir(pub.app_dir)
-            pub.initialize_app_dir()
 
             if service.get('template_name'):
                 skeleton_filepath = os.path.join(global_app_dir, 'skeletons',
diff --git a/wcs/ctl/export_settings.py b/wcs/ctl/export_settings.py
deleted file mode 100644
index 5f74855bb..000000000
--- a/wcs/ctl/export_settings.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# w.c.s. - web application for online forms
-# Copyright (C) 2005-2010  Entr'ouvert
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-
-from __future__ import print_function
-
-import os
-
-from ..qommon.ctl import Command, make_option
-
-
-class CmdExportSettings(Command):
-    name = 'export_settings'
-
-    def __init__(self):
-        Command.__init__(self, [
-                make_option('--vhost', metavar='VHOST', action='store',
-                            dest='vhost'),
-                ])
-
-    def execute(self, base_options, sub_options, args):
-        from .. import publisher
-        self.config.remove_option('main', 'error_log')
-        publisher.WcsPublisher.configure(self.config)
-        pub = publisher.WcsPublisher.create_publisher(
-                register_tld_names=False)
-        pub.app_dir = os.path.join(pub.app_dir, sub_options.vhost)
-        pub.reload_cfg()
-        print(pub.export_cfg())
-
-CmdExportSettings.register()
diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py
index b3c4ba848..079df402a 100644
--- a/wcs/qommon/publisher.py
+++ b/wcs/qommon/publisher.py
@@ -92,7 +92,6 @@ class QommonPublisher(Publisher, object):
 
     site_options = None
     site_charset = 'utf-8'
-    default_configuration_path = None
     auto_create_appdir = True
     missing_appdir_redirect = None
     use_sms_feature = True
@@ -474,24 +473,9 @@ class QommonPublisher(Publisher, object):
         except OSError: # already exists
             pass
 
-    def initialize_app_dir(self):
-        '''If empty initialize the application directory with default
-        configuration. Returns True if initialization has been done.'''
-        if self.default_configuration_path and len(os.listdir(self.app_dir)) == 0:
-            # directory just got created, we should import some configuration...
-            if os.path.isabs(self.default_configuration_path):
-                path = self.default_configuration_path
-            else:
-                path = os.path.join(self.DATA_DIR, self.default_configuration_path)
-            self.cfg = self.import_cfg(path)
-            self.write_cfg()
-            return True
-        return False
-
     def init_publish(self, request):
         self.set_app_dir(request)
 
-        self.initialize_app_dir()
         self.set_config(request)
         self._http_adapter = None
 
@@ -726,85 +710,6 @@ class QommonPublisher(Publisher, object):
         except:
             self.cfg = {}
 
-    def export_cfg(self):
-        root = ET.Element('settings')
-        for k in self.cfg:
-            part = ET.SubElement(root, k)
-            for k2 in self.cfg[k]:
-                elem = ET.SubElement(part, k2)
-                val = self.cfg[k][k2]
-                if val is None:
-                    pass
-
-                elif type(val) is dict:
-                    for k3, v3 in val.items():
-                        ET.SubElement(elem, k3).text = str(v3)
-
-                elif type(val) is list:
-                    for v in val:
-                        ET.SubElement(elem, 'item').text = v
-
-                elif isinstance(val, six.string_types):
-                    elem.text = val
-
-                else:
-                    elem.text = str(val)
-
-        return ET.tostring(root)
-
-    def import_cfg(self, filename):
-        try:
-            tree = ET.parse(open(filename))
-        except:
-            self.get_app_logger().warning('failed to import config from; failed to parse: %s', filename)
-            raise
-
-        if tree.getroot().tag != 'settings':
-            self.get_app_logger().warning('failed to import config; not a settings file: %s', filename)
-            return
-
-        cfg = {}
-        for elem in tree.getroot():
-            sub_cfg = {}
-            cfg[elem.tag] = sub_cfg
-            for child in elem:
-                sub_cfg[child.tag] = None
-                if list(child):
-                    if list(child)[0].tag == 'item':
-                        # list
-                        sub_cfg[child.tag] = []
-                        for c in child:
-                            value = force_str(c.text)
-                            if value in ('True', 'False'):
-                                value = (value == 'True')
-                            sub_cfg[child.tag].append(value)
-                    else:
-                        # dict
-                        sub_cfg[child.tag] = {}
-                        for c in child:
-                            value = force_str(c.text)
-                            if value in ('True', 'False'):
-                                value = (value == 'True')
-                            sub_cfg[child.tag][c.tag] = c
-                else:
-                    text = child.text
-                    if text is None:
-                        sub_cfg[child.tag] = None
-                        continue
-                    text = force_str(text)
-                    try:
-                        sub_cfg[child.tag] = int(text)
-                    except (ValueError, TypeError):
-                        pass
-                    else:
-                        continue
-                    if text in ('False', 'True'):
-                        sub_cfg[child.tag] = bool(text == 'True')
-                    else:
-                        sub_cfg[child.tag] = text
-
-        return cfg
-
     def process(self, stdin, env):
         request = HTTPRequest(stdin, env)
         self.response = self.process_request(request)
-- 
2.28.0

