# $Id: Portfile 119241 2014-04-21 13:30:14Z stromnov@macports.org $

PortSystem 1.0
PortGroup python 1.0

name                    py-openssl
version                 0.13
categories-append       devel security
license                 Apache-2
maintainers             mcalhoun openmaintainer
platforms               darwin freebsd
description             python wrapper around the OpenSSL library
long_description        This python module is a rather thin wrapper around (a \
                                subset of) the OpenSSL library. With thin wrapper a lot of the \
                                object methods do nothing more than calling a corresponding \
                                function in the OpenSSL library.

homepage                http://launchpad.net/pyopenssl
master_sites            http://pypi.python.org/packages/source/p/pyOpenSSL/
distname                pyOpenSSL-${version}

checksums               md5    767bca18a71178ca353dff9e10941929 \
                        sha1   b4de25c5e4e9d9bc375c419071efc45fa96d5597 \
                        rmd160 85d6a8a5ca43ee12c4054f8f483db20e13dd6551

python.versions         24 25 26 27 33

if {${name} ne ${subport}} {
    depends_lib-append      port:openssl

    post-patch   {
            reinplace "s|#!/usr/bin/env python|#!${python.bin}|" ${worksrcpath}/examples/proxy.py
    }

    post-destroot   {
            xinstall -m 644 -W ${worksrcpath} ChangeLog INSTALL LICENSE README \
                    TODO ${destroot}${prefix}/share/doc/${subport}
            file delete ${destroot}${prefix}/share/doc/${subport}/examples
            file copy ${worksrcpath}/examples ${destroot}${prefix}/share/doc/${subport}
    }

    variant doc description {build html documentation} {
        depends_build-append port:latex2html

        post-patch {
            # Ensure that the correct binaries are used.
            # Some are not actually invoked because only the html documentation is created.
            foreach bin {bibtex dvips latex latex2html lynx makeindex pdflatex perl python} {
                reinplace "s| = \"${bin}\"| = \"${prefix}/bin/${bin}\"|" ${worksrcpath}/doc/tools/mkhowto
            }

            # Ensure that the correct python is used.
            reinplace "s|${prefix}/bin/python|${python.bin}|" ${worksrcpath}/doc/tools/mkhowto
            reinplace "s| python | ${python.bin} |" ${worksrcpath}/doc/Makefile
        }

        post-build {
            system "cd ${worksrcpath}/doc && /usr/bin/make html"
        }

        post-destroot {
            file copy ${worksrcpath}/doc/html ${destroot}${prefix}/share/doc/${subport}
        }
    }

    livecheck.type      none
} else {
    livecheck.type      regex
    livecheck.url       ${master_sites}
    livecheck.regex     "pyOpenSSL-(\\d+(?:\\.\\d+)*)${extract.suffix}"
}
