1. Calogero Sanfilippo
  2. Grammy Client

Commits

fripp  committed 112ac61

Gestione delle IOError exceptions

Comments (0)

Files changed (4)

File src/common/AlbumScanner.py Modified

View file
  • Ignore whitespace
  • Hide word diff
     '''
 
     scanningCompleted = QtCore.pyqtSignal(int, list)
+    notifyCriticalError = QtCore.pyqtSignal('QString')
 
     def __init__(self, id, albumURL, parent = None):
         '''
         
     def run(self):
         off = 0
-        t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.albumURL]))
-            
+        
+        try:
+            t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.albumURL]))
+        except IOError as err:
+            self.parent().albumScannerHasFinished()
+            self.notifyCriticalError.emit(QtCore.QString(str(err)))
+            return
         with open(t[0],"r") as f:
             albumText = f.read()
         
         while self.hasNexPage(albumText) and not self.stopFlag:
             off += 20
             
-            t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.albumURL+ "&off=" + str(off)]))
+            try:
+                t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.albumURL+ "&off=" + str(off)]))
+            except IOError as err:
+                self.parent().albumScannerHasFinished()
+                self.notifyCriticalError.emit(QtCore.QString(str(err)))
+                return
+            
             
             with open(t[0],'r') as f:
                 albumText = f.read()

File src/common/ArtistScanner.py Modified

View file
  • Ignore whitespace
  • Hide word diff
     '''
     albumFound = QtCore.pyqtSignal(AlbumData,int)
     albumScanningCompleted = QtCore.pyqtSignal()
+    notifyCriticalError = QtCore.pyqtSignal('QString')
     
 
     def __init__(self, url, id,parent = None):
             
     def run(self):
         off = 0
-        
-        t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.url]))
+        try:
+            t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.url]))
+        except IOError as err:
+            self.parent().artistScannerHasFinished()
+            self.notifyCriticalError.emit(QtCore.QString(str(err)))
+            return
         
         with open(t[0],"r") as f:
             text = f.read()
         while self.hasNexPage(text) and not self.flag:
             off += 20
             
-            t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.url + "&off=" + str(off)]))
+            try:
+                t = urllib.urlretrieve("/".join(["http://www.grammy.ru/music",self.url + "&off=" + str(off)]))
+            except IOError as err:
+                self.parent().artistScannerHasFinished()
+                self.notifyCriticalError.emit(QtCore.QString(str(err)))
+                return
             
             with open(t[0],'r') as f:
                 text = f.read()

File src/common/GrammyParser.py Modified

View file
  • Ignore whitespace
  • Hide word diff
     '''
 
     parsingFinished = QtCore.pyqtSignal()
+    notifyCriticalError = QtCore.pyqtSignal('QString')
     
     def __init__(self, target, sstr, currentID, parent = None):
         '''
         
         params = urllib.urlencode({"target": self.target, "sstr" : self.searchString})
         
-        t = urllib.urlretrieve(searchURL % params)
-        
+        try:
+            t = urllib.urlretrieve(searchURL % params)
+        except IOError as err:
+            self.parent().workingThreadHasFinished()
+            self.notifyCriticalError.emit(QtCore.QString(str(err)))
+            return
 
         with open(t[0],"r") as f:
             text = f.read()
             
             offParam = "&".join([params,"off=%d" % off])
             
-            t = urllib.urlretrieve(searchURL % offParam)
-            
+            try:
+                t = urllib.urlretrieve(searchURL % offParam)
+            except IOError as err:
+                self.parent().workingThreadHasFinished()
+                self.notifyCriticalError.emit(QtCore.QString(str(err)))
+                return
+                
             with open(t[0],"r") as f:
                 text = f.read()
         
             
         if self.stop:
             self.parent().workingThreadHasFinished()
-            
+        
         self.parsingFinished.emit()
         
     @QtCore.pyqtSlot()

File src/gui/MainWindow.py Modified

View file
  • Ignore whitespace
  • Hide word diff
 '''
 
 import os
+import socket
 
 from PyQt4 import QtGui, QtCore, QtNetwork
 
             self.homeDir = os.environ["HOME"]
         elif "HOMEPATH" in os.environ.keys():
             self.homeDir = os.environ["HOMEPATH"]
+            
+            
+        socket.setdefaulttimeout(2)
         
     @QtCore.pyqtSlot('QModelIndex')
     def albumSelectionChanged(self, index):
         url = self.albumListModel.item(index.row(), index.column()).data(QtCore.Qt.UserRole).toString()
         
         scanner = AlbumScanner(self.currentSongID, str(url), self)
+        scanner.notifyCriticalError.connect(self.showCriticalErrorMessages)
         
         self.songListModel.clear()
         self.actionDownload_song.setEnabled(False)
     def parsingFinished(self):
         self.fetching = False
         self.statusLabel.setText("Fetching completed")
+        
+    @QtCore.pyqtSlot('QString')   
+    def showCriticalErrorMessages(self, message):
+        QtGui.QMessageBox.critical(self,"Grammy Client Error", message)
             
     @QtCore.pyqtSlot(ArtistData,int)       
     def addArtist(self,data,id):
         sstr = str(self.searchLine.text())
 
         p = GrammyParser(self.target, sstr, self.currentID, self)
-            
+        p.notifyCriticalError.connect(self.showCriticalErrorMessages)
         self.closeWhileFetching.connect(p.stopWorking)
 
         p.start()
         scanner = ArtistScanner(self.artistData[row].url,self.currentAlbumID,self)
         scanner.albumFound.connect(self.addNewAlbum)
         scanner.albumScanningCompleted.connect(self.albumScanningCompleted)
+        scanner.notifyCriticalError.connect(self.showCriticalErrorMessages)
+        
         scanner.start()
         
         self.fetchingAlbums = True