Projet

Général

Profil

0001-misc-remove-auto-tenant-configuration-support-47823.patch

Frédéric Péters, 18 octobre 2020 10:32

Télécharger (7,72 ko)

Voir les différences:

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
tests/test_ctl.py
51 51
def test_loading():
52 52
    ctl = wcs.qommon.ctl.Ctl(cmd_prefixes=['wcs.ctl'])
53 53
    ctl.load_all_commands(ignore_errors=False)
54
    assert 'export_settings' in ctl.get_commands().keys()
54
    assert 'shell' in ctl.get_commands().keys()
55 55
    # call all __init__() methods
56 56
    for cmd in ctl.get_commands().values():
57 57
        cmd()
wcs/ctl/check_hobos.py
123 123
        if not os.path.exists(pub.app_dir):
124 124
            print('initializing instance in', pub.app_dir)
125 125
            os.mkdir(pub.app_dir)
126
            pub.initialize_app_dir()
127 126

  
128 127
            if service.get('template_name'):
129 128
                skeleton_filepath = os.path.join(global_app_dir, 'skeletons',
wcs/ctl/export_settings.py
1
# w.c.s. - web application for online forms
2
# Copyright (C) 2005-2010  Entr'ouvert
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, see <http://www.gnu.org/licenses/>.
16

  
17
from __future__ import print_function
18

  
19
import os
20

  
21
from ..qommon.ctl import Command, make_option
22

  
23

  
24
class CmdExportSettings(Command):
25
    name = 'export_settings'
26

  
27
    def __init__(self):
28
        Command.__init__(self, [
29
                make_option('--vhost', metavar='VHOST', action='store',
30
                            dest='vhost'),
31
                ])
32

  
33
    def execute(self, base_options, sub_options, args):
34
        from .. import publisher
35
        self.config.remove_option('main', 'error_log')
36
        publisher.WcsPublisher.configure(self.config)
37
        pub = publisher.WcsPublisher.create_publisher(
38
                register_tld_names=False)
39
        pub.app_dir = os.path.join(pub.app_dir, sub_options.vhost)
40
        pub.reload_cfg()
41
        print(pub.export_cfg())
42

  
43
CmdExportSettings.register()
wcs/qommon/publisher.py
92 92

  
93 93
    site_options = None
94 94
    site_charset = 'utf-8'
95
    default_configuration_path = None
96 95
    auto_create_appdir = True
97 96
    missing_appdir_redirect = None
98 97
    use_sms_feature = True
......
474 473
        except OSError: # already exists
475 474
            pass
476 475

  
477
    def initialize_app_dir(self):
478
        '''If empty initialize the application directory with default
479
        configuration. Returns True if initialization has been done.'''
480
        if self.default_configuration_path and len(os.listdir(self.app_dir)) == 0:
481
            # directory just got created, we should import some configuration...
482
            if os.path.isabs(self.default_configuration_path):
483
                path = self.default_configuration_path
484
            else:
485
                path = os.path.join(self.DATA_DIR, self.default_configuration_path)
486
            self.cfg = self.import_cfg(path)
487
            self.write_cfg()
488
            return True
489
        return False
490

  
491 476
    def init_publish(self, request):
492 477
        self.set_app_dir(request)
493 478

  
494
        self.initialize_app_dir()
495 479
        self.set_config(request)
496 480
        self._http_adapter = None
497 481

  
......
726 710
        except:
727 711
            self.cfg = {}
728 712

  
729
    def export_cfg(self):
730
        root = ET.Element('settings')
731
        for k in self.cfg:
732
            part = ET.SubElement(root, k)
733
            for k2 in self.cfg[k]:
734
                elem = ET.SubElement(part, k2)
735
                val = self.cfg[k][k2]
736
                if val is None:
737
                    pass
738

  
739
                elif type(val) is dict:
740
                    for k3, v3 in val.items():
741
                        ET.SubElement(elem, k3).text = str(v3)
742

  
743
                elif type(val) is list:
744
                    for v in val:
745
                        ET.SubElement(elem, 'item').text = v
746

  
747
                elif isinstance(val, six.string_types):
748
                    elem.text = val
749

  
750
                else:
751
                    elem.text = str(val)
752

  
753
        return ET.tostring(root)
754

  
755
    def import_cfg(self, filename):
756
        try:
757
            tree = ET.parse(open(filename))
758
        except:
759
            self.get_app_logger().warning('failed to import config from; failed to parse: %s', filename)
760
            raise
761

  
762
        if tree.getroot().tag != 'settings':
763
            self.get_app_logger().warning('failed to import config; not a settings file: %s', filename)
764
            return
765

  
766
        cfg = {}
767
        for elem in tree.getroot():
768
            sub_cfg = {}
769
            cfg[elem.tag] = sub_cfg
770
            for child in elem:
771
                sub_cfg[child.tag] = None
772
                if list(child):
773
                    if list(child)[0].tag == 'item':
774
                        # list
775
                        sub_cfg[child.tag] = []
776
                        for c in child:
777
                            value = force_str(c.text)
778
                            if value in ('True', 'False'):
779
                                value = (value == 'True')
780
                            sub_cfg[child.tag].append(value)
781
                    else:
782
                        # dict
783
                        sub_cfg[child.tag] = {}
784
                        for c in child:
785
                            value = force_str(c.text)
786
                            if value in ('True', 'False'):
787
                                value = (value == 'True')
788
                            sub_cfg[child.tag][c.tag] = c
789
                else:
790
                    text = child.text
791
                    if text is None:
792
                        sub_cfg[child.tag] = None
793
                        continue
794
                    text = force_str(text)
795
                    try:
796
                        sub_cfg[child.tag] = int(text)
797
                    except (ValueError, TypeError):
798
                        pass
799
                    else:
800
                        continue
801
                    if text in ('False', 'True'):
802
                        sub_cfg[child.tag] = bool(text == 'True')
803
                    else:
804
                        sub_cfg[child.tag] = text
805

  
806
        return cfg
807

  
808 713
    def process(self, stdin, env):
809 714
        request = HTTPRequest(stdin, env)
810 715
        self.response = self.process_request(request)
811
-