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