Commit fb9a2fc6 authored by Jim Fulton's avatar Jim Fulton

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

both from command line and from config files.

Cherry-picked from svn trunk. Thanks Godefroid.
parent 4332d164
...@@ -4,6 +4,11 @@ Change History ...@@ -4,6 +4,11 @@ Change History
?.?.? (unreleased) ?.?.? (unreleased)
================== ==================
New features:
- Added buildout:socket-timout option so that socket timeout can be configured
both from command line and from config files. (gotcha)
- Distutils-style scripts are also installed now (for instance pyflakes' and - Distutils-style scripts are also installed now (for instance pyflakes' and
docutils' scripts). https://bugs.launchpad.net/zc.buildout/+bug/422724 docutils' scripts). https://bugs.launchpad.net/zc.buildout/+bug/422724
......
...@@ -124,6 +124,7 @@ _buildout_default_options = _annotate_section({ ...@@ -124,6 +124,7 @@ _buildout_default_options = _annotate_section({
'parts-directory': 'parts', 'parts-directory': 'parts',
'prefer-final': 'false', 'prefer-final': 'false',
'python': 'buildout', 'python': 'buildout',
'socket-timeout': '',
'use-dependency-links': 'true', 'use-dependency-links': 'true',
}, 'DEFAULT_VALUE') }, 'DEFAULT_VALUE')
...@@ -271,6 +272,7 @@ class Buildout(UserDict.DictMixin): ...@@ -271,6 +272,7 @@ class Buildout(UserDict.DictMixin):
options['installed']) options['installed'])
self._setup_logging() self._setup_logging()
self._setup_socket_timeout()
offline = options['offline'] offline = options['offline']
if offline not in ('true', 'false'): if offline not in ('true', 'false'):
...@@ -770,6 +772,19 @@ class Buildout(UserDict.DictMixin): ...@@ -770,6 +772,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')
...@@ -1623,16 +1638,13 @@ def main(args=None): ...@@ -1623,16 +1638,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()
......
...@@ -769,6 +769,8 @@ COMMAND_LINE_VALUE). ...@@ -769,6 +769,8 @@ COMMAND_LINE_VALUE).
DEFAULT_VALUE DEFAULT_VALUE
python= buildout python= buildout
DEFAULT_VALUE DEFAULT_VALUE
socket-timeout=
DEFAULT_VALUE
use-dependency-links= true use-dependency-links= true
DEFAULT_VALUE DEFAULT_VALUE
<BLANKLINE> <BLANKLINE>
...@@ -1514,6 +1516,56 @@ set the logging level to WARNING ...@@ -1514,6 +1516,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
----------------- -----------------
...@@ -2241,6 +2293,7 @@ database is shown. ...@@ -2241,6 +2293,7 @@ database is shown.
parts-directory = /sample-buildout/parts parts-directory = /sample-buildout/parts
prefer-final = false prefer-final = false
python = buildout python = buildout
socket-timeout =
use-dependency-links = true use-dependency-links = true
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