[library-web/new-website-style] Fallback to cache file in case of failed download



commit b2512fa678efb946337c4cbd08d0e7ed9eeb4fd5
Author: Frédéric Péters <fpeters 0d be>
Date:   Wed Mar 30 20:49:52 2011 +0530

    Fallback to cache file in case of failed download

 src/app.py |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/src/app.py b/src/app.py
index f5c02f1..e452c09 100644
--- a/src/app.py
+++ b/src/app.py
@@ -134,9 +134,15 @@ class App:
             try:
                 s = urllib2.urlopen(url).read()
             except urllib2.HTTPError, e:
+                if os.path.exists(cache_filename):
+                    logging.warning('error %s downloading %s (using cache now)' % (e.code, url))
+                    return cache_filename
                 logging.warning('error %s downloading %s' % (e.code, url))
                 return None
             except urllib2.URLError, e:
+                if os.path.exists(cache_filename):
+                    logging.warning('error (URLError) downloading %s (using cache now)' % url)
+                    return cache_filename
                 logging.warning('error (URLError) downloading %s' % url)
                 return None
             open(cache_filename, 'w').write(s)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]