%{!?python_sitearch: %define python_sitearch %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)" 2>/dev/null)}
%{?!pybasever:%{expand:%%define pybasever %(python -c "import sys ; print sys.version[:3]" 2>/dev/null)}}

Name:		python-twisted-core
Version:	11.1.0
Release:	2.0.cf%{?dist}
Summary:	Asynchronous networking framework written in Python
Group:		Development/Libraries
License:	MIT
URL:		http://twistedmatrix.com/trac/wiki/TwistedCore
Source0:	http://twistedmatrix.com/Releases/Core/11.1/TwistedCore-%{version}.tar.bz2
# Available here:
# https://apestaart.org/thomas/trac/browser/pkg/fedora.extras/python-twisted-core/twisted-dropin-cache?format=raw
Source1:	twisted-dropin-cache
Patch0:		TwistedCore-11.1.0-UTF8.patch
BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(id -nu)
BuildRequires:	python2-devel >= 2.4, python-zope-interface >= 3.0.1
Requires:	python-zope-interface, pyOpenSSL, pyserial

# Obsolete/Provide old zsh subpackage for clean upgrades
Obsoletes:	python-twisted-core-zsh < %{version}-%{release}
Provides:	python-twisted-core-zsh = %{version}-%{release}

# Don't want provides for python shared objects
%{?filter_provides_in: %filter_provides_in %{python_sitearch}/twisted/.*\.so}
%{?filter_setup}

%description
An extensible framework for Python programming, with special focus
on event-based network programming and multi-protocol integration.

It is expected that one day the project will expanded to the point
that the framework will seamlessly integrate with mail, web, DNS,
net news, IRC, RDBMSs, desktop environments, and your toaster.

Twisted Core is used by most of the servers, clients and protocols that are
part of other Twisted projects.

%package doc
Summary:	Documentation for Twisted Core
Group:		Documentation
Requires:	python-twisted-core = %{version}-%{release}

%description doc
Documentation for Twisted Core.

%prep
%setup -n TwistedCore-%{version} -q

# Turn off exec bits on docs to avoid spurious dependencies
find doc -type f | xargs chmod 644

