# Path: core/utils.py
# def refresh_geoip_database():
#     if not os.path.exists(settings.GEOIP_CONFIG_ROOT):
#         os.makedirs(settings.GEOIP_CONFIG_ROOT)
# 
#     log.info("Downloading MaxMind GeoIP database...")
#     url = 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz'
# 
#     with requests.get(url, stream=True) as r, tempfile.NamedTemporaryFile() as tmp:
#         r.raw.decode_content = True  # decode gzip/deflate compression of response
#         shutil.copyfileobj(r.raw, tmp)
# 
#         tmp.seek(0)
# 
#         with tarfile.open(fileobj=tmp, mode="r:gz") as tar:
#             members = [m for m in tar.getmembers() if m.isfile() and os.path.splitext(m.name)[1] == '.mmdb']
# 
#             # remove any directory prefix
#             for member in members:
#                 member.name = os.path.basename(member.name)
#             log.info('Extracting %s to %s', ', '.join([m.name for m in members]), settings.GEOIP_CONFIG_ROOT)
# 
#             tar.extractall(settings.GEOIP_CONFIG_ROOT, members)


from django.core.management.base import BaseCommand
from core.utils import refresh_geoip_database
# This file is part of django-xmpp-server-list
# (https://github.com/mathiasertl/django-xmpp-server-list)
#
# django-xmpp-server-list is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# xmppllist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with django-xmpp-server-list.  If not, see <http://www.gnu.org/licenses/>.




class Command(BaseCommand):
    help = 'Refresh GeoIP database.'

    def handle(self, *args, **options):

# Path: core/utils.py
# def refresh_geoip_database():
#     if not os.path.exists(settings.GEOIP_CONFIG_ROOT):
#         os.makedirs(settings.GEOIP_CONFIG_ROOT)
# 
#     log.info("Downloading MaxMind GeoIP database...")
#     url = 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz'
# 
#     with requests.get(url, stream=True) as r, tempfile.NamedTemporaryFile() as tmp:
#         r.raw.decode_content = True  # decode gzip/deflate compression of response
#         shutil.copyfileobj(r.raw, tmp)
# 
#         tmp.seek(0)
# 
#         with tarfile.open(fileobj=tmp, mode="r:gz") as tar:
#             members = [m for m in tar.getmembers() if m.isfile() and os.path.splitext(m.name)[1] == '.mmdb']
# 
#             # remove any directory prefix
#             for member in members:
#                 member.name = os.path.basename(member.name)
#             log.info('Extracting %s to %s', ', '.join([m.name for m in members]), settings.GEOIP_CONFIG_ROOT)
# 
#             tar.extractall(settings.GEOIP_CONFIG_ROOT, members)


# Path: core/management/commands/geoip.py
from django.core.management.base import BaseCommand
from core.utils import refresh_geoip_database

# This file is part of django-xmpp-server-list
# (https://github.com/mathiasertl/django-xmpp-server-list)
#
# django-xmpp-server-list is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# xmppllist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with django-xmpp-server-list.  If not, see <http://www.gnu.org/licenses/>.




class Command(BaseCommand):
    help = 'Refresh GeoIP database.'

    def handle(self, *args, **options):

        refresh_geoip_database()