Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/statsmaster/files/cron_geoipdb_update.py

Issue 5316783485485056: Issue 670 - Use GeoIP City database for AWStats (Closed)
Patch Set: Created June 17, 2014, 3:06 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | modules/statsmaster/manifests/init.pp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/statsmaster/files/cron_geoipdb_update.py
===================================================================
rename from modules/statsmaster/files/cron_geoipdb_update.sh
rename to modules/statsmaster/files/cron_geoipdb_update.py
--- a/modules/statsmaster/files/cron_geoipdb_update.sh
+++ b/modules/statsmaster/files/cron_geoipdb_update.py
@@ -1,17 +1,19 @@
-#!/bin/sh
+#!/usr/bin/env python
-#
-# paranoia settings
-#
-umask 022
+import urllib
+import zlib
+from StringIO import StringIO
Wladimir Palant 2014/06/17 15:16:21 I already removed that import locally, it's a left
-PATH=/sbin:/bin:/usr/sbin:/usr/bin
-export PATH
+downloads = {
+ '/usr/share/GeoIP/GeoIP.dat': 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz',
+ '/usr/share/GeoIP/GeoIPv6.dat': 'http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz',
-wget -q http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -O /tmp/GeoIP.dat.gz
-test -e /tmp/GeoIP.dat.gz && gzip -fd /tmp/GeoIP.dat.gz
-test -e /tmp/GeoIP.dat && mv -f /tmp/GeoIP.dat /usr/share/GeoIP/GeoIP.dat
+ '/usr/share/GeoIP/GeoIPCity.dat': 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz',
+ '/usr/share/GeoIP/GeoIPCityv6.dat': 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz',
+}
-wget -q http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz -O /tmp/GeoIPv6.dat.gz
-test -e /tmp/GeoIPv6.dat.gz && gzip -fd /tmp/GeoIPv6.dat.gz
-test -e /tmp/GeoIPv6.dat && mv -f /tmp/GeoIPv6.dat /usr/share/GeoIP/GeoIPv6.dat
+for dest, source in downloads.iteritems():
+ data = urllib.urlopen(source).read()
+ with open(dest, "wb") as f:
+ # wbit parameter value isn't properly documented, see https://stackoverflow.com/a/22310760/785541
+ f.write(zlib.decompress(data, zlib.MAX_WBITS | 16))
« no previous file with comments | « no previous file | modules/statsmaster/manifests/init.pp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld