%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.6
Release: 3%{?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
# The tests require geoip-geolite which hasn't been reviewed yet
# https://bugzilla.redhat.com/show_bug.cgi?id=910233
# The tests will remain disabled until it is available.
#BuildRequires: geoip-geolite
# 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}
## The tests require geoip-geolite which hasn't been reviewed yet
## https://bugzilla.redhat.com/show_bug.cgi?id=910233
#%%check
#PYTHONPATH=$(pwd) nosetests
#%%if 0%%{?with_python3}
#pushd %%{py3dir}
#PYTHONPATH=$(pwd) nosetests-%%{py3ver}
#popd
#%%endif
%files
%doc README.md COPYING DEVELOPER INSTALL apidocs/
%{python_sitelib}/%{modname}/
%{python_sitelib}/%{modname}-%{version}*
%if 0%{?with_python3}
%files -n python3-pygeoip
%doc README.md COPYING DEVELOPER INSTALL apidocs/
%{python3_sitelib}/%{modname}/
%{python3_sitelib}/%{modname}-%{version}-*
%endif
%changelog
* Wed May 28 2014 Kalev Lember <kalevlember@gmail.com> - 0.2.6-3
- Rebuilt for https://fedoraproject.org/wiki/Changes/Python_3.4
* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.2.6-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild
* Sat Feb 23 2013 Ralph Bean <rbean@redhat.com> - 0.2.6-1
- Latest upstream release
- Now including docs, license, readme, and tests.
- Tests are disabled until data is available
https://bugzilla.redhat.com/show_bug.cgi?id=910233
* Mon Feb 11 2013 Ralph Bean <rbean@redhat.com> - 0.2.5-1
- Initial package for Fedora.