forked from geraldcroes/atoum-s-old-documentation
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathbuilddoc
executable file
·139 lines (116 loc) · 4.56 KB
/
builddoc
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
#!/usr/bin/env php
<?php
# You can set these variables from the command line.
$SPHINXOPTS = '';
$SPHINXBUILD = getenv('SPHINXBUILD') ?: 'sphinx-build';
$SOURCEDIR = 'source';
$BUILDDIR = 'build';
try {
# Check for sphinx-build
checkExecutable(
$SPHINXBUILD,
"The $SPHINXBUILD command was not found. " .
"Make sure you have Sphinx installed, then set the \$SPHINXBUILD variable to point to the full path of the $SPHINXBUILD executable. " .
"Alternatively you can add the directory with the executable to your PATH. " .
"If you don't have Sphinx installed, grab it from http://sphinx-doc.org/"
);
# Internal variables.
$SOURCEDIR = $SOURCEDIR;
$BUILDDIR = $BUILDDIR;
$ALLSPHINXOPTS = "-D latex_paper_size=a4 $SPHINXOPTS";
# function to manage languages
$generateByLang = function($type, $format = null, $callback = null) use ($SPHINXBUILD, $ALLSPHINXOPTS, $SOURCEDIR, $BUILDDIR) {
$format = $format ?: $type;
foreach (glob($SOURCEDIR . '/*') as $path) {
$lang = basename($path);
createDirectory("$BUILDDIR/$lang/doctrees");
createDirectory("$BUILDDIR/$lang/$format");
command("$SPHINXBUILD -b $type -d $BUILDDIR/$lang/doctrees $ALLSPHINXOPTS $SOURCEDIR/$lang $BUILDDIR/$lang/$format");
if ($callback) {
$callback($SPHINXBUILD, $ALLSPHINXOPTS, "$SOURCEDIR/$lang", "$BUILDDIR/$lang");
}
writeln();
writeln("Build for language \"$lang\" finished.");
writeln("Documentation was generated in format \"$format\" in $BUILDDIR/$lang.");
writeln();
}
writeln("Build finished.");
writeln("Documentation was generated in format \"$format\" in $BUILDDIR.");
writeln();
};
# get command
$command = isset($argv[1]) ? $argv[1] : 'help';
switch ($command) {
case 'clean':
command("rm -rf $BUILDDIR/*");
break;
case 'html':
$generateByLang('html');
break;
case 'epub':
$generateByLang('epub');
break;
case 'pdf':
checkExecutable(
'pdflatex',
"The pdflatex command was not found."
);
$generateByLang(
'latex',
'pdf',
function($SPHINXBUILD, $ALLSPHINXOPTS, $SOURCEDIR, $BUILDDIR) {
command("make -C $BUILDDIR/pdf all-pdf");
}
);
break;
case 'text':
$generateByLang('text');
break;
case 'linkcheck':
$generateByLang(
'linkcheck',
null,
function($SPHINXBUILD, $ALLSPHINXOPTS, $SOURCEDIR, $BUILDDIR) {
writeln();
writeln("Link check complete; look for any errors in the above output or in $BUILDDIR/linkcheck/output.txt.");
}
);
break;
default:
throw new Exception("undefined $command command.");
case 'help':
writeln("Please use 'make <target>' where <target> is one of");
writeln(" html to make standalone HTML files");
writeln(" epub to make an epub");
writeln(" pdf to make a pdf");
writeln(" text to make text files");
writeln(" linkcheck to check all external links for integrity");
break;
}
} catch (Exception $e) {
writeln('Error: ' . $e->getMessage());
}
function writeln($text = '') {
echo "$text\n";
}
function command($command, $display = true) {
if ($display) {
writeln("> $command");
passthru($command, $returnValue);
writeln();
} else {
$output = array();
exec($command, $output, $returnValue);
}
return $returnValue;
}
function createDirectory($path) {
if (!file_exists($path)) {
mkdir($path, 0755, true);
}
}
function checkExecutable($executable, $errorMessage) {
/*if (command("which $executable", false) !== 0) {
throw new Exception($errorMessage);
}*/
}