misc: remove auto-tenant configuration support (#47823)

This commit is contained in:
Frédéric Péters 2020-10-17 22:21:49 +02:00
parent ec58f1e2bd
commit 760962edc1
4 changed files with 1 additions and 140 deletions

View File

@ -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()

View File

@ -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',

View File

@ -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()

View File

@ -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)