[Checkins] SVN: zc.buildout/branches/gotcha-timeout-cfg/ Added buildout:socket-timout option so that socket timeout can be configured

Godefroid Chapelle gotcha at bubblenet.be
Fri Apr 16 05:33:10 EDT 2010


Log message for revision 110957:
  Added buildout:socket-timout option so that socket timeout can be configured
  both from command line and from config files.
  

Changed:
  U   zc.buildout/branches/gotcha-timeout-cfg/CHANGES.txt
  U   zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.py
  U   zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.txt

-=-
Modified: zc.buildout/branches/gotcha-timeout-cfg/CHANGES.txt
===================================================================
--- zc.buildout/branches/gotcha-timeout-cfg/CHANGES.txt	2010-04-16 09:23:32 UTC (rev 110956)
+++ zc.buildout/branches/gotcha-timeout-cfg/CHANGES.txt	2010-04-16 09:33:09 UTC (rev 110957)
@@ -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.
+
 1.4.3 (2009-12-10)
 ==================
 

Modified: zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.py	2010-04-16 09:23:32 UTC (rev 110956)
+++ zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.py	2010-04-16 09:33:09 UTC (rev 110957)
@@ -32,6 +32,7 @@
 import re
 import shutil
 import sys
+import socket
 import tempfile
 import UserDict
 import zc.buildout
@@ -121,9 +122,21 @@
     'executable': sys.executable,
     'log-level': 'INFO',
     'log-format': '',
+    'socket-timeout': '',
     }, 'DEFAULT_VALUE')
 
+DEFAULT_SOCKET_TIMEOUT = socket.getdefaulttimeout()
 
+def _setup_socket_timeout(timeout_string):
+    try:
+        timeout = int(timeout_string)
+    except ValueError:
+        _error("Timeout value must be numeric [%s]." % timeout_string)
+    current_timeout = socket.getdefaulttimeout()
+    if current_timeout <> timeout:
+        socket.setdefaulttimeout(timeout)
+
+
 class Buildout(UserDict.DictMixin):
 
     def __init__(self, config_file, cloptions,
@@ -245,6 +258,7 @@
                                                 options['installed'])
 
         self._setup_logging()
+        self._display_socket_timeout()
 
         offline = options.get('offline', 'false')
         if offline not in ('true', 'false'):
@@ -749,6 +763,12 @@
     def _error(self, message, *args):
         raise zc.buildout.UserError(message % args)
 
+    def _display_socket_timeout(self):
+        current_timeout = socket.getdefaulttimeout()
+        if current_timeout <> DEFAULT_SOCKET_TIMEOUT:
+            info_msg = 'Socket timeout is set to %d seconds.' % current_timeout
+            self._logger.info(info_msg)
+
     def _setup_logging(self):
         root_logger = logging.getLogger()
         self._logger = logging.getLogger('zc.buildout')
@@ -1316,13 +1336,18 @@
         os.remove(path)
 
     extends = extended_by = None
+    socket_timeout = None
     for section in parser.sections():
         options = dict(parser.items(section))
         if section == 'buildout':
             extends = options.pop('extends', extends)
             extended_by = options.pop('extended-by', extended_by)
+            socket_timeout = options.pop('socket-timeout', socket_timeout)
         result[section] = options
 
+    if socket_timeout is not None:
+        _setup_socket_timeout(socket_timeout)
+
     result = _annotate(result, filename)
 
     if root_config_file and 'buildout' in result:
@@ -1615,16 +1640,11 @@
                             _error("No file name specified for option", orig_op)
                 elif op_ == 't':
                     try:
-                        timeout = int(args.pop(0))
+                        timeout_string = args.pop(0)
+                        _setup_socket_timeout(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("No timeout value specified for option t", orig_op)
             elif op:
                 if orig_op == '--help':
                     _help()

Modified: zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.txt	2010-04-16 09:23:32 UTC (rev 110956)
+++ zc.buildout/branches/gotcha-timeout-cfg/src/zc/buildout/buildout.txt	2010-04-16 09:33:09 UTC (rev 110957)
@@ -748,6 +748,8 @@
         DEFAULT_VALUE
     python= buildout
         DEFAULT_VALUE
+    socket-timeout= 
+        DEFAULT_VALUE
     <BLANKLINE>
     [data-dir]
     path= foo bins
@@ -1491,6 +1493,49 @@
     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),
+    Socket timeout is set to 5 seconds.
+    Develop: '/sample-buildout/recipes'
+    Uninstalling debug.
+    Installing debug.
+    op timeout
+    recipe recipes:debug
+
+If socket-timeout is not numeric, an error message is issued.
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... socket-timeout = 5s
+    ... develop = recipes
+    ... parts = debug
+    ...
+    ... [debug]
+    ... recipe = recipes:debug
+    ... op = timeout
+    ... """)
+
+    >>> print system(buildout),
+    Error: Timeout value must be numeric [5s].
+
 Uninstall recipes
 -----------------
 
@@ -2213,6 +2258,7 @@
     parts =
     parts-directory = /sample-buildout/parts
     python = buildout
+    socket-timeout = 
     verbosity = 20
     <BLANKLINE>
 



More information about the checkins mailing list