1#!/usr/bin/env bash
2
3TYPES="html pdf-a4 pdf-letter text"
4URL=http://docs.python.org/ftp/python/doc/VERSION/python-VERSION-docs-TYPE.tar.bz2
5VERSIONS=$(curl http://www.python.org/download/releases/ 2>/dev/null | grep "releases/[123456789]"| cut -d/ -f4 |grep -v "^[12].[012345]" |grep -v "^1.6.1")
6echo "Generating expressions for:
7${VERSIONS}
8"
9
10
11cat >default.nix <<EOF
12{ stdenv, fetchurl, lib }:
13
14let
15pythonDocs = {
16EOF
17
18for type in $TYPES; do
19 cat >>default.nix <<EOF
20 ${type/-/_} = {
21 recurseForDerivations = true;
22EOF
23
24 for version in $VERSIONS; do
25 major=$(echo -n ${version}| cut -d. -f1)
26 minor=$(echo -n ${version}| cut -d. -f2)
27 outfile=${major}.${minor}-${type}.nix
28 hash=
29 if [ -e ${outfile} ]; then
30 currentversion=$(grep "url =" ${outfile} |cut -d/ -f7)
31 if [ ${version} = ${currentversion} ]; then
32 hash=$(grep sha256 ${outfile} | cut -d'"' -f2)
33 fi
34 fi
35 echo "Generating ${outfile}"
36 url=$(echo -n $URL |sed -e "s,VERSION,${version},g" -e "s,TYPE,${type},")
37 sha=$(nix-prefetch-url ${url} ${hash})
38
39 sed -e "s,VERSION,${version}," \
40 -e "s,MAJOR,${major}," \
41 -e "s,MINOR,${minor}," \
42 -e "s,TYPE,${type}," \
43 -e "s,URL,${url}," \
44 -e "s,SHA,${sha}," < template.nix > ${outfile}
45
46 attrname=python${major}${minor}
47 cat >>default.nix <<EOF
48 ${attrname} = import ./${major}.${minor}-${type}.nix {
49 inherit stdenv fetchurl lib;
50 };
51EOF
52
53 echo "done."
54 echo
55 done
56 echo " };" >> default.nix
57done
58
59echo "}; in pythonDocs" >> default.nix