[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/buildout. set socket timeout just after we parse each *.cfg file

Godefroid Chapelle gotcha at bubblenet.be
Tue Mar 16 13:31:51 EDT 2010


Log message for revision 109996:
  set socket timeout just after we parse each *.cfg file

Changed:
  U   zc.buildout/trunk/src/zc/buildout/buildout.py
  U   zc.buildout/trunk/src/zc/buildout/buildout.txt

-=-
Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py	2010-03-16 16:21:55 UTC (rev 109995)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2010-03-16 17:31:51 UTC (rev 109996)
@@ -125,10 +125,16 @@
     'socket-timeout': '',
     }, 'DEFAULT_VALUE')
 
+DEFAULT_SOCKET_TIMEOUT = socket.getdefaulttimeout()
 
-def _setup_socket_timeout(timeout):
-    socket.setdefaulttimeout(timeout)
-    return 'Setting socket time out to %d seconds.' % timeout
+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):
@@ -252,7 +258,7 @@
                                                 options['installed'])
 
         self._setup_logging()
-        self._setup_socket_timeout()
+        self._display_socket_timeout()
 
         offline = options.get('offline', 'false')
         if offline not in ('true', 'false'):
@@ -757,19 +763,11 @@
     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)
-                socket_timeout = socket.getdefaulttimeout()
-                if socket_timeout <> timeout:
-                    info_msg = _setup_socket_timeout(timeout)
-                    self._logger.info(info_msg)
-            except ValueError:
-                self._logger.warning("Default socket timeout is used !\n"
-                    "Value in configuration is not numeric: [%s].\n",
-                    timeout)
+    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()
@@ -1338,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:
@@ -1638,15 +1641,10 @@
                 elif op_ == 't':
                     try:
                         timeout_string = args.pop(0)
-                        timeout = int(timeout_string)
+                        _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("Timeout value must be numeric", orig_op)
-
-                    info_msg = _setup_socket_timeout(timeout)
-                    print info_msg
+                        _error("No timeout value specified for option t", 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-16 16:21:55 UTC (rev 109995)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt	2010-03-16 17:31:51 UTC (rev 109996)
@@ -1512,15 +1512,14 @@
     ... """)
 
     >>> print system(buildout),
-    Setting socket time out to 5 seconds.
+    Socket timeout is set 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.
+If socket-timeout is not numeric, an error message is issued.
 
     >>> write(sample_buildout, 'buildout.cfg',
     ... """
@@ -1535,13 +1534,7 @@
     ... """)
 
     >>> 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
+    Error: Timeout value must be numeric [5s].
 
 Uninstall recipes
 -----------------



More information about the checkins mailing list