summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2012-05-16 09:16:40 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2014-09-19 12:48:52 (GMT)
commitb4ad231eee7294f20ef06137661c79390a6de0c0 (patch)
tree1ca9e07d59a6143c9b39f87398241900067536ab
parent10150c50aaec994c708b7d1e8b78fd8cd4dd82a0 (diff)
downloadpratic-b4ad231eee7294f20ef06137661c79390a6de0c0.zip
pratic-b4ad231eee7294f20ef06137661c79390a6de0c0.tar.gz
pratic-b4ad231eee7294f20ef06137661c79390a6de0c0.tar.bz2
wcsinst: change startup script to use a configuration file
-rw-r--r--wcsinst/setup.py7
-rw-r--r--wcsinst/wcsinst/ctl/start.py99
-rw-r--r--wcsinst/wcsinst/insts.py9
-rw-r--r--wcsinst/wcsinst/publisher.py26
-rwxr-xr-xwcsinst/wcsinstctl.py20
5 files changed, 98 insertions, 63 deletions
diff --git a/wcsinst/setup.py b/wcsinst/setup.py
index 9888f01..5cda693 100644
--- a/wcsinst/setup.py
+++ b/wcsinst/setup.py
@@ -4,11 +4,6 @@ import os
import distutils.core
from quixote.ptl.qx_distutils import qx_build_py
-local_cfg = None
-if os.path.exists('wcsinst/wcsinst_cfg.py'):
- local_cfg = file('wcsinst/wcsinst_cfg.py').read()
- os.unlink('wcsinst/wcsinst_cfg.py')
-
def data_tree(destdir, sourcedir):
extensions = ['.css', '.png', '.jpeg', '.jpg', '.xml', '.html', '.js', '.ezt', '.gif']
r = []
@@ -37,5 +32,3 @@ distutils.core.setup(
data_files = data_tree('share/authentic/themes/', 'theme/'),
)
-if local_cfg:
- file('wcsinst/wcsinst_cfg.py', 'w').write(local_cfg)
diff --git a/wcsinst/wcsinst/ctl/start.py b/wcsinst/wcsinst/ctl/start.py
index a8df6c1..51b7259 100644
--- a/wcsinst/wcsinst/ctl/start.py
+++ b/wcsinst/wcsinst/ctl/start.py
@@ -1,30 +1,77 @@
+# wcsinst - w.c.s. deployment server
+# Copyright (C) 2007-2012 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/>.
+
import socket
import sys
-from quixote.server.scgi_server import run
-
-import publisher
-
-def start(args):
- run_kwargs = {}
- run_kwargs['port'] = 3954
-
- i = 0
- while i < len(args):
- if args[i] == '--port':
- run_kwargs['port'] = int(args[i+1])
- i += 1
- elif args[i] == '--script-name':
- run_kwargs['script_name'] = args[i+1]
- i += 1
- i += 1
-
- try:
- run(publisher.WcsInstPublisher.create_publisher, **run_kwargs)
- except socket.error, e:
- if e[0] == 98:
- print >> sys.stderr, 'address already in use'
+import qommon.scgi_server
+import quixote.server.simple_server
+
+from qommon.ctl import Command, make_option
+
+class CmdStart(Command):
+ name = 'start'
+
+ def __init__(self):
+ Command.__init__(self, [
+ make_option('--port', metavar='PORT', action='store',
+ dest='port', default=3954),
+ make_option('--handler-connection-limit', metavar='LIMIT',
+ action='store',
+ dest='handler_connection_limit', default=None),
+ make_option('--script-name', metavar='NAME', action='store',
+ dest='script_name', default=None),
+ make_option('--http', action='store_true',
+ dest='http', default=False),
+ make_option('--silent', action='store_true',
+ dest='silent', default=False),
+ make_option('--max-children', metavar='MAX_CHILDREN',
+ type='int', action='store', dest='max_children')
+ ])
+
+ def execute(self, base_options, sub_options, args):
+ import publisher
+
+ run_kwargs = {}
+ run_kwargs['port'] = int(sub_options.port)
+ run_kwargs['spawn_cron'] = False
+ run_function = qommon.scgi_server.run
+ publisher.WcsInstPublisher.configure(self.config, sub_options.extra)
+ if sub_options.handler_connection_limit:
+ run_kwargs['handler_connection_limit'] = int(sub_options.handler_connection_limit)
+ if sub_options.script_name:
+ run_kwargs['script_name'] = sub_options.script_name
+ if sub_options.max_children:
+ run_kwargs['max_children'] = sub_options.max_children
+ elif self.config.has_option('main', 'max_children'):
+ run_kwargs['max_children'] = self.config.getint('main', 'max_children')
+ if sub_options.http:
+ run_function = qommon.scgi_server.http_run
+ if sub_options.silent:
+ sys.stdout = file('/dev/null', 'w')
+ sys.stderr = file('/dev/null', 'w')
+
+ try:
+ run_function(publisher.WcsInstPublisher.create_publisher, **run_kwargs)
+ except socket.error, e:
+ if e[0] == 98:
+ print >> sys.stderr, 'address already in use'
+ sys.exit(1)
+ raise
+ except KeyboardInterrupt:
sys.exit(1)
- raise
- except KeyboardInterrupt:
- sys.exit(1)
+
+CmdStart.register()
diff --git a/wcsinst/wcsinst/insts.py b/wcsinst/wcsinst/insts.py
index 486c764..9050757 100644
--- a/wcsinst/wcsinst/insts.py
+++ b/wcsinst/wcsinst/insts.py
@@ -51,14 +51,7 @@ class Inst(StorableObject):
if path:
coldir += path.replace('/', '+')
- try:
- import wcs.wcs_cfg
- wcs_app_dir = wcs.wcs_cfg.APP_DIR
- except (ImportError, AttributeError):
- import wcs.Defaults
- wcs_app_dir = wcs.Defaults.APP_DIR
-
- col_inst_dir = os.path.join(wcs_app_dir, coldir)
+ col_inst_dir = os.path.join(get_publisher().wcs_app_dir, coldir)
if os.path.exists(col_inst_dir):
shutil.rmtree(col_inst_dir) # XXX: or abort?
diff --git a/wcsinst/wcsinst/publisher.py b/wcsinst/wcsinst/publisher.py
index dc46aef..4b6501b 100644
--- a/wcsinst/wcsinst/publisher.py
+++ b/wcsinst/wcsinst/publisher.py
@@ -3,11 +3,6 @@ import sys
from Defaults import *
-try:
- from wcsinst_cfg import *
-except ImportError:
- pass
-
from qommon.publisher import QommonPublisher, set_publisher_class
from root import RootDirectory
@@ -38,4 +33,25 @@ class WcsInstPublisher(QommonPublisher):
return admin
get_admin_module = classmethod(get_admin_module)
+ def configure(cls, config, extra=[]):
+ if config.has_option('main', 'app_dir'):
+ cls.APP_DIR = config.get('main', 'app_dir')
+ if config.has_option('main', 'data_dir'):
+ cls.DATA_DIR = config.get('main', 'data_dir')
+ if config.has_option('main', 'error_log'):
+ cls.ERROR_LOG = config.get('main', 'error_log')
+ if config.has_option('main', 'use_long_traces'):
+ cls.USE_LONG_TRACES = config.getboolean('main', 'use_long_traces')
+ if config.has_option('main', 'auto_create_appdir'):
+ cls.auto_create_appdir = config.getboolean('main', 'auto_create_appdir')
+ if config.has_option('main', 'url_template'):
+ cls.URL_TEMPLATE = config.get('main', 'url_template')
+ if config.has_option('main', 'apache_file_name'):
+ cls.APACHE_FILE_NAME = config.get('main', 'apache_file_name')
+ if config.has_option('main', 'apache_line_template'):
+ cls.APACHE_LINE_TEMPLATE = config.get('main', 'apache_line_template')
+ if config.has_option('main', 'wcs_app_dir'):
+ cls.wcs_app_dir = config.get('main', 'wcs_app_dir')
+ configure = classmethod(configure)
+
set_publisher_class(WcsInstPublisher)
diff --git a/wcsinst/wcsinstctl.py b/wcsinst/wcsinstctl.py
index bae5902..f05d97d 100755
--- a/wcsinst/wcsinstctl.py
+++ b/wcsinst/wcsinstctl.py
@@ -2,22 +2,8 @@
import sys
-def print_usage():
- print 'Usage: wcsinstctl.py command [...]'
- print ''
- print 'Commands:'
- print ' start start server'
+import wcsinst.qommon.ctl
-
-if len(sys.argv) < 2:
- print_usage()
- sys.exit(1)
-else:
- command = sys.argv[1]
-
- if command == 'start':
- from wcsinst.ctl.start import start
- start(sys.argv[2:])
- else:
- print_usage()
+ctl = wcsinst.qommon.ctl.Ctl(cmd_prefixes=['wcsinst.ctl'])
+ctl.run(sys.argv[1:])