# Fix line endings
sed -i -e 's,\r$,,' doc/howto/listings/udp/*

# Remove spurious shellbangs
sed -i -e '/^#! *\/usr\/bin\/python/d' \
	twisted/internet/glib2reactor.py 
sed -i -e '/^#! *\/usr\/bin\/env python/d' \
	twisted/trial/test/scripttest.py

# Fix encodings
%patch0 -p1

%build
CFLAGS="%{optflags}" python setup.py build

%install
rm -rf %{buildroot}
python setup.py install -O1 --skip-build --root %{buildroot}

# cfsupport is support for MacOSX Core Foundations, so we can delete it
rm -rf %{buildroot}%{python_sitearch}/twisted/internet/cfsupport

# iocpreactor is a win32 reactor, so we can delete it
rm -rf %{buildroot}%{python_sitearch}/twisted/internet/iocpreactor

# Man pages
mkdir -p %{buildroot}%{_mandir}/man1/
cp -a doc/man/*.1 %{buildroot}%{_mandir}/man1/
rm -rf doc/man

# script to regenerate dropin.cache
mkdir -p %{buildroot}%{_libexecdir}
install -m 755 %{SOURCE1} %{buildroot}%{_libexecdir}

# Create an empty dropin.cache to be %%ghost-ed
touch %{buildroot}%{python_sitearch}/twisted/plugins/dropin.cache

# C files don't need to be packaged
rm -f %{buildroot}%{python_sitearch}/twisted/internet/_sigchld.c
rm -f %{buildroot}%{python_sitearch}/twisted/python/_epoll.c
rm -f %{buildroot}%{python_sitearch}/twisted/python/_initgroups.c
rm -f %{buildroot}%{python_sitearch}/twisted/test/raiser.c

# Fix permissions of shared objects
chmod 755 %{buildroot}%{python_sitearch}/twisted/internet/_sigchld.so
chmod 755 %{buildroot}%{python_sitearch}/twisted/python/_epoll.so
chmod 755 %{buildroot}%{python_sitearch}/twisted/python/_initgroups.so
chmod 755 %{buildroot}%{python_sitearch}/twisted/test/raiser.so

# See if there's any egg-info
if [ -f %{buildroot}%{python_sitearch}/Twisted*.egg-info ]; then
	echo %{buildroot}%{python_sitearch}/Twisted*.egg-info |
		sed -e 's|^%{buildroot}||'
fi > egg-info

%check
# can't get this to work yet, but it's close
# export PYTHONPATH=%{buildroot}%{python_sitearch}
# export PATH=$PATH:%{buildroot}%{_bindir}
# trial twisted

%clean
rm -rf %{buildroot}

%post
%{_libexecdir}/twisted-dropin-cache || :

%preun
if [ $1 -eq 0 ]; then
	# Complete removal, not upgrade, so remove plugins cache file
	rm -f %{python_sitearch}/twisted/plugins/dropin.cache || :
fi

%files -f egg-info
%defattr(-,root,root,-)
%doc CREDITS LICENSE NEWS README
%{_bindir}/manhole
%{_bindir}/pyhtmlizer
%{_bindir}/tap2deb
%{_bindir}/tap2rpm
%{_bindir}/tapconvert
%{_bindir}/trial
%{_bindir}/twistd
%{_libexecdir}/twisted-dropin-cache
%{_mandir}/man1/manhole.1*
%{_mandir}/man1/pyhtmlizer.1*
%{_mandir}/man1/tap2deb.1*
%{_mandir}/man1/tap2rpm.1*
%{_mandir}/man1/tapconvert.1*
%{_mandir}/man1/trial.1*
%{_mandir}/man1/twistd.1*
%dir %{python_sitearch}/twisted/
%{python_sitearch}/twisted/*.py*
%{python_sitearch}/twisted/application/
%{python_sitearch}/twisted/cred/
%{python_sitearch}/twisted/enterprise/
%{python_sitearch}/twisted/internet/
%{python_sitearch}/twisted/manhole/
%{python_sitearch}/twisted/persisted/
%dir %{python_sitearch}/twisted/plugins/
%{python_sitearch}/twisted/plugins/*.py*
%ghost %{python_sitearch}/twisted/plugins/dropin.cache
%{python_sitearch}/twisted/protocols/
%{python_sitearch}/twisted/python/
%{python_sitearch}/twisted/scripts/
%dir %{python_sitearch}/twisted/spread/
%{python_sitearch}/twisted/spread/*.py*
%dir %{python_sitearch}/twisted/spread/ui/
%{python_sitearch}/twisted/spread/ui/*.py*
%{python_sitearch}/twisted/spread/ui/*.glade
%{python_sitearch}/twisted/tap/
%{python_sitearch}/twisted/test/
%{python_sitearch}/twisted/trial/

%files doc
%defattr(-,root,root,-)
%doc doc/*

%changelog
* Mon Jan  9 2012 Paul Howarth <paul@city-fan.org> 11.1.0-2.0.cf
- Rebuilt for gcc-4.7 in Rawhide

* Fri Nov 18 2011 Paul Howarth <paul@city-fan.org> 11.1.0-1.0.cf
- Update to 11.1.0 (see NEWS for details)
- Upstream source distribution has moved to twistedmatrix.com
- Use a patch rather than scripted iconv to fix character encoding
- Drop zsh package as functionality now incorporated into zsh itself
- mktap, deprecated since Twisted 8.0, has been removed

* Mon Apr  4 2011 Paul Howarth <paul@city-fan.org> 11.0.0-1.0.cf
- Update to 11.0.0 (see NEWS for details)
- BR: python2-devel rather than just python-devel
- Nobody else likes macros for commands

* Sun Feb 13 2011 Paul Howarth <paul@city-fan.org> 10.2.0-2.0.cf
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Tue Nov 30 2010 Paul Howarth <paul@city-fan.org> 10.2.0-1.0.cf
- Update to 10.2.0 (see NEWS for details)

* Fri Oct  1 2010 Paul Howarth <paul@city-fan.org> 10.1.0-3.0.cf
- Added pyserial to Requires

* Wed Jul 28 2010 Paul Howarth <paul@city-fan.org> 10.1.0-1.1.cf
- Rebuild for python 2.7 in Rawhide

* Mon Jul  4 2010 Paul Howarth <paul@city-fan.org> 10.1.0-1.0.cf
- Update to 10.1.0 (see NEWS for details)
- Twisted now requires python >= 2.4

* Thu Mar  4 2010 Paul Howarth <paul@city-fan.org> 10.0.0-1.0.cf
- Update to 10.0.0 (see NEWS for details)
- Another C object (_initgroups) to fix up in %%install
- Filter provides for python shared objects

* Wed Nov 25 2009 Paul Howarth <paul@city-fan.org> 9.0.0-1.0.cf
- Update to 9.0.0
- Drop upstreamed python 2.6 DeprecationWarnings patch
- Remove changed shellbang in twisted/trial/test/scripttest.py

* Mon Jun 29 2009 Paul Howarth <paul@city-fan.org> 8.2.0-3.0.cf
- Include patch pulled from debian to fix all python 2.6 DeprecationWarnings
  (#497783)

* Mon Mar  2 2009 Paul Howarth <paul@city-fan.org> 8.2.0-2.0.cf
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Fri Jan 16 2009 Paul Howarth <paul@city-fan.org> 8.2.0-1.0.CF
- Update to 8.2.0
- Upstream no longer includes t-im
- twisted/trial/test/scripttest.py has a different shellbang to remove

* Fri Jan 16 2009 Paul Howarth <paul@city-fan.org> 8.1.0-2.0.CF
- Make sure the scriplets never return a non-zero exit status
- Remove dropin.cache file upon package removal

* Mon May 19 2008 Paul Howarth <paul@city-fan.org> 8.1.0-1.0.cf
- Update to 8.1.0
- Another C object (raiser) to fix up in %%install

* Mon Mar 31 2008 Paul Howarth <paul@city-fan.org> 8.0.1-1.0.cf
- Update to 8.0.1
- New programs pyhtmlizer and t-im
- Fix permissions of installed shared objects to placate rpmlint
- dropin.cache no longer created by installer so do it ourselves

* Mon Mar 10 2008 Paul Howarth <paul@city-fan.org> 2.5.0-4.0.cf
- Include egg info in %%files list if present

* Fri Sep 28 2007 Paul Howarth <paul@city-fan.org> 2.5.0-2.1
- don't include twisted/spread/*.so
- fix documentation character encoding where possible

* Wed Jan 10 2007 Paul Howarth <paul@city-fan.org> 2.5.0-1
- update to 2.5.0
- tkmktap no longer included
- don't include empty zsh completion stubs

* Tue Dec 26 2006 Thomas Vander Stichele <thomas at apestaart dot org> 2.4.0-6
- new twisted-dropin-cache; does not complain loudly about plugins in
  the cache that are no longer installed

* Mon Dec 11 2006 Paul Howarth <paul@city-fan.org> 2.4.0-5
- rebuild for python 2.5 on Rawhide

* Fri Nov  3 2006 Paul Howarth <paul@city-fan.org> 2.4.0-4
- incorporate changes from current FE submission (Thomas Vander Stichele &
  Jeffrey C. Ollie)
- use Twisted Core specific URL
- add -doc and -zsh subpackages
- don't package C source files

* Mon Sep  4 2006 Paul Howarth <paul@city-fan.org> 2.4.0-3
- split python-twisted into python-twisted metapackage and python-twisted-core
- add twisted-dropin-cache script and use it
- ghost the dropin.cache file
- remove cfsupport (MacOS) and iocpreactor (Windows) bits inappropriate for
  Linux
- don't ghost .pyo files

* Fri Jun  9 2006 Paul Howarth <paul@city-fan.org> 2.4.0-2
- drop dependencies on sub-projects flow, pair, and web2 that are not
  included in the upstream Twisted bundle
- script the python files list generation to clean up the spec

* Wed May 31 2006 Paul Howarth <paul@city-fan.org> 2.4.0-1
- update to 2.4.0
- update Source0 URL to point to core-only tarball

* Wed May 10 2006 Paul Howarth <paul@city-fan.org> 2.2.0-2
- drop python-twisted-xish dep, now bundled with python-twisted-words

* Tue May  9 2006 Paul Howarth <paul@city-fan.org> 2.2.0-1
- import from PyVault Repository
- update to 2.2.0
- change python-openssl dep to pyOpenSSL for Fedora compatibility
- rewrite in Fedora Extras style

* Mon Oct 10 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.1.0-1
- upstream release

* Tue Aug 23 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.1-1
- upstream release

* Mon Apr 04 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.0-2
- add zsh support

* Fri Mar 25 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.0-1
- final release

* Thu Mar 17 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.0-0.2.a3
- dropped web2

* Wed Mar 16 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.0-0.1.a3
- upstream release

* Sat Mar 12 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.0-0.1.a2
- new prerelease; FE versioning

* Mon Feb 07 2005 Jeff Pitman <symbiont+pyvault@berlios.de> 2.0.0a1-1
- prep for split

* Fri Aug 20 2004 Jeff Pitman <symbiont+pyvault@berlios.de> 1.3.0-1
- new version

* Mon Apr 19 2004 Jeff Pitman <symbiont+pyvault@berlios.de> 1.2.0-3
- vaultize

* Mon Apr 12 2004 Jeff Pitman <symbiont+pyvault@berlios.de> 1.2.0-2
- require pyOpenSSL, SOAPpy, openssh-clients, crypto, dia so trial can run