about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaweł Jastrzębski <[email protected]>2013-10-29 11:00:48 +0100
committerPaweł Jastrzębski <[email protected]>2013-10-29 11:00:48 +0100
commit95bb070a6b337933007566f09a9cea549b6e546d (patch)
tree318e77121fc6d7847b06e61f988e5dc7a3e1c9b5
parentCode cleanup (diff)
downloadkcc-95bb070a6b337933007566f09a9cea549b6e546d.tar.gz
kcc-95bb070a6b337933007566f09a9cea549b6e546d.tar.bz2
kcc-95bb070a6b337933007566f09a9cea549b6e546d.zip
Added content server multithreading
-rw-r--r--kcc/KCC_gui.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py
index 86f89da..193435e 100644
--- a/kcc/KCC_gui.py
+++ b/kcc/KCC_gui.py
@@ -35,6 +35,7 @@ import socket
 import string
 from KCC_rc_web import WebContent
 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+from SocketServer import ThreadingMixIn
 from image import ProfileData
 from subprocess import call, Popen, STDOUT, PIPE
 from PyQt4 import QtGui, QtCore
@@ -78,10 +79,6 @@ class HTMLStripper(HTMLParser):
 
 
 class WebServerHandler(BaseHTTPRequestHandler):
-    #noinspection PyShadowingBuiltins
-    def log_message(self, format, *args):
-        pass
-
     #noinspection PyAttributeOutsideInit
     def do_GET(self):
         if self.path == '/':
@@ -114,17 +111,11 @@ class WebServerHandler(BaseHTTPRequestHandler):
                                  'alt="KCC Logo" src="' + GUIMain.webContent.logo + '" /> -</p>\n')
                 if len(GUIMain.completedWork) > 0 and not GUIMain.conversionAlive:
                     for key in sorted(GUIMain.completedWork.iterkeys()):
-                        self.wfile.write('<p style="font-weight: bold">Only one file is available at once.<br/>'
-                                         'Refresh page after successful download.</p>\n'
-                                         '<p><br/><a href="' + key + '">&gt;&gt;&gt; ' + string.split(key, '.')[0] +
-                                         ' &lt;&lt;&lt;</a></p>\n')
-                        break
+                        self.wfile.write('<p><a href="' + key + '">' + string.split(key, '.')[0] + '</a></p>\n')
                 else:
                     self.wfile.write('<p style="font-weight: bold">No downloads are available.<br/>'
                                      'Convert some files and refresh this page.</p>\n')
-                self.wfile.write('<p><br/><a style="font-weight: bold" href="javascript:history.go(0)">- Refresh page -'
-                                 '</a></p>\n'
-                                 '</div>\n'
+                self.wfile.write('</div>\n'
                                  '</body>\n'
                                  '</html>\n')
             elif sendReply:
@@ -135,17 +126,20 @@ class WebServerHandler(BaseHTTPRequestHandler):
                 self.send_header('Content-Length', os.path.getsize(outputFile))
                 self.end_headers()
                 while True:
-                    chunk = fp.read(1024)
+                    chunk = fp.read(8192)
                     if not chunk:
                         fp.close()
                         break
                     self.wfile.write(chunk)
-                GUIMain.completedWork.pop(urllib2.unquote(self.path[1:]), None)
             return
         except (IOError, LookupError):
             self.send_error(404, 'File Not Found: %s' % self.path)
 
 
+class WebServerThreaded(ThreadingMixIn, HTTPServer):
+    """Handle requests in a separate thread."""
+
+
 class WebServerThread(QtCore.QThread):
     def __init__(self):
         QtCore.QThread.__init__(self)
@@ -163,7 +157,7 @@ class WebServerThread(QtCore.QThread):
             # Sadly it can fail on some Linux configurations
             lIP = None
         try:
-            self.server = HTTPServer(('', 4242), WebServerHandler)
+            self.server = WebServerThreaded(('', 4242), WebServerHandler)
             self.running = True
             if lIP:
                 self.emit(QtCore.SIGNAL("addMessage"), '<b><a href="http://' + lIP +