Add stdandard command line options

* larpe/ctl/start.py:
   add standard options --http, --data-dir, --app-dir.
   --script-name cannot be used with http.

git-svn-id: svn+ssh://labs.libre-entreprise.org/svnroot/larpe@471 3ed937ae-f919-0410-9a43-8e6f19e4ba6e
This commit is contained in:
bdauvergne 2009-04-27 13:02:37 +00:00
parent f612aba869
commit e69a4ca86b
1 changed files with 23 additions and 5 deletions

View File

@ -1,29 +1,47 @@
import socket
import sys
import quixote.server.simple_server
from qommon.scgi_server import run
import publisher
def start(args):
port = 3007
script_name = ''
run_function = run
run_kwargs = {
'port': 3007,
'script_name': ''
}
http = 0
i = 0
while i < len(args):
if args[i] == '--port':
port = int(args[i+1])
run_kwargs['port'] = int(args[i+1])
i += 1
elif args[i] == '--silent':
sys.stdout = open('/dev/null', 'w')
sys.stderr = open('/dev/null', 'w')
elif args[i] == '--script-name':
script_name = args[i+1]
run_kwargs['script_name'] = args[i+1]
i += 1
elif args[i] == '--app-dir':
publisher.LarpePublisher.APP_DIR = args[i+1]
i += 1
elif args[i] == '--data-dir':
publisher.LarpePublisher.DATA_DIR = args[i+1]
i += 1
elif args[i] == '--http':
http = 1
i += 1
if http == 1:
run_function = quixote.server.simple_server.run
if run_kwargs['script_name']:
print "--http option is incompatible with --script-name"
del run_kwargs['script_name']
try:
run(publisher.LarpePublisher.create_publisher, port=port, script_name=script_name)
run_function(publisher.LarpePublisher.create_publisher, **run_kwargs)
except socket.error, err:
if err[0] == 98:
print >> sys.stderr, 'address already in use'