From 5a79659bb3801f21ea6ea14ee76d0e50b0011b43 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 4 Mar 2012 20:15:47 +0100 Subject: [PATCH] add manage command to update geoip db --- pandora/app/config.py | 21 +++++++++++-------- .../app/management/commands/update_geoip.py | 15 +++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 pandora/app/management/commands/update_geoip.py diff --git a/pandora/app/config.py b/pandora/app/config.py index 03b313e6..7623c1b6 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -116,20 +116,23 @@ def update_static(): image = os.path.join(settings.STATIC_ROOT, 'png/logo%d.png'%size) if not os.path.exists(image): shutil.copyfile(pandora, image) - #download geo data - path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCity.dat') - if not os.path.exists(path): - url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz' - print 'download', url - ox.net.saveUrl(url, "%s.gz"%path) - os.system('gunzip "%s.gz"' % path) - + update_geoip() #poster script if not os.path.exists(settings.ITEM_POSTER): os.symlink(settings.ITEM_POSTER.replace('poster', 'oxdb_poster'), settings.ITEM_POSTER) - + +def update_geoip(force=False): + path = os.path.join(settings.GEOIP_PATH, 'GeoLiteCity.dat') + if not os.path.exists(path) or force: + url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz' + print 'download', url + ox.net.saveUrl(url, "%s.gz"%path) + if os.path.exists(path): + os.unlink(path) + os.system('gunzip "%s.gz"' % path) + def init(): load_config() thread.start_new_thread(reloader_thread, ()) diff --git a/pandora/app/management/commands/update_geoip.py b/pandora/app/management/commands/update_geoip.py new file mode 100644 index 00000000..6b771e6a --- /dev/null +++ b/pandora/app/management/commands/update_geoip.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +from django.core.management.base import BaseCommand + +from ... import config + + +class Command(BaseCommand): + """ + """ + help = 'update geoip database' + args = '' + + def handle(self, **options): + config.update_geoip(True)