[Checkins] SVN: zc.buildout/trunk/ Added buildout:socket-timout option so that socket timeout can be configured
Godefroid Chapelle
gotcha at bubblenet.be
Wed Mar 10 15:41:10 EST 2010
Log message for revision 109904:
Added buildout:socket-timout option so that socket timeout can be configured
both from command line and from config files.
Changed:
U zc.buildout/trunk/CHANGES.txt
U zc.buildout/trunk/src/zc/buildout/buildout.py
U zc.buildout/trunk/src/zc/buildout/buildout.txt
-=-
Modified: zc.buildout/trunk/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt 2010-03-10 20:12:30 UTC (rev 109903)
+++ zc.buildout/trunk/CHANGES.txt 2010-03-10 20:41:09 UTC (rev 109904)
@@ -4,7 +4,11 @@
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)
==================
Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py 2010-03-10 20:12:30 UTC (rev 109903)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py 2010-03-10 20:41:09 UTC (rev 109904)
@@ -121,6 +121,7 @@
'executable': sys.executable,
'log-level': 'INFO',
'log-format': '',
+ 'socket-timeout': '',
}, 'DEFAULT_VALUE')
@@ -245,6 +246,7 @@
options['installed'])
self._setup_logging()
+ self._setup_socket_timeout()
offline = options.get('offline', 'false')
if offline not in ('true', 'false'):
@@ -749,6 +751,19 @@
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')
@@ -1615,16 +1630,13 @@
_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()
Modified: zc.buildout/trunk/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.txt 2010-03-10 20:12:30 UTC (rev 109903)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt 2010-03-10 20:41:09 UTC (rev 109904)
@@ -748,6 +748,8 @@
DEFAULT_VALUE
python= buildout
DEFAULT_VALUE
+ socket-timeout=
+ DEFAULT_VALUE
<BLANKLINE>
[data-dir]
path= foo bins
@@ -1491,6 +1493,56 @@
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
-----------------
@@ -2213,6 +2265,7 @@
parts =
parts-directory = /sample-buildout/parts
python = buildout
+ socket-timeout =
verbosity = 20
<BLANKLINE>
More information about the checkins
mailing list