From ff7d4f1a13db0f4a9d6c427dcccbb0d1faf6c577 Mon Sep 17 00:00:00 2001
From: mkaay <mkaay@mkaay.de>
Date: Sun, 27 Dec 2009 15:26:33 +0100
Subject: closes #51

---
 module/gui/MainWindow.py |   1 +
 module/gui/connector.py  | 100 ++++++++++++++++++++++++++---------------------
 pyLoadCore.py            |  61 ++++++++++++++++++-----------
 pyLoadGui.py             |  14 +++++++
 4 files changed, 110 insertions(+), 66 deletions(-)

diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py
index 74bf00b51..06df7447c 100644
--- a/module/gui/MainWindow.py
+++ b/module/gui/MainWindow.py
@@ -53,6 +53,7 @@ class MainWindow(QMainWindow):
         #set menubar and statusbar
         self.menubar = self.menuBar()
         self.statusbar = self.statusBar()
+        self.connect(self.statusbar, SIGNAL("showMsg"), self.statusbar.showMessage)
         self.serverStatus = QLabel("Status: Not Connected")
         self.statusbar.addPermanentWidget(self.serverStatus)
         
diff --git a/module/gui/connector.py b/module/gui/connector.py
index 64c05ba8c..8458d74b9 100644
--- a/module/gui/connector.py
+++ b/module/gui/connector.py
@@ -71,11 +71,11 @@ class connector(QThread):
         if not server_version == SERVER_VERSION:
             self.emit(SIGNAL("error_box"), "server is version %s client accepts version %s" % (server_version, SERVER_VERSION))
     
-    def _proxyError(self, func):
+    def _proxyError(self, func, e):
         """
             formats proxy error msg
         """
-        msg = "proxy error in '%s'" % (func,)
+        msg = "proxy error in '%s':\n%s" % (func, e)
         self.errorQueue.append(msg)
     
     def getError(self):
@@ -93,8 +93,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_collector_files()
-        except:
-            self.emit(SIGNAL("proxy_error"), "getLinkCollector")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getLinkCollector", e)
         finally:
             self.mutex.unlock()
     
@@ -105,8 +105,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_collector_packages()
-        except:
-            self.emit(SIGNAL("proxy_error"), "getPackageCollector")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getPackageCollector", e)
         finally:
             self.mutex.unlock()
     
@@ -117,8 +117,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_file_info(id)
-        except:
-            self.emit(SIGNAL("proxy_error"), "getLinkInfo")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getLinkInfo", e)
         finally:
             self.mutex.unlock()
     
@@ -129,8 +129,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_package_data(id)
-        except:
-            self.emit(SIGNAL("proxy_error"), "getPackageInfo")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getPackageInfo", e)
         finally:
             self.mutex.unlock()
     
@@ -141,8 +141,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_queue()
-        except:
-            self.emit(SIGNAL("proxy_error"), "getPackageQueue")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getPackageQueue", e)
         finally:
             self.mutex.unlock()
     
@@ -153,8 +153,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_package_files(id)
-        except:
-            self.emit(SIGNAL("proxy_error"), "getPackageFiles")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getPackageFiles", e)
         finally:
             self.mutex.unlock()
     
@@ -165,8 +165,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.status_downloads()
-        except:
-            self.emit(SIGNAL("proxy_error"), "getDownloadQueue")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getDownloadQueue", e)
         finally:
             self.mutex.unlock()
     
@@ -177,8 +177,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.status_server()
-        except:
-            self.emit(SIGNAL("proxy_error"), "getServerStatus")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getServerStatus", e)
         finally:
             self.mutex.unlock()
     
@@ -189,8 +189,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.add_urls(links)
-        except:
-            self.emit(SIGNAL("proxy_error"), "addURLs")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "addURLs", e)
         finally:
             self.mutex.unlock()
     
@@ -201,8 +201,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.toggle_pause()
-        except:
-            self.emit(SIGNAL("proxy_error"), "togglePause")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "togglePause", e)
         finally:
             self.mutex.unlock()
     
@@ -216,8 +216,8 @@ class connector(QThread):
                 self.proxy.pause_server()
             else:
                 self.proxy.unpause_server()
-        except:
-            self.emit(SIGNAL("proxy_error"), "setPause")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "setPause", e)
         finally:
             self.mutex.unlock()
     
@@ -228,8 +228,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.new_package(name)
-        except:
-            self.emit(SIGNAL("proxy_error"), "newPackage")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "newPackage", e)
         finally:
             self.mutex.unlock()
     
@@ -240,8 +240,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.move_file_2_package(fileid, packid)
-        except:
-            self.emit(SIGNAL("proxy_error"), "addFileToPackage")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "addFileToPackage", e)
         finally:
             self.mutex.unlock()
     
@@ -252,8 +252,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.push_package_2_queue(packid)
-        except:
-            self.emit(SIGNAL("proxy_error"), "pushPackageToQueue")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "pushPackageToQueue", e)
         finally:
             self.mutex.unlock()
     
@@ -264,8 +264,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.restart_package(packid)
-        except:
-            self.emit(SIGNAL("proxy_error"), "restartPackage")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "restartPackage", e)
         finally:
             self.mutex.unlock()
     
@@ -276,8 +276,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.restart_file(fileid)
-        except:
-            self.emit(SIGNAL("proxy_error"), "restartFile")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "restartFile", e)
         finally:
             self.mutex.unlock()
     
@@ -288,8 +288,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.del_packages([packid,])
-        except:
-            self.emit(SIGNAL("proxy_error"), "removePackage")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "removePackage", e)
         finally:
             self.mutex.unlock()
     
