# $Id: PKGBUILD 158582 2012-05-05 00:26:09Z allan $
# Maintainer: Allan McRae <allan@archlinux.org>
# Contributor: Simo Leone <neotuli@gmail.com>

# Note: python2 version must be built first as packaging python3 version "destroys" the source
pkgname=('python2-feedparser' 'python-feedparser' 'python-sgmllib')
pkgbase=python-feedparser
pkgver=5.1.2
pkgrel=1
pkgdesc="Parse RSS and Atom feeds in Python"
arch=('any')
url="http://code.google.com/p/feedparser/"
license=('custom')
makedepends=('python' 'python2' 'libxml2' 'python2-distribute' 'python-distribute')
source=(http://feedparser.googlecode.com/files/feedparser-${pkgver}.tar.bz2)
md5sums=('9f88692c7c1af1d47839eb2025984975')

build() {
  cd ${srcdir}/feedparser-$pkgver
  
  # files get installed with (incorrect) permissions in the tarball...
  chmod 644 feedparser/feedparser.egg-info/*
}

package_python2-feedparser() {
  depends=('python2' 'libxml2' )
  pkgdesc="Parse RSS and Atom feeds in Python2"

  cd ${srcdir}/feedparser-$pkgver
  python2 setup.py install --root=${pkgdir}
  
  sed -i 's#env python$#env python2#' \
    $pkgdir/usr/lib/python2.7/site-packages/feedparser.py
  
  install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/license
}

package_python-feedparser() {
  depends=('libxml2' 'python-sgmllib')
  
  cd ${srcdir}/feedparser-$pkgver
  
  # this _should_ happen automatically...
  2to3 -w feedparser/feedparser.py feedparser/feedparsertest.py
  
  PYTHONPATH=feedparser python setup.py install --root=${pkgdir}  
  
  install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/license
}

package_python-sgmllib() {
  depends=('python')
  pkgdesc="Port of sgmllib to python-3"
  license=('PSF')
  
  cd ${srcdir}/feedparser-$pkgver
  install -Dm644 feedparser/sgmllib3.py \
    ${pkgdir}/usr/lib/python3.2/site-packages/sgmllib.py
  
  python /usr/lib/python3.2/compileall.py \
    ${pkgdir}/usr/lib/python3.2/site-packages/
}
