Repository navigation
Expand file tree
/
Copy pathbuild_docs.sh
More file actions
executable file
·145 lines (126 loc) · 3.93 KB
/
Copy pathbuild_docs.sh
File metadata and controls
executable file
·145 lines (126 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
# **build_docs.sh** - Build the gh-pages docs for DevStack
#
# - Install shocco if not found on PATH
# - Clone MASTER_REPO branch MASTER_BRANCH
# - Re-creates ``docs`` directory from existing repo + new generated script docs
# Usage:
## build_docs.sh [[-b branch] [-p] repo] | .
## -b branch The DevStack branch to check out (default is master; ignored if
## repo is not specified)
## -p Push the resulting docs tree to the source repo; fatal error if
## repo is not specified
## repo The DevStack repository to clone (default is DevStack github repo)
## If a repo is not supplied use the current directory
## (assumed to be a DevStack checkout) as the source.
## . Use the current repo and branch (do not use with -p to
## prevent stray files in the workspace being added tot he docs)
# Defaults
# --------
# Source repo/branch for DevStack
MASTER_REPO=${MASTER_REPO:-https://github.com/openstack-dev/devstack.git}
MASTER_BRANCH=${MASTER_BRANCH:-master}
# http://devstack.org is a GitHub gh-pages site in the https://github.com/cloudbuilders/devtack.git repo
GH_PAGES_REPO=git@github.com:cloudbuilders/devstack.git
# Keep track of the devstack directory
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
# Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support
SHOCCO=${SHOCCO:-shocco}
if ! which shocco; then
if [[ ! -x $TOP_DIR/shocco/shocco ]]; then
if [[ -z "$INSTALL_SHOCCO" ]]; then
echo "shocco not found in \$PATH, please set environment variable SHOCCO"
exit 1
fi
echo "Installing local copy of shocco"
if ! which pygmentize; then
sudo pip install Pygments
fi
if ! which rst2html.py; then
sudo pip install docutils
fi
git clone -b rst_support https://github.com/dtroyer/shocco shocco
cd shocco
./configure
make
cd ..
fi
SHOCCO=$TOP_DIR/shocco/shocco
fi
# Process command-line args
while getopts b:p c; do
case $c in
b) MASTER_BRANCH=$OPTARG
;;
p) PUSH_REPO=1
;;
esac
done
shift `expr $OPTIND - 1`
# Sanity check the args
if [[ "$1" == "." ]]; then
REPO=""
if [[ -n $PUSH_REPO ]]; then
echo "Push not allowed from an active workspace"
unset PUSH_REPO
fi
else
if [[ -z "$1" ]]; then
REPO=$MASTER_REPO
else
REPO=$1
fi
fi
# Check out a specific DevStack branch
if [[ -n $REPO ]]; then
# Make a workspace
TMP_ROOT=$(mktemp -d devstack-docs-XXXX)
echo "Building docs in $TMP_ROOT"
cd $TMP_ROOT
# Get the master branch
git clone $REPO devstack
cd devstack
git checkout $MASTER_BRANCH
fi
# Processing
# ----------
# Assumption is we are now in the DevStack repo workspace to be processed
# Pull the latest docs branch from devstack.org repo
if ! [ -d docs ]; then
git clone -b gh-pages $GH_PAGES_REPO docs
fi
# Build list of scripts to process
FILES=""
for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
echo $f
FILES+="$f "
mkdir -p docs/`dirname $f`;
$SHOCCO $f > docs/$f.html
done
for f in $(find functions lib samples -type f -name \*); do
echo $f
FILES+="$f "
mkdir -p docs/`dirname $f`;
$SHOCCO $f > docs/$f.html
done
echo "$FILES" >docs-files
# Switch to the gh_pages repo
cd docs
# Collect the new generated pages
find . -name \*.html -print0 | xargs -0 git add
# Push our changes back up to the docs branch
if ! git diff-index HEAD --quiet; then
git commit -a -m "Update script docs"
if [[ -n $PUSH ]]; then
git push
fi
fi
# Clean up or report the temp workspace
if [[ -n REPO && -n $PUSH_REPO ]]; then
rm -rf $TMP_ROOT
else
if [[ -z "$TMP_ROOT" ]]; then
TMP_ROOT="$(pwd)"
fi
echo "Built docs in $TMP_ROOT"
fi