Projet

Général

Profil

wcs.manageconfigfile.diff

Jérôme Schneider, 30 décembre 2011 19:17

Télécharger (13,2 ko)

Voir les différences:


  

wcs.cfg-sample
1
[main]
2
app_dir = /var/lib/wcs
3
data_dir = /usr/share/wcs
4
auto_create_vhosts = true
5
use_long_traces = true
6
#error_log = /var/log/wcs/error.log
7
#redirect_on_unknown_vhost = http://www.mysite.com
wcs/ctl/apply_timeouts.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, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
# 02110-1301  USA
18

  
19
from qommon.ctl import Command, make_option
20

  
21
class CmdApplyTimeouts(Command):
22
    name = 'apply_timeouts'
23

  
24
    def __init__(self):
25
        Command.__init__(self, [
26
                make_option('--extra', metavar='DIR', action='append',
27
                            dest='extra', default=[]),
28
                make_option('--app-dir', metavar='DIR', action='store',
29
                            dest='app_dir', default=None),
30
                make_option('--data-dir', metavar='DIR', action='store',
31
                            dest='data_dir', default=None),
32
                make_option('--silent', action='store_true',
33
                            dest='silent', default=False),
34
                ])
35

  
36
    def execute(self, options, args):
37
        import wcs.workflows as workflows
38
        import publisher
39

  
40
        if options.app_dir:
41
            publisher.WcsPublisher.APP_DIR = options.app_dir
42
        if options.data_dir:
43
            publisher.WcsPublisher.DATA_DIR = options.data_dir
44
        if options.silent:
45
            sys.stdout = file('/dev/null', 'w')
46
            sys.stderr = file('/dev/null', 'w')
47

  
48
        pub = publisher.WcsPublisher.create_publisher()
49
        workflows.apply_timeouts()
50

  
51
CmdApplyTimeouts.register()
wcs/ctl/clean_sessions.py
40 40
class CmdCleanSessions(Command):
41 41
    name = 'clean_sessions'
42 42

  
43
    def execute(self, options, args):
43
    def execute(self, base_options, sub_options, args):
44 44
        import publisher
45 45

  
46
        publisher.WcsPublisher.configure(self.config, sub_options.extra)
46 47
        pub = publisher.WcsPublisher.create_publisher()
47 48

  
48 49
        app_dir = pub.app_dir
wcs/ctl/export_settings.py
30 30
                            dest='vhost'),
31 31
                ])
32 32

  
33
    def execute(self, options, args):
33
    def execute(self, base_options, sub_options, args):
34 34
        import publisher
35 35
        stdout = sys.stdout
36
        publisher.WcsPublisher.configure(self.config, sub_options.extra)
36 37
        pub = publisher.WcsPublisher.create_publisher()
37
        pub.app_dir = os.path.join(pub.app_dir, options.vhost)
38
        pub.app_dir = os.path.join(pub.app_dir, sub_options.vhost)
38 39
        pub.reload_cfg()
39 40
        print >> stdout, pub.export_cfg()
40 41

  
wcs/ctl/process_bounce.py
31 31
class CmdProcessBounce(Command):
32 32
    name = 'process_bounce'
33 33

  
34
    def execute(self, options, args):
34
    def execute(self, base_options, sub_options, args):
35 35
        from qommon.tokens import Token
36 36
        from qommon.bounces import Bounce
37 37

  
......
59 59
            except (IndexError, KeyError):
60 60
                return
61 61

  
62
            publisher.WcsPublisher.configure(self.config, sub_options.extra)
62 63
            pub = publisher.WcsPublisher.create_publisher()
63 64
            pub.app_dir = os.path.join(pub.app_dir, server_part)
64 65

  
wcs/ctl/rebuild_indexes.py
42 42
                            dest='all', default=False),
43 43
                make_option('--destroy', action='store_true',
44 44
                            dest='destroy', default=False),
