1ab6bd5afc772b3f7f76c1fc0dab65ddee5099e9
[blender.git] / doc / python_api / sphinx_doc_gen.sh
1 #!/bin/sh
2 # run from the blender source dir
3 #   bash doc/python_api/sphinx_doc_gen.sh
4 # ssh upload means you need an account on the server
5
6 if [ "$1" == "" ] ; then
7         echo "Expected a single argument for the username on blender.org, aborting"
8         exit 1
9 fi
10
11 # ----------------------------------------------------------------------------
12 # Upload vars
13
14 # disable for testing
15 DO_UPLOAD=true
16 DO_EXE_BLENDER=true
17 DO_OUT_HTML=true
18 DO_OUT_HTML_ZIP=true
19 DO_OUT_PDF=false
20
21 if [ -z $BLENDER_BIN ] ; then
22         BLENDER_BIN="./blender.bin"
23 fi
24
25 SSH_USER=$1
26 SSH_HOST=$SSH_USER"@blender.org"
27 SSH_UPLOAD="/data/www/vhosts/www.blender.org/api" # blender_python_api_VERSION, added after
28
29 # ----------------------------------------------------------------------------
30 # Blender Version & Info
31
32 # 'Blender 2.53 (sub 1) Build' --> '2_53_1' as a shell script.
33 # "_".join(str(v) for v in bpy.app.version)
34 # custom blender vars
35 blender_srcdir=$(dirname -- $0)/../..
36 blender_version=$(grep "BLENDER_VERSION\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
37 blender_version_char=$(grep "BLENDER_VERSION_CHAR\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
38 blender_version_cycle=$(grep "BLENDER_VERSION_CYCLE\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
39 blender_subversion=$(grep "BLENDER_SUBVERSION\s" "$blender_srcdir/source/blender/blenkernel/BKE_blender_version.h" | awk '{print $3}')
40
41 if [ "$blender_version_cycle" = "release" ] ; then
42         BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)$blender_version_char"_release"
43 else
44         BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)_$blender_subversion
45 fi
46
47 SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
48
49 SPHINXBASE=doc/python_api
50
51
52 # ----------------------------------------------------------------------------
53 # Generate reStructuredText (blender/python only)
54
55 if $DO_EXE_BLENDER ; then
56         # dont delete existing docs, now partial updates are used for quick builds.
57         $BLENDER_BIN \
58                 --background \
59                 -noaudio \
60                 --factory-startup \
61                 --python-exit-code 1 \
62                 --python $SPHINXBASE/sphinx_doc_gen.py
63
64         if (($? != 0)) ; then
65                 echo "Generating documentation failed, aborting"
66                 exit 1
67         fi
68 fi
69
70
71 # ----------------------------------------------------------------------------
72 # Generate HTML (sphinx)
73
74 if $DO_OUT_HTML ; then
75         # sphinx-build -n -b html $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
76
77         # annoying bug in sphinx makes it very slow unless we do this. should report.
78         cd $SPHINXBASE
79         sphinx-build -b html sphinx-in sphinx-out
80
81         # XXX, saves space on upload and zip, should move HTML outside
82         # and zip up there, for now this is OK
83         rm -rf sphinx-out/.doctrees
84
85         # incase we have a zip already
86         rm -f blender_python_reference_$BLENDER_VERSION.zip
87
88         # ------------------------------------------------------------------------
89         # ZIP the HTML dir for upload
90
91         if $DO_OUT_HTML_ZIP ; then
92                 # lame, temp rename dir
93                 mv sphinx-out blender_python_reference_$BLENDER_VERSION
94                 zip -r -9 blender_python_reference_$BLENDER_VERSION.zip blender_python_reference_$BLENDER_VERSION
95                 mv blender_python_reference_$BLENDER_VERSION sphinx-out
96         fi
97
98         cd -
99 fi
100
101
102 # ----------------------------------------------------------------------------
103 # Generate PDF (sphinx/laytex)
104
105 if $DO_OUT_PDF ; then
106         sphinx-build -n -b latex $SPHINXBASE/sphinx-in $SPHINXBASE/sphinx-out
107         make -C $SPHINXBASE/sphinx-out
108         mv $SPHINXBASE/sphinx-out/contents.pdf $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf
109 fi
110
111
112 # ----------------------------------------------------------------------------
113 # Upload to blender servers, comment this section for testing
114
115 if $DO_UPLOAD ; then
116
117         cp $SPHINXBASE/sphinx-out/contents.html $SPHINXBASE/sphinx-out/index.html
118         ssh $SSH_USER@blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
119         rsync --progress -ave "ssh -p 22" $SPHINXBASE/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
120
121         ## symlink the dir to a static URL
122         #ssh $SSH_USER@blender.org 'rm '$SSH_UPLOAD'/250PythonDoc && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/250PythonDoc'
123         if [ "$blender_version_cycle" = "release" ] ; then
124                 ssh $SSH_USER@blender.org 'rm '$SSH_UPLOAD'/blender_python_api_current && ln -s '$SSH_UPLOAD_FULL' '$SSH_UPLOAD'/blender_python_api_current'
125         fi
126
127         # better redirect
128         ssh $SSH_USER@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'
129
130         # redirect for release only so wiki can point here
131         if [ "$blender_version_cycle" = "release" ] ; then
132                 ssh $SSH_USER@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'
133         fi
134
135         if $DO_OUT_PDF ; then
136                 # rename so local PDF has matching name.
137                 rsync --progress -ave "ssh -p 22" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf
138         fi
139
140         if $DO_OUT_HTML_ZIP ; then
141                 rsync --progress -ave "ssh -p 22" $SPHINXBASE/blender_python_reference_$BLENDER_VERSION.zip $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.zip
142         fi
143
144 fi
145
146
147 # ----------------------------------------------------------------------------
148 # Print some useful text
149
150 echo ""
151 echo "Finished! view the docs from: "
152 if $DO_OUT_HTML ; then echo "  html:" $SPHINXBASE/sphinx-out/contents.html ; fi
153 if $DO_OUT_PDF ; then  echo "   pdf:" $SPHINXBASE/sphinx-out/blender_python_reference_$BLENDER_VERSION.pdf ; fi