Handle errors in update thread gracefully

This commit is contained in:
Kovid Goyal 2007-12-05 22:13:50 +00:00
parent ab242cc96d
commit 8a111f5730

View File

@ -13,7 +13,7 @@
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import urllib, re import urllib, re, traceback
from PyQt4.QtCore import QThread, SIGNAL from PyQt4.QtCore import QThread, SIGNAL
@ -23,14 +23,17 @@ from libprs500.ebooks.BeautifulSoup import BeautifulSoup
class CheckForUpdates(QThread): class CheckForUpdates(QThread):
def run(self): def run(self):
src = urllib.urlopen('http://pypi.python.org/pypi/libprs500').read() try:
soup = BeautifulSoup(src) src = urllib.urlopen('http://pypi.python.org/pypi/libprs500').read()
meta = soup.find('link', rel='meta', title='DOAP') soup = BeautifulSoup(src)
if meta: meta = soup.find('link', rel='meta', title='DOAP')
src = meta['href'] if meta:
match = re.search(r'version=(\S+)', src) src = meta['href']
if match: match = re.search(r'version=(\S+)', src)
version = match.group(1) if match:
if version != __version__: version = match.group(1)
self.emit(SIGNAL('update_found(PyQt_PyObject)'), version) if version != __version__:
self.emit(SIGNAL('update_found(PyQt_PyObject)'), version)
except:
traceback.print_exc()