[kupu-checkins] r38540 - in kupu/trunk/kupu: . common

duncan at codespeak.net duncan at codespeak.net
Mon Feb 12 11:41:22 CET 2007


Author: duncan
Date: Mon Feb 12 11:41:21 2007
New Revision: 38540

Modified:
   kupu/trunk/kupu/common/kupueditor.js
   kupu/trunk/kupu/lint.py
Log:
Fix escapeEntities to entitise non-break spaces. (Otherwise they get lost in source view mode).
Gratuitous rewrite of lint.py to spawn multiple sub-processes. This halves the time taken to run jslint on a dual core system.


Modified: kupu/trunk/kupu/common/kupueditor.js
==============================================================================
--- kupu/trunk/kupu/common/kupueditor.js	(original)
+++ kupu/trunk/kupu/common/kupueditor.js	Mon Feb 12 11:41:21 2007
@@ -773,6 +773,7 @@
     };
     this.escapeEntities = function(xml) {
         // XXX: temporarily disabled
+        xml = xml.replace(/\xa0/g, ' ');
         return xml;
         // Escape non-ascii characters as entities.
 //         return xml.replace(/[^\r\n -\177]/g,

Modified: kupu/trunk/kupu/lint.py
==============================================================================
--- kupu/trunk/kupu/lint.py	(original)
+++ kupu/trunk/kupu/lint.py	Mon Feb 12 11:41:21 2007
@@ -10,6 +10,8 @@
 # Run jslint over modified javascript files
 import os, sys, glob, time
 import cPickle
+from Queue import Queue
+import threading
 
 COMPILE_COMMAND = "java org.mozilla.javascript.tools.shell.Main %(lint)s --options %(options)s %(file)s"
 if sys.platform=='win32':
@@ -17,9 +19,10 @@
 
 def lint(name):
     cmd = COMPILE_COMMAND % dict(lint=LINT, file=name, options=OPTIONS)
-    ret = os.system(cmd)
-    if ret != 0:
-        sys.exit(ret)
+    stream = os.popen(cmd)
+    data = stream.read()
+    rc = stream.close()
+    return data, rc
 
 def scriptrelative(relative):
     """Find absolute path of file relative to this script"""
@@ -69,9 +72,55 @@
     cPickle.dump(status, f)
     f.close()
 
+# Thread pool code.
+class Pool:
+    def __init__(self, nThreads):
+        self.nThreads = nThreads
+        self.requestQueue = Queue()
+        self.responseQueue = Queue()
+        self.exitcode = 0
+        self.thread_pool = [
+                threading.Thread(target=self.run)
+                for i in range(nThreads)]
+        for t in self.thread_pool:
+            t.start()
+
+    def run(self):
+        for item in iter(self.requestQueue.get, None):
+            if not self.exitcode:
+                self.responseQueue.put([item, lint(item)])
+            else:
+                # Error state, just ignore this item
+                self.responseQueue.put([item, ("skipped %s" % item, 1)])
+
+    def handleResponse(self, item, data, rc):
+        if rc is not None:
+            if item in status:
+                del status[item]
+            self.exitcode = max(self.exitcode, rc)
+        print data
+
+    def process(self, items):
+        items = list(items)
+        for item in items:
+             self.requestQueue.put(item)
+        for dummy in items:
+            item, (data, rc) = self.responseQueue.get()
+            self.handleResponse(item, data, rc)
+
+    def shutdown(self):
+        # and then to shut down the threads when you've finished:
+        for t in self.thread_pool:
+            self.requestQueue.put(None)
+        for t in self.thread_pool:
+             t.join()
+
 if __name__=='__main__':
     status = loadstatus(STATUSFILE)
-    for n in newfiles(status, 'common/*.js', 'plone/kupu_plone_layer/*.js'):
-        lint(n)
-        savestatus(STATUSFILE, status)
-
+    exitcode = None
+    threads = Pool(4)
+    work = newfiles(status, 'common/*.js', 'plone/kupu_plone_layer/*.js')
+    threads.process(work)
+    threads.shutdown()
+    savestatus(STATUSFILE, status)
+    sys.exit(exitcode)


More information about the kupu-checkins mailing list