[gimp-web/testing] Add sanity try for parsing mirrors2.json
- From: Pat David <patdavid src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-web/testing] Add sanity try for parsing mirrors2.json
- Date: Wed, 8 Jun 2016 19:34:44 +0000 (UTC)
commit b034d7a7771db6f7635c189855ee41fcab78407f
Author: Pat David <patdavid gmail com>
Date: Wed Jun 8 14:33:56 2016 -0500
Add sanity try for parsing mirrors2.json
Added a check to the plugin to only proceed if
the mirrors2.json file is succesfully opened.
plugins/gimp_mirrors/gimp_mirrors.py | 37 +++++++++++++++++++--------------
1 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/plugins/gimp_mirrors/gimp_mirrors.py b/plugins/gimp_mirrors/gimp_mirrors.py
index 2619cef..6405d14 100644
--- a/plugins/gimp_mirrors/gimp_mirrors.py
+++ b/plugins/gimp_mirrors/gimp_mirrors.py
@@ -63,27 +63,32 @@ def do_mirrors(content_object):
gi = pygeoip.GeoIP('./plugins/gimp_mirrors/GeoIP.dat')
# load mirrors2.json file from content
- with open('./content/downloads/mirrors2.json') as data_file:
- data = json.load(data_file)
+ try:
+ with open('./content/downloads/mirrors2.json') as data_file:
+ data = json.load(data_file)
- for record in data:
- #print "####"
- #print record
+ for record in data:
+ #print "####"
+ #print record
- try:
- country = gi.country_name_by_name( record )
- #print country
+ try:
+ country = gi.country_name_by_name( record )
+ #print country
- if country in mirrors:
- mirrors[ country ] += data[ record ]
- else:
- mirrors[ country ] = data[ record ]
+ if country in mirrors:
+ mirrors[ country ] += data[ record ]
+ else:
+ mirrors[ country ] = data[ record ]
- except:
- print "cannot resolve record: ", record
+ except:
+ print "cannot resolve record: ", record
+
+ page._content = page.content.replace(u"<!-- MIRRORS -->", html_output( mirrors) )
+
+ except IOError:
+ print "Cannot open /content/downloads/mirrors.json!"
+ page._content = page.content.replace(u"<!-- MIRRORS -->", "<p><small>Cannot open
mirrors2.json</small></p>")
- #page._content = page.content.replace(u"<!-- MIRRORS -->", u"<h2>Mirrors Test</h2>")
- page._content = page.content.replace(u"<!-- MIRRORS -->", html_output( mirrors) )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]