# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id$

PortSystem          1.0
name                py-htmldocs
PortGroup           python 1.0
python.versions     26 27 31 32 33 34 35
python.default_version 27
version             1.0
set base_rev        2
revision            ${base_rev}
license             {PSF}

if {$subport != $name} {
    if {${python.version} == 26} { version 2.6.9 }
    if {${python.version} == 27} { version 2.7.12 }
    if {${python.version} == 31} { version 3.1.5 }
    if {${python.version} == 32} { version 3.2.6 }
    if {${python.version} == 33} { version 3.3.6 }
    if {${python.version} == 34} { version 3.4.5 }
    if {${python.version} == 35} { version 3.5.2 }
}

categories          lang
platforms           darwin
maintainers         eborisch \
                    openmaintainer
supported_archs     noarch
installs_libs       no

use_bzip2           yes
use_configure       no

description         Local HTML documentation for Python.
long_description    ${description}
homepage            http://www.python.org/
master_sites        http://www.python.org/ftp/python/doc/

if {${name} != ${subport}} {
    description         HTML documentation for Python ${version}
    long_description    Access Python ${version} HTML docs via \
        file://${prefix}/share/doc/python${python.version}-doc/index.html

    master_sites        http://www.python.org/ftp/python/doc/${version}
    distname            python-${version}-docs-html
    set extractname     ${distname}
    depends_lib-delete  port:python${python.version}
    notes               ${long_description}

    if {${python.version} == 26} {
      checksums \
        rmd160  a7bd375ac3a62249529da805693c3b15510ff976 \
        sha256  f3faa71f4b0cc8fa2bb6c5624233ae79983a2d5c11195fb2089668c60ceb7f1f
    }

    if {${python.version} == 27} {
      checksums \
        rmd160  07fa479d9570a4d86f9e355183c91eeea57688d9 \
        sha256  40891e010cdd9a752a17bd02e30aa853f9a2a7767ee82911cf4507dfa3b13de8
    }
    
    if {${python.version} == 31} {
      checksums \
        rmd160  29717979d6a8b4e970a4747e101259da3e3890c1 \
        sha256  ff327cfaa1219d8d82fcb4f3bae3ec4ce28567982a49784004130521d282faa0
    }
    
    if {${python.version} == 32} {
      checksums \
        rmd160  039539fc90454d35525c8b9478156f7135b86622 \
        sha256  b746ef40a29abe7949e5f183e236a0734c58b841c0600043160a518390704c13
    }

    if {${python.version} == 33} {
      checksums \
        rmd160  84290bfaea54b943025f7088268f256d4a50cf71 \
        sha256  54da33f8a91be819e7ac22fdc88c5125bdd4c67494f52dd79d6b603572c41fb0
    }

    if {${python.version} == 34} {
      # These seem to be re-generated daily. This is a hack to host our own
      # sable mirror. The files may be deleted once the MP mirror has them.
      master_sites          https://www.dropbox.com/s/0n0oanfkkmj8wcn/
      distname              python-3.4.5-docs-html~
      checksums \
        rmd160  5ea48760369cf865aed6d518400391d8daab66bd \
        sha256  21a890f961d8f115d966390dc3a3b7df2511be0cfa03751e85a589a45d3636bf
    }

    if {${python.version} == 35} {
      # These seem to be re-generated daily. This is a hack to host our own
      # sable mirror. The files may be deleted once the MP mirror has them.
      master_sites          https://www.dropbox.com/s/7si63y9i0425o7f/
      distname              python-3.5.2-docs-html~
      checksums \
        rmd160  16e6dc1ca90841e3f2a114fd34d7fbb931d4d3ca \
        sha256  05062d543f8a759e85b6409119e95321db25fd607a3bf258aa2f4333575a9dc0
    }

    if {[string match https://www.dropbox* ${master_sites}]} {
      depends_fetch-append  port:wget
      fetch {
          # Curl doesn't redirect successfully to download; use wget
          system -W ${distpath} \
            "wget -nc ${master_sites}${distname}${extract.suffix}"
      }
    }

    dist_subdir         ${name}/${revision}

    build {}

    destroot {
        set  destdocdir \
            ${destroot}${prefix}/share/doc/python${python.version}-doc
        file mkdir ${destroot}${prefix}/share/doc
        file copy ${workpath}/${extractname} ${destdocdir}
        system "chmod -R a+rX ${destdocdir}" 
    }
    
    livecheck.url       https://docs.python.org/${python.branch}/download.html
    livecheck.type      regex
    livecheck.regex     python-(\[0-9\]+(\\.\[0-9abrc\]+){2})-docs
} else {
    livecheck.type      none
}