@@ -300,8 +300,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.del_links([fileid,])
-        except:
-            self.emit(SIGNAL("proxy_error"), "removeFile")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "removeFile", e)
         finally:
             self.mutex.unlock()
     
@@ -312,8 +312,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.upload_container(filename, type, content)
-        except:
-            self.emit(SIGNAL("proxy_error"), "uploadContainer")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "uploadContainer", e)
         finally:
             self.mutex.unlock()
     
@@ -324,8 +324,8 @@ class connector(QThread):
         self.mutex.lock()
         try:
             return self.proxy.get_log(offset)
-        except:
-            self.emit(SIGNAL("proxy_error"), "getLog")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "getLog", e)
         finally:
             self.mutex.unlock()
     
@@ -336,8 +336,20 @@ class connector(QThread):
         self.mutex.lock()
         try:
             self.proxy.stop_downloads()
-        except:
-            self.emit(SIGNAL("proxy_error"), "stopAllDownloads")
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "stopAllDownloads", e)
+        finally:
+            self.mutex.unlock()
+    
+    def updateAvailable(self):
+        """
+            update available
+        """
+        self.mutex.lock()
+        try:
+            return self.proxy.update_available()
+        except Exception, e:
+            self.emit(SIGNAL("proxy_error"), "updateAvailable", e)
         finally:
             self.mutex.unlock()
         
diff --git a/pyLoadCore.py b/pyLoadCore.py
index 979abaf44..c062374bc 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -125,8 +125,10 @@ class Core(object):
         self.server_methods = ServerMethods(self)
         self.file_list = File_List(self)
         self.thread_list = Thread_List(self)
-
-        self.server_methods.check_update()
+        
+        self.last_update_check = 0
+        self.update_check_interval = 1800
+        self.update_available = self.check_update()
 
         self.init_server()
         self.init_webserver() # start webinterface like cli, gui etc
@@ -160,7 +162,9 @@ class Core(object):
             if self.do_kill:
                 self.shutdown()
                 self.logger.info("pyLoad quits")
-                exit()
+                exit()
+            if self.last_update_check + self.update_check_interval <= time.time():
+                self.update_available = self.check_update()
 
     def init_server(self):
         try:
@@ -323,41 +327,51 @@ class Core(object):
             thread.shutdown = True
             thread.join(15)
         self.file_list.save()
-        
-    ####################################
-    ########## XMLRPC Methods ##########
-    ####################################
 
-class ServerMethods():
-    def __init__(self, core):
-        self.core = core
+    def check_update(self):
+        try:
+            if self.config['updates']['search_updates']:
+                version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, False))
+                if version_check == "":
+                    self.logger.info("No Updates for pyLoad")
+                    return False
+                else:
+                    self.logger.info("New pyLoad Version %s available" % version_check)
+                    return True
+            else:
+                return False
+        finally:
+            self.last_update_check = time.time()
 
-    def check_update(self):
-        """checks newst version"""
-        if self.core.config['updates']['search_updates']:
+    def install_update(self):
+        if self.config['updates']['search_updates']:
             version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, self.core.config['updates']['install_updates']))
             if version_check == "":
-                self.core.logger.info("No Updates for pyLoad")
                 return False
             else:
-                if self.core.config['updates']['install_updates']:
+                if self.config['updates']['install_updates']:
                     try:
                         tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name
-                        tmp_zip = open(tmp_zip_name, 'w')
+                        tmp_zip = open(tmp_zip_name, 'wb')
                         tmp_zip.write(version_check)
                         tmp_zip.close()
                         __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip_name, "Test/")
                         return True
-
                     except:
-                        self.logger.core.info("Auto install Faild")
+                        self.logger.info("Auto install Failed")
                         return False
-
                 else:
-                    self.core.logger.info("New pyLoad Version %s available" % version_check)
-                    return True
+                    return False
         else:
             return False
+        
+    ####################################
+    ########## XMLRPC Methods ##########
+    ####################################
+
+class ServerMethods():
+    def __init__(self, core):
+        self.core = core
 
     def status_downloads(self):
         downloads = []
@@ -521,7 +535,10 @@ class ServerMethods():
         return lines[offset:]
     
     def stop_downloads(self):
-        self.core.thread_list.stopAllDownloads()
+        self.core.thread_list.stopAllDownloads()
+    
+    def update_available(self):
+        return self.core.update_available
 
     #def move_urls_up(self, ids):
     #    for id in ids:
diff --git a/pyLoadGui.py b/pyLoadGui.py
index 0f76e6429..ea106c516 100755
--- a/pyLoadGui.py
+++ b/pyLoadGui.py
@@ -217,6 +217,9 @@ class main(QObject):
         self.mainWindow.serverStatus.setText(text)
     
     def refreshLog(self):
+        """
+            update log window
+        """
         offset = self.mainWindow.tabs["log"]["text"].logOffset
         lines = self.connector.getLog(offset)
         if not lines:
@@ -228,6 +231,16 @@ class main(QObject):
         cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
         self.mainWindow.tabs["log"]["text"].setTextCursor(cursor)
     
+    def updateAvailable(self):
+        """
+            update notification
+        """
+        status = self.connector.updateAvailable()
+        if status:
+            self.mainWindow.statusbar.emit(SIGNAL("showMsg"), "Update Available")
+        else:
+            self.mainWindow.statusbar.emit(SIGNAL("showMsg"), "")
+    
     def getConnections(self):
         """
             parse all connections in the config file
@@ -494,6 +507,7 @@ class main(QObject):
             """
             self.parent.refreshServerStatus()
             self.parent.refreshLog()
+            self.parent.updateAvailable()
         
         def stop(self):
             self.running = False
-- 
cgit v1.2.3