Commits

Ralph Bean committed 48f5cbd Merge

Merge paj

  • Participants
  • Parent commits 717d5a2, a5e5384

Comments (0)

Files changed (6)

tests/test_memoize.py

-
 import time
 from tw2.devtools import memoize
 

tw2/devtools/__init__.py

+from server import dev_server

tw2/devtools/browser.py

 import tw2.core as twc, pkg_resources as pr, docutils.core, os, genshi.input as gsi, re
+import tw2.devtools
 import tw2.jquery
 import tw2.jqplugins.ui
 import tw2.protovis.custom
 def prepare_source(s):
     try:
         source = inspect.getsource(s)
-    except IOError as e:
+    except IOError, e:
         warnings.warn(repr(s) + " : " + str(e))
         return ""
 
     def command(self):
         WbPage.enable_repo_metadata = self.options.enable_repo_metadata
         WbPage.enable_pypi_metadata = self.options.enable_pypi_metadata
-        twc.dev_server(
+        tw2.devtools.dev_server(
             host=self.options.host, port=self.options.port,
             use_threadpool=self.options.use_threadpool,
             threadpool_workers=self.options.threadpool_workers,
     max_args = 0
 
 if __name__ == '__main__':
-    twc.dev_server()
+    tw2.devtools.dev_server()

tw2/devtools/memoize.py

+from __future__ import with_statement
 import hashlib
 import datetime
 import pickle

tw2/devtools/repositories.py

         p = urllib2.urlopen(url)
         commits = simplejson.loads(p.read())
         p.close()
-    except urllib2.HTTPError as e:
+    except urllib2.HTTPError, e:
         pass
     return commits
 
 
         try:
             urllib2.urlopen(url).close()
-        except urllib2.HTTPError as e:
+        except urllib2.HTTPError, e:
             return False
 
         return True

tw2/devtools/server.py

+import tw2.core as twc
+
+def dev_server(
+    app=None, host='127.0.0.1', port=8000, logging=True, weberror=True,
+    use_threadpool=None, threadpool_workers=10, request_queue_size=5,
+    repoze_tm=False, **config):
+    """
+    Run a development server, hosting the ToscaWidgets application.
+    This requires Paste and WebError, which are only sure to be available if
+    tw2.devtools is installed.
+    """
+    config.setdefault('debug', True)
+    config.setdefault('controller_prefix', '/')
+    app = twc.make_middleware(app, **config)
+
+    if repoze_tm:
+        import repoze.tm as rtm, tw2.sqla as tws
+        app = rtm.TM(app, tws.commit_veto)
+
+    if weberror:
+        import weberror.errormiddleware as we
+        app = we.ErrorMiddleware(app, debug=True)
+
+    if logging:
+        import paste.translogger as pt
+        app = pt.TransLogger(app)
+
+    import paste.httpserver as ph
+    ph.serve(app, host=host, port=port,
+             use_threadpool=use_threadpool,
+             threadpool_workers=threadpool_workers,
+             request_queue_size=request_queue_size)
+
+# TBD: autoreload