[py-svn] r37065 - in py/branch/config/py/test: . rsession

arigo at codespeak.net arigo at codespeak.net
Sat Jan 20 17:15:12 CET 2007


Author: arigo
Date: Sat Jan 20 17:15:10 2007
New Revision: 37065

Modified:
   py/branch/config/py/test/config.py
   py/branch/config/py/test/rsession/rsession.py
   py/branch/config/py/test/rsession/web.py
Log:
Choose a random free port when using the --runbrowser option,
but stick to the fixed 8000 when using --startserver only.


Modified: py/branch/config/py/test/config.py
==============================================================================
--- py/branch/config/py/test/config.py	(original)
+++ py/branch/config/py/test/config.py	Sat Jan 20 17:15:10 2007
@@ -219,6 +219,6 @@
     option._fromremote = False 
 
     if option.runbrowser and not option.startserver:
-        print "Cannot point browser when not starting server"
+        #print "Cannot point browser when not starting server"
         option.startserver = True
     # XXX: Shouldn't we fix the session here?

Modified: py/branch/config/py/test/rsession/rsession.py
==============================================================================
--- py/branch/config/py/test/rsession/rsession.py	(original)
+++ py/branch/config/py/test/rsession/rsession.py	Sat Jan 20 17:15:10 2007
@@ -57,13 +57,19 @@
         
         if startserverflag and reporter is None:
             from py.__.test.rsession.web import start_server, exported_methods
+            if self.config.option.runbrowser:
+                from socket import INADDR_ANY
+                port = INADDR_ANY   # pick a random port when starting browser
+            else:
+                port = 8000         # stick to a fixed port otherwise
             
             reporter = exported_methods.report
-            start_server()
+            httpd = start_server(server_address = ('', port))
+            port = httpd.server_port
             if self.config.option.runbrowser:
                 import webbrowser, thread
                 # webbrowser.open() may block until the browser finishes or not
-                url = "http://localhost:8000"
+                url = "http://localhost:%d" % (port,)
                 thread.start_new_thread(webbrowser.open, (url,))
         elif reporter is None: 
             if restflag:

Modified: py/branch/config/py/test/rsession/web.py
==============================================================================
--- py/branch/config/py/test/rsession/web.py	(original)
+++ py/branch/config/py/test/rsession/web.py	Sat Jan 20 17:15:10 2007
@@ -416,10 +416,10 @@
 
     if start_new:
         thread.start_new_thread(httpd.serve_forever, ())
-        print "Server started, listening on %s" % (server_address,)
+        print "Server started, listening on port %d" % (httpd.server_port,)
         return httpd
     else:
-        print "Server started, listening on %s" % (server_address,)
+        print "Server started, listening on port %d" % (httpd.server_port,)
         httpd.serve_forever()
 
 def kill_server():


More information about the py-svn mailing list