45
                make_option('--extra', metavar='DIR', action='append',
46
                            dest='extra', default=[]),
47 45
                ])
48 46

  
49
    def execute(self, options, args):
47
    def execute(self, base_options, sub_options, args):
50 48
        import publisher
51 49

  
52
        for directory in options.extra:
53
            publisher.WcsPublisher.register_extra_dir(directory)
54

  
50
        publisher.WcsPublisher.configure(self.config, sub_options.extra)
55 51
        pub = publisher.WcsPublisher.create_publisher()
56 52

  
57 53
        app_dir = pub.app_dir
58
        if options.all:
54
        if sub_options.all:
59 55
            hostnames = os.listdir(app_dir)
60 56
        else:
61 57
            hostnames = args
62 58
        for hostname in hostnames:
63 59
            pub.app_dir = os.path.join(app_dir, hostname)
64
            rebuild_vhost_indexes(destroy=options.destroy)
60
            rebuild_vhost_indexes(destroy=sub_options.destroy)
65 61

  
66 62
CmdRebuildIndexes.register()
wcs/ctl/start.py
30 30
        Command.__init__(self, [
31 31
                make_option('--port', metavar='PORT', action='store',
32 32
                            dest='port', default=3001),
33
                make_option('--extra', metavar='DIR', action='append',
34
                            dest='extra', default=[]),
35 33
                make_option('--handler-connection-limit', metavar='LIMIT',
36 34
                            action='store',
37 35
                            dest='handler_connection_limit', default=None),
38 36
                make_option('--script-name', metavar='NAME', action='store',
39 37
                            dest='script_name', default=None),
40
                make_option('--app-dir', metavar='DIR', action='store',
41
                            dest='app_dir', default=None),
42
                make_option('--data-dir', metavar='DIR', action='store',
43
                            dest='data_dir', default=None),
44 38
                make_option('--http', action='store_true',
45 39
                            dest='http', default=False),
46 40
                make_option('--silent', action='store_true',
47 41
                            dest='silent', default=False),
48 42
                ])
49 43

  
50
    def execute(self, options, args):
44
    def execute(self, base_options, sub_options, args):
51 45
        import publisher
52 46

  
53 47
        run_kwargs = {}
54
        run_kwargs['port'] = int(options.port)
48
        run_kwargs['port'] = int(sub_options.port)
55 49
        run_kwargs['spawn_cron'] = True
56 50
        run_function = qommon.scgi_server.run
57
        for directory in options.extra:
58
            publisher.WcsPublisher.register_extra_dir(directory)
59
        if options.handler_connection_limit:
60
            run_kwargs['handler_connection_limit'] = int(options.handler_connection_limit)
61
        if options.script_name:
62
            run_kwargs['script_name'] = options.script_name
63
        if options.app_dir:
64
            publisher.WcsPublisher.APP_DIR = options.app_dir
65
        if options.data_dir:
66
            publisher.WcsPublisher.DATA_DIR = options.data_dir
67
        if options.http:
51
        publisher.WcsPublisher.configure(self.config, sub_options.extra)
52
        if sub_options.handler_connection_limit:
53
            run_kwargs['handler_connection_limit'] = int(sub_options.handler_connection_limit)
54
        if sub_options.script_name:
55
            run_kwargs['script_name'] = sub_options.script_name
56
        if sub_options.http:
68 57
            run_function = qommon.scgi_server.http_run
69
        if options.silent:
58
        if sub_options.silent:
70 59
            sys.stdout = file('/dev/null', 'w')
71 60
            sys.stderr = file('/dev/null', 'w')
72 61

  
wcs/publisher.py
89 89
        return admin
90 90
    get_admin_module = classmethod(get_admin_module)
91 91

  
92
    def configure(cls, config, extra=[]):
93
        for directory in extra:
94
            cls.register_extra_dir(directory)
95

  
96
        if config.has_option("main", "app_dir"):
97
            cls.APP_DIR = config.get("main", "app_dir")
98
        if config.has_option("main", "data_dir"):
99
            cls.DATA_DIR = config.get("main", "data_dir")
100
        if config.has_option("main", "error_log"):
101
            cls.ERROR_LOG = config.get("main", "error_log")
102
        if config.has_option("main", "use_long_traces"):
103
            cls.USE_LONG_TRACES = config.getboolean("main",
104
                    "use_long_traces")
105
        if config.has_option("main", "auto_create_vhosts"):
106
            cls.auto_create_appdir = config.getboolean("main",
107
                    "auto_create_vhosts")
108
        if config.has_option("main", "redirect_on_unknown_vhost"):
109
            cls.missing_appdir_redirect = config.get("main",
110
                    "redirect_on_unknown_vhost")
111
    configure = classmethod(configure)
112

  
92 113
    def set_config(self, request = None):
93 114
        QommonPublisher.set_config(self, request = request)
94 115
        filename = os.path.join(self.app_dir, 'config.pck')
wcs/qommon/cron.py
80 80
    global cron_pid
81 81
    cron_pid = os.fork()
82 82
    if cron_pid == 0:
83
        print >>sys.stderr, 'Cron process launched'
84 83
        pub = create_publisher()
85 84
        # set process name, this only works on Linux, 15 == PR_SET_NAME
86 85
        if dl:
wcs/qommon/ctl.py
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 17
# 02110-1301  USA
18 18

  
19
import ConfigParser
19 20
import optparse
20 21
from optparse import make_option
21 22
import sys
......
35 36
    usage_args = '[ options ... ]'
36 37

  
37 38
    def __init__(self, options=[]):
38
        self.options = options
39
        self.config = ConfigParser.ConfigParser()
40
        self.options = options + [
41
                    make_option('--extra', metavar='DIR', action='append',
42
                        dest='extra', default=[]),
43
                    make_option('--app-dir', metavar='DIR', action='store',
44
                        dest='app_dir', default=None),
45
                    make_option('--data-dir', metavar='DIR', action='store',
46
                        dest='data_dir', default=None),
47
                    ]
39 48

  
40
    def run(self, args):
41
        options, args = self.parse_args(args)
42
        return self.execute(options, args)
49
    def run(self, args, base_options):
50
        if base_options.configfile:
51
            try:
52
                self.config.read(base_options.configfile)
53
            except ConfigParser.ParsingError, e:
54
                print >> sys.stderr, 'Invalid configuration file %s' % base_options.configfile
55
                print >> sys.stderr, e
56
                print >> sys.stderr, 'Using default options'
57
        if not self.config.has_section('main'):
58
            self.config.add_section('main')
59
        sub_options, args = self.parse_args(args)
60
        if sub_options.app_dir:
61
            self.config.set("main", "app_dir", sub_options.app_dir)
62
        if sub_options.data_dir:
63
            self.config.set("main", "data_dir", sub_options.data_dir)
64
        return self.execute(base_options, sub_options, args)
43 65

  
44 66
    def parse_args(self, args):
45 67
        self.parser = optparse.OptionParser(
......
48 70
        self.parser.add_options(self.options)
49 71
        return self.parser.parse_args(args)
50 72

  
51
    def execute(self, options, args):
73
    def execute(self, base_options, sub_options, args):
52 74
        """The body of the command"""
53 75
        raise NotImplementedError
54 76

  
......
103 125

  
104 126
    def run(self, args):
105 127
        options, args = self.parser.parse_args(args)
128
        if not args:
129
            self.parser.error("You must use a command")
106 130
        command, args = args[0], args[1:]
107 131
        if command not in qommon._commands:
108 132
            for cmd_prefix in self.cmd_prefixes:
......
112 136
                    pass
113 137
        command_class = qommon._commands[command]
114 138
        cmd = command_class()
115
        return cmd.run(args)
139
        return cmd.run(args, options)
116 140