307476d9a924be0a53dc71676eb0e82343a4bb81
[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_PDF=true
15
16
17 BLENDER="./blender.bin"
18 SSH_USER="ideasman42"
19 SSH_HOST=$SSH_USER"@emo.blender.org"
20 SSH_UPLOAD="/data/www/vhosts/www.blender.org/documentation" # blender_python_api_VERSION, added after
21
22 # ----------------------------------------------------------------------------
23 # Blender Version & Info
24
25 # 'Blender 2.53 (sub 1) Build' --> '2_53_1' as a shell script.
26 # "_".join(str(v) for v in bpy.app.version)
27 # custom blender vars
28 blender_srcdir=$(dirname $0)/../../
29 blender_version=$(grep "BLENDER_VERSION\s" $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
30 blender_version_char=$(grep BLENDER_VERSION_CHAR $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
31 blender_version_cycle=$(grep BLENDER_VERSION_CYCLE $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
32 blender_subversion=$(grep BLENDER_SUBVERSION $blender_srcdir/source/blender/blenkernel/BKE_blender.h | awk '{print $3}')
33
34 if [ "$blender_version_cycle" == "release" ]
35 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 --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 -n -b html sphinx-in sphinx-out
64         cd -
65 fi
66
67
68 # ----------------------------------------------------------------------------
69 # Generate PDF (sphinx/laytex)
70
71 if $DO_OUT_PDF ; then
72         sphinx-build -n -b latex $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
73         make -C $SPHINXBASE/sphinx-out
74         mv $SPHINXBASE/sphinx-out/contents.pdf $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
75 fi
76
77 # ----------------------------------------------------------------------------
78 # Upload to blender servers, comment this section for testing
79
80 if $DO_UPLOAD ; then
81
82         cp $SPHINXBASE/sphinx-out/contents.html $SPHINXBASE/sphinx-out/index.html
83         ssh $SSH_USER@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
84         rsync --progress -avze "ssh -p 22" $SPHINXBASE/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
85
86         ## symlink the dir to a static URL
87         #ssh $SSH_USER@emo.blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
88
89         # better redirect
90         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'
91
92         # rename so local PDF has matching name.
93         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
94
95 fi
96
97
98 # ----------------------------------------------------------------------------
99 # Print some useful text
100
101 echo ""
102 echo "Finished! view the docs from: "
103 if $DO_OUT_HTML ; then echo "  html:" $SPHINXBASE/sphinx-out/contents.html ; fi
104 if $DO_OUT_PDF ; then  echo "   pdf:" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf ; fi