Part I of the Freestyle branch merger: new 'freestyle' folders.
[blender.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" ] ; then
36         BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)$blender_version_char"_release"
37 else
38         BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)_$blender_subversion
39 fi
40
41 SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
42
43 SPHINXBASE=doc/python_api
44
45
46 # ----------------------------------------------------------------------------
47 # Generate reStructuredText (blender/python only)
48
49 if $DO_EXE_BLENDER ; then
50         # dont delete existing docs, now partial updates are used for quick builds.
51         $BLENDER --background -noaudio --factory-startup --python $SPHINXBASE/sphinx_doc_gen.py
52 fi
53
54
55 # ----------------------------------------------------------------------------
56 # Generate HTML (sphinx)
57
58 if $DO_OUT_HTML ; then
59         # sphinx-build -n -b html $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
60
61         # annoying bug in sphinx makes it very slow unless we do this. should report.
62         cd $SPHINXBASE
63         sphinx-build -b html sphinx-in sphinx-out
64
65         # XXX, saves space on upload and zip, should move HTML outside
66         # and zip up there, for now this is OK
67         rm -rf sphinx-out/.doctrees
68
69         # incase we have a zip already
70         rm -f blender_python_reference_$BLENDER_VERSION.zip
71
72         # ------------------------------------------------------------------------
73         # ZIP the HTML dir for upload
74
75         if $DO_OUT_HTML_ZIP ; then
76                 # lame, temp rename dir
77                 mv sphinx-out blender_python_reference_$BLENDER_VERSION
78                 zip -r -9 blender_python_reference_$BLENDER_VERSION.zip blender_python_reference_$BLENDER_VERSION
79                 mv blender_python_reference_$BLENDER_VERSION sphinx-out
80         fi
81
82         cd -
83 fi
84
85
86 # ----------------------------------------------------------------------------
87 # Generate PDF (sphinx/laytex)
88
89 if $DO_OUT_PDF ; then
90         sphinx-build -n -b latex $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
91         make -C $SPHINXBASE/sphinx-out
92         mv $SPHINXBASE/sphinx-out/contents.pdf $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
93 fi
94
95
96 # ----------------------------------------------------------------------------
97 # Upload to blender servers, comment this section for testing
98
99 if $DO_UPLOAD ; then
100
101         cp $SPHINXBASE/sphinx-out/contents.html $SPHINXBASE/sphinx-out/index.html
102         ssh $SSH_USER@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
103         rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
104
105         ## symlink the dir to a static URL
106         #ssh $SSH_USER@emo.blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
107
108         # better redirect
109         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'
110
111         # redirect for release only so wiki can point here
112         if [ "$blender_version_cycle" == "release" ] ; then
113                 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'/blender_python_api/index.html'
114         fi
115
116         if $DO_OUT_PDF ; then
117                 # rename so local PDF has matching name.
118                 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
119         fi
120
121         if $DO_OUT_HTML_ZIP ; then
122                 rsync --progress -avze "ssh -p 22" $SPHINXBASE/blender_python_reference_$BLENDER_VERSION.zip $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.zip
123         fi
124
125 fi
126
127
128 # ----------------------------------------------------------------------------
129 # Print some useful text
130
131 echo ""
132 echo "Finished! view the docs from: "
133 if $DO_OUT_HTML ; then echo "  html:" $SPHINXBASE/sphinx-out/contents.html ; fi
134 if $DO_OUT_PDF ; then  echo "   pdf:" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf ; fi