diff --git a/CHANGES.rst b/CHANGES.rst index 85f43a767f47a6918ab2a92cfcbb003a1f31b3c8..4fc4f24c5544cd24ecf8a2441496cd1c62744c61 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,11 @@ Change History ?.?.? (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 docutils' scripts). https://bugs.launchpad.net/zc.buildout/+bug/422724 diff --git a/src/zc/buildout/buildout.py b/src/zc/buildout/buildout.py index c27f2071aec5053af22561a4457722fc79487589..7f9bb80215006312da56f77cf1f037fe64989766 100644 --- a/src/zc/buildout/buildout.py +++ b/src/zc/buildout/buildout.py @@ -124,6 +124,7 @@ _buildout_default_options = _annotate_section({ 'parts-directory': 'parts', 'prefer-final': 'false', 'python': 'buildout', + 'socket-timeout': '', 'use-dependency-links': 'true', }, 'DEFAULT_VALUE') @@ -271,6 +272,7 @@ class Buildout(UserDict.DictMixin): options['installed']) self._setup_logging() + self._setup_socket_timeout() offline = options['offline'] if offline not in ('true', 'false'): @@ -770,6 +772,19 @@ class Buildout(UserDict.DictMixin): def _error(self, 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): root_logger = logging.getLogger() self._logger = logging.getLogger('zc.buildout') @@ -1623,16 +1638,13 @@ def main(args=None): _error("No file name specified for option", orig_op) elif op_ == 't': try: - timeout = int(args.pop(0)) + timeout_string = args.pop(0) + timeout = int(timeout_string) + options.append(('buildout', 'socket-timeout', timeout_string)) except IndexError: _error("No timeout value specified for option", orig_op) except ValueError: - _error("No timeout value must be numeric", orig_op) - - import socket - print 'Setting socket time out to %d seconds' % timeout - socket.setdefaulttimeout(timeout) - + _error("Timeout value must be numeric", orig_op) elif op: if orig_op == '--help': _help() diff --git a/src/zc/buildout/buildout.txt b/src/zc/buildout/buildout.txt index 5884755d8a9d1bcb501d6705d59003c4b496eb34..5b05f85d339df009ea24d24dd7121ffce105bf9d 100644 --- a/src/zc/buildout/buildout.txt +++ b/src/zc/buildout/buildout.txt @@ -769,6 +769,8 @@ COMMAND_LINE_VALUE). DEFAULT_VALUE python= buildout DEFAULT_VALUE + socket-timeout= + DEFAULT_VALUE use-dependency-links= true DEFAULT_VALUE <BLANKLINE> @@ -1514,6 +1516,56 @@ set the logging level to WARNING op3 b2 3 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 ----------------- @@ -2241,6 +2293,7 @@ database is shown. parts-directory = /sample-buildout/parts prefer-final = false python = buildout + socket-timeout = use-dependency-links = true verbosity = 20 <BLANKLINE>