%if 0%{?fedora} %global with_python3 1 %{!?py3ver: %global py3ver %(%{__python3} -c "import sys ; print(sys.version[:3])")} %endif %{!?py2ver: %global py2ver %(%{__python} -c "import sys ; print sys.version[:3]")} %global modname pygeoip Name: python-pygeoip Version: 0.2.5 Release: 1%{?dist} Summary: Pure Python GeoIP API Group: Development/Libraries License: LGPLv3+ URL: http://pypi.python.org/pypi/pygeoip Source0: http://pypi.python.org/packages/source/p/%{modname}/%{modname}-%{version}.zip BuildArch: noarch BuildRequires: python2-devel BuildRequires: python-nose # While this doesn't strictly require geoip-geolite, it only makes sense # that you would install it alongside this module. Requires: geoip-geolite %if 0%{?with_python3} BuildRequires: python3-devel BuildRequires: python3-nose %endif %description Pure Python GeoIP API based on MaxMind's C-based Python API but the code itself is ported from the Pure PHP GeoIP API. Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap. import pygeoip gi = pygeoip.GeoIP('/usr/share/geoip/GeoIP.dat', pygeoip.MEMORY_CACHE) Country lookup >>> gi.country_code_by_name('google.com') 'US' >>> gi.country_code_by_addr('64.233.161.99') 'US' >>> gi.country_name_by_addr('64.233.161.99') 'United States' City lookup >>> gi = pygeoip.GeoIP('/usr/share/geoip/GeoLiteCity.dat') >>> gi.record_by_addr('64.233.161.99') { 'city': 'Mountain View', 'region_name': 'CA', 'area_code': 650, 'longitude': -122.0574, 'country_code3': 'USA', 'latitude': 37.419199999999989, 'postal_code': '94043', 'dma_code': 807, 'country_code': 'US', 'country_name': 'United States' } >>> gi.time_zone_by_addr('64.233.161.99') 'America/Los_Angeles' For more information, check out the full API documentation at http://packages.python.org/pygeoip. %if 0%{?with_python3} %package -n python3-pygeoip Summary: Pure Python GeoIP API Group: Development/Libraries # While this doesn't strictly require geoip-geolite, it only makes sense # that you would install it alongside this module. Requires: geoip-geolite %description -n python3-pygeoip Pure Python GeoIP API based on MaxMind's C-based Python API but the code itself is ported from the Pure PHP GeoIP API. Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap. import pygeoip gi = pygeoip.GeoIP('/usr/share/geoip/GeoIP.dat', pygeoip.MEMORY_CACHE) Country lookup >>> gi.country_code_by_name('google.com') 'US' >>> gi.country_code_by_addr('64.233.161.99') 'US' >>> gi.country_name_by_addr('64.233.161.99') 'United States' City lookup >>> gi = pygeoip.GeoIP('/usr/share/geoip/GeoLiteCity.dat') >>> gi.record_by_addr('64.233.161.99') { 'city': 'Mountain View', 'region_name': 'CA', 'area_code': 650, 'longitude': -122.0574, 'country_code3': 'USA', 'latitude': 37.419199999999989, 'postal_code': '94043', 'dma_code': 807, 'country_code': 'US', 'country_name': 'United States' } >>> gi.time_zone_by_addr('64.233.161.99') 'America/Los_Angeles' For more information, check out the full API documentation at http://packages.python.org/pygeoip. %endif %prep %setup -q -n %{modname}-%{version} # Remove bundled egg-info in case it exists rm -rf %{modname}.egg-info %if 0%{?with_python3} rm -rf %{py3dir} cp -a . %{py3dir} %endif %build %{__python} setup.py build %if 0%{?with_python3} pushd %{py3dir} %{__python3} setup.py build popd %endif %install %if 0%{?with_python3} pushd %{py3dir} %{__python3} setup.py install -O1 --skip-build --root=%{buildroot} popd %endif %{__python} setup.py install -O1 --skip-build --root=%{buildroot} %check PYTHONPATH=$(pwd) nosetests %if 0%{?with_python3} pushd %{py3dir} PYTHONPATH=$(pwd) nosetests-%{py3ver} popd %endif %files # Unfortunately, none of these docs are distributed yet # https://github.com/appliedsec/pygeoip/pull/28 #%%doc README.md COPYING DEVELOPER INSTALL apidocs/ %{python_sitelib}/%{modname}/ %{python_sitelib}/%{modname}-%{version}* %if 0%{?with_python3} %files -n python3-pygeoip # Unfortunately, none of these docs are distributed yet # https://github.com/appliedsec/pygeoip/pull/28 #%%doc README.md COPYING DEVELOPER INSTALL apidocs/ %{python3_sitelib}/%{modname}/ %{python3_sitelib}/%{modname}-%{version}-* %endif %changelog * Mon Feb 11 2013 Ralph Bean - 0.2.5-1 - Initial package for Fedora.