[gimp-web/testing] MIRRORS plugin testing



commit ba2389e32d635a7792ad87f165d0f4b95ffee0a1
Author: Pat David <patdavid gmail com>
Date:   Fri Dec 18 11:03:32 2015 -0600

    MIRRORS plugin testing

 content/downloads/index.md                    |    3 +-
 plugins/gimp_mirrors/GeoIP.dat                |  Bin 0 -> 818578 bytes
 plugins/gimp_mirrors/GeoIP.dat.gz             |  Bin 0 -> 470095 bytes
 plugins/gimp_mirrors/GeoLite2-Country.mmdb    |  Bin 0 -> 2108182 bytes
 plugins/gimp_mirrors/GeoLite2-Country.mmdb.gz |  Bin 0 -> 1074451 bytes
 plugins/gimp_mirrors/gimp_mirrors.py          |   56 +++++++++++++++++++++++--
 6 files changed, 54 insertions(+), 5 deletions(-)
---
diff --git a/content/downloads/index.md b/content/downloads/index.md
index 30f3992..adba3e0 100644
--- a/content/downloads/index.md
+++ b/content/downloads/index.md
@@ -332,9 +332,10 @@ If you are running one of the existing GIMP mirrors, or want to create a new one
 <dd><a 
href="rsync://mirrors-usa.go-parts.com/mirrors/gimp/">rsync://mirrors-usa.go-parts.com/mirrors/gimp/</a> 
(rsync access)</dd>
 </dl>
 
-
 </div>
 
+<!-- MIRRORS -->
+
 <script src="/js/platform.js"></script>
 
 <script>
diff --git a/plugins/gimp_mirrors/GeoIP.dat b/plugins/gimp_mirrors/GeoIP.dat
new file mode 100644
index 0000000..eecf60b
Binary files /dev/null and b/plugins/gimp_mirrors/GeoIP.dat differ
diff --git a/plugins/gimp_mirrors/GeoIP.dat.gz b/plugins/gimp_mirrors/GeoIP.dat.gz
new file mode 100644
index 0000000..911b018
Binary files /dev/null and b/plugins/gimp_mirrors/GeoIP.dat.gz differ
diff --git a/plugins/gimp_mirrors/GeoLite2-Country.mmdb b/plugins/gimp_mirrors/GeoLite2-Country.mmdb
new file mode 100644
index 0000000..f682bbc
Binary files /dev/null and b/plugins/gimp_mirrors/GeoLite2-Country.mmdb differ
diff --git a/plugins/gimp_mirrors/GeoLite2-Country.mmdb.gz b/plugins/gimp_mirrors/GeoLite2-Country.mmdb.gz
new file mode 100644
index 0000000..219d722
Binary files /dev/null and b/plugins/gimp_mirrors/GeoLite2-Country.mmdb.gz differ
diff --git a/plugins/gimp_mirrors/gimp_mirrors.py b/plugins/gimp_mirrors/gimp_mirrors.py
index 9fdd680..22e84cb 100644
--- a/plugins/gimp_mirrors/gimp_mirrors.py
+++ b/plugins/gimp_mirrors/gimp_mirrors.py
@@ -1,6 +1,11 @@
 from pelican import signals, contents
 import os.path
 from os.path import basename
+#import geoip2.database
+import socket
+import json
+import pygeoip
+
 
 '''
 This is a skeleton for testing the parsing of a MIRRORS file
@@ -8,19 +13,62 @@ to show a list on /downloads/
 '''
 
 '''
-It's been created by me, Pat David, to do what I need for wgo
-don't try to make any sense of it.  I don't know what I'm doing.
+It's been created by me, Pat David, to do what I need for wgo.
+This is based heavily on stuff the LoTR was doing already...
+Don't try to make any sense of it.  I don't know what I'm doing.
 I am not kidding.
 '''
 
 class UnexpectedException(Exception): pass
 
 def do_mirrors(content_object):
+    # Not 'Page' object?  Quit.
     if type(content_object) is not contents.Page:
         return
     
-    print "##########"
-    print "%s" % content_object.metadata
+    # normalize OS path separators to fwd slash
+    page = content_object
+    path = content_object.source_path.replace( os.path.sep, '/' )
+
+    #print "##########"
+    #print "%s" % content_object
+    #print "path: %s" % path
+    #print dir(page)
+
+    # if we are on a downloads page
+    if '/downloads/index.md' in path:
+
+        # create mirrors dict
+        mirrors = {}
+        # instantiate geoip object, load db 
+        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)
+
+        for record in data:
+            print "####"
+            print record
+
+            try:
+                country = gi.country_name_by_name( record )
+                print country
+
+                if country in mirrors:
+                    mirrors[ country ] += data[ record ]
+                else:
+                    mirrors[ country ] = data[ record ]
+
+            except:
+                print "cannot resolve record: ", record
+
+        print( mirrors )
+
+        page._content = page.content.replace(u"<!-- MIRRORS -->", u"<h2>Mirrors Test</h2>")
+
+
+
     
 
 def register():


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