Merging r44003 through r44069 from trunk into soc-2011-tomato
[blender-staging.git] / doc / python_api / sphinx_doc_gen.sh
1 #!/bin/sh
2 # run from the blender source dir
3 #   bash source/blender/python/doc/sphinx_doc_gen.sh
4 # ssh upload means you need an account on the server
5
6
7 # ----------------------------------------------------------------------------
8 # Upload vars
9
10 # disable for testing
11 DO_UPLOAD=true
12 DO_EXE_BLENDER=true
13 DO_OUT_HTML=true
14 DO_OUT_HTML_ZIP=true
15 DO_OUT_PDF=false
16
17
18 BLENDER="./blender.bin"
19 SSH_USER="ideasman42"
20 SSH_HOST=$SSH_USER"@emo.blender.org"
21 SSH_UPLOAD="/data/www/vhosts/www.blender.org/documentation" # blender_python_api_VERSION, added after
22
23 # ----------------------------------------------------------------------------
24 # Blender Version & Info
25
26 # 'Blender 2.53 (sub 1) Build' --> '2_53_1' as a shell script.
27 # "_".join(str(v) for v in bpy.app.version)
28 # custom blender vars
29 blender_srcdir=$(dirname $0)/../../
30 blender_version=$(grep "BLENDER_VERSION\s" $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
31 blender_version_char=$(grep BLENDER_VERSION_CHAR $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
32 blender_version_cycle=$(grep BLENDER_VERSION_CYCLE $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
33 blender_subversion=$(grep BLENDER_SUBVERSION $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
34
35 if [ "$blender_version_cycle" == "release" ]
36 then
37         BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)$blender_version_char"_release"
38 else
39         BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)_$blender_subversion
40 fi
41
42 SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
43
44 SPHINXBASE=doc/python_api
45
46
47 # ----------------------------------------------------------------------------
48 # Generate reStructuredText (blender/python only)
49
50 if $DO_EXE_BLENDER ; then
51         # dont delete existing docs, now partial updates are used for quick builds.
52         $BLENDER --background -noaudio --factory-startup --python $SPHINXBASE/sphinx_doc_gen.py
53 fi
54
55
56 # ----------------------------------------------------------------------------
57 # Generate HTML (sphinx)
58
59 if $DO_OUT_HTML ; then
60         # sphinx-build -n -b html $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
61
62         # annoying bug in sphinx makes it very slow unless we do this. should report.
63         cd $SPHINXBASE
64         sphinx-build -n -b html sphinx-in sphinx-out
65
66         # ------------------------------------------------------------------------
67         # ZIP the HTML dir for upload
68
69         if $DO_OUT_HTML_ZIP ; then
70                 # lame, temp rename dir
71                 mv sphinx-out blender_python_reference_$BLENDER_VERSION
72                 zip -r -9 blender_python_reference_$BLENDER_VERSION.zip blender_python_reference_$BLENDER_VERSION
73                 mv blender_python_reference_$BLENDER_VERSION sphinx-out
74         fi
75
76         cd -
77 fi
78
79
80 # ----------------------------------------------------------------------------
81 # Generate PDF (sphinx/laytex)
82
83 if $DO_OUT_PDF ; then
84         sphinx-build -n -b latex $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
85         make -C $SPHINXBASE/sphinx-out
86         mv $SPHINXBASE/sphinx-out/contents.pdf $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
87 fi
88
89
90 # ----------------------------------------------------------------------------
91 # Upload to blender servers, comment this section for testing
92
93 if $DO_UPLOAD ; then
94
95         cp $SPHINXBASE/sphinx-out/contents.html $SPHINXBASE/sphinx-out/index.html
96         ssh $SSH_USER@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
97         rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
98
99         ## symlink the dir to a static URL
100         #ssh $SSH_USER@emo.blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
101
102         # better redirect
103         ssh $SSH_USER@emo.blender.org 'echo "<html><head><title>Redirecting...</title><meta http-equiv=\"REFRESH\" content=\"0;url=../blender_python_api_'$BLENDER_VERSION'/\"></head><body>Redirecting...</body></html>" > '$SSH_UPLOAD'/250PythonDoc/index.html'
104
105         if $DO_OUT_PDF ; then
106                 # rename so local PDF has matching name.
107                 rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf
108         fi
109
110         if $DO_OUT_HTML_ZIP ; then
111                 rsync --progress -avze "ssh -p 22" $SPHINXBASE/blender_python_reference_$BLENDER_VERSION.zip $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.zip
112         fi
113
114 fi
115
116
117 # ----------------------------------------------------------------------------
118 # Print some useful text
119
120 echo ""
121 echo "Finished! view the docs from: "
122 if $DO_OUT_HTML ; then echo "  html:" $SPHINXBASE/sphinx-out/contents.html ; fi
123 if $DO_OUT_PDF ; then  echo "   pdf:" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf ; fi