Commit 54a98bc8 authored by gotcha's avatar gotcha

Added buildout:socket-timout option so that socket timeout can be configured

both from command line and from config files.

git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@109904 62d5b8a3-27da-0310-9561-8e5933582275
parent bbb8902c
...@@ -4,6 +4,10 @@ Change History ...@@ -4,6 +4,10 @@ Change History
1.4.4 (?) 1.4.4 (?)
========= =========
New feature:
- Added buildout:socket-timout option so that socket timeout can be configured
both from command line and from config files. (gotcha)
1.4.3 (2009-12-10) 1.4.3 (2009-12-10)
================== ==================
......
...@@ -121,6 +121,7 @@ _buildout_default_options = _annotate_section({ ...@@ -121,6 +121,7 @@ _buildout_default_options = _annotate_section({
'executable': sys.executable, 'executable': sys.executable,
'log-level': 'INFO', 'log-level': 'INFO',
'log-format': '', 'log-format': '',
'socket-timeout': '',
}, 'DEFAULT_VALUE') }, 'DEFAULT_VALUE')
...@@ -245,6 +246,7 @@ class Buildout(UserDict.DictMixin): ...@@ -245,6 +246,7 @@ class Buildout(UserDict.DictMixin):
options['installed']) options['installed'])
self._setup_logging() self._setup_logging()
self._setup_socket_timeout()
offline = options.get('offline', 'false') offline = options.get('offline', 'false')
if offline not in ('true', 'false'): if offline not in ('true', 'false'):
...@@ -749,6 +751,19 @@ class Buildout(UserDict.DictMixin): ...@@ -749,6 +751,19 @@ class Buildout(UserDict.DictMixin):
def _error(self, message, *args): def _error(self, message, *args):
raise zc.buildout.UserError(message % args) raise zc.buildout.UserError(message % args)
def _setup_socket_timeout(self):
timeout = self['buildout']['socket-timeout']
if timeout <> '':
try:
timeout = int(timeout)
import socket
self._logger.info('Setting socket time out to %d seconds.', timeout)
socket.setdefaulttimeout(timeout)
except ValueError:
self._logger.warning("Default socket timeout is used !\n"
"Value in configuration is not numeric: [%s].\n",
timeout)
def _setup_logging(self): def _setup_logging(self):
root_logger = logging.getLogger() root_logger = logging.getLogger()
self._logger = logging.getLogger('zc.buildout') self._logger = logging.getLogger('zc.buildout')
...@@ -1615,16 +1630,13 @@ def main(args=None): ...@@ -1615,16 +1630,13 @@ def main(args=None):
_error("No file name specified for option", orig_op) _error("No file name specified for option", orig_op)
elif op_ == 't': elif op_ == 't':
try: try:
timeout = int(args.pop(0)) timeout_string = args.pop(0)
timeout = int(timeout_string)
options.append(('buildout', 'socket-timeout', timeout_string))
except IndexError: except IndexError:
_error("No timeout value specified for option", orig_op) _error("No timeout value specified for option", orig_op)
except ValueError: except ValueError:
_error("No timeout value must be numeric", orig_op) _error("Timeout value must be numeric", orig_op)
import socket
print 'Setting socket time out to %d seconds' % timeout
socket.setdefaulttimeout(timeout)
elif op: elif op:
if orig_op == '--help': if orig_op == '--help':
_help() _help()
......
...@@ -748,6 +748,8 @@ COMMAND_LINE_VALUE). ...@@ -748,6 +748,8 @@ COMMAND_LINE_VALUE).
DEFAULT_VALUE DEFAULT_VALUE
python= buildout python= buildout
DEFAULT_VALUE DEFAULT_VALUE
socket-timeout=
DEFAULT_VALUE
<BLANKLINE> <BLANKLINE>
[data-dir] [data-dir]
path= foo bins path= foo bins
...@@ -1491,6 +1493,56 @@ set the logging level to WARNING ...@@ -1491,6 +1493,56 @@ set the logging level to WARNING
op3 b2 3 op3 b2 3
recipe recipes:debug recipe recipes:debug
Socket timeout
--------------
The timeout of the connections to egg and configuration servers can be
configured in the buildout section. Its value is configured in seconds.
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... socket-timeout = 5
... develop = recipes
... parts = debug
...
... [debug]
... recipe = recipes:debug
... op = timeout
... """)
>>> print system(buildout),
Setting socket time out to 5 seconds.
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
op timeout
recipe recipes:debug
If the socket-timeout is not numeric, a warning is issued and the default
timeout of the Python socket module is used.
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... socket-timeout = 5s
... develop = recipes
... parts = debug
...
... [debug]
... recipe = recipes:debug
... op = timeout
... """)
>>> print system(buildout),
Default socket timeout is used !
Value in configuration is not numeric: [5s].
<BLANKLINE>
Develop: '/sample-buildout/recipes'
Updating debug.
op timeout
recipe recipes:debug
Uninstall recipes Uninstall recipes
----------------- -----------------
...@@ -2213,6 +2265,7 @@ database is shown. ...@@ -2213,6 +2265,7 @@ database is shown.
parts = parts =
parts-directory = /sample-buildout/parts parts-directory = /sample-buildout/parts
python = buildout python = buildout
socket-timeout =
verbosity = 20 verbosity = 20
<BLANKLINE> <BLANKLINE>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment