-
Notifications
You must be signed in to change notification settings - Fork 3
/
ww-make-docs-from-svn
executable file
·258 lines (234 loc) · 8.13 KB
/
ww-make-docs-from-svn
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/perl -sT
################################################################################
# WeBWorK Online Homework Delivery System
# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
# $CVSHeader: admintools/ww-make-docs-from-cvs,v 1.5 2007/10/02 20:27:44 sh002i Exp $
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of either: (a) the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version, or (b) the "Artistic License" which comes with this package.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the
# Artistic License for more details.
################################################################################
=head1 NAME
ww-make-docs-from-cvs - make WeBWorK documentation from SVN viewable over the web
=cut
use strict;
use warnings;
use IO::File;
$ENV{PATH} = "";
$ENV{ENV} = "";
our $CHECKOUT_DIR = '/home/jaubrey/webwork/';
our $DOC_DIR = '/var/www/wwdocs/';
our $SVN = "/usr/bin/svn";
our $MKDIR = "/bin/mkdir";
our $RM = "/bin/rm";
our $WW_MAKE_DOCS = '/home/jaubrey/admintools/ww-make-docs';
our $BASE_URL = 'http://webwork.maa.org/pod';
our $v; # for verbose switch
my @dirs;
my %index;
if (@ARGV) {
@dirs = map "$CHECKOUT_DIR/$_", @ARGV;
} else {
@dirs = glob("$CHECKOUT_DIR/*");
}
foreach my $dir (@dirs) {
next unless -d $dir;
if ($dir =~ m/^([^\!\$\^\&\*\(\)\~\[\]\|\{\}\'\"\;\<\>\?]+)$/) {
print "\n-----> $dir <-----\n\n" if $v;
update_svn($1);
process_dir($1);
update_index($1);
} else {
warn "'$dir' insecure.\n";
}
}
{
my $fh = new IO::File("$DOC_DIR/index.html", 'w')
or die "failed to open '$DOC_DIR/index.html' for writing: $!\n";
write_index_new($fh);
#write_index($fh);
my $mode = (stat $fh)[2] & 0777 | 0111;
chmod $mode, $fh;
}
sub update_svn {
my ($dir) = @_;
system "cd \"$dir\" && $SVN up" and die "svn failed: $!\n";
}
sub process_dir {
my ($source_dir) = @_;
my $dest_dir = $source_dir;
$dest_dir =~ s/^$CHECKOUT_DIR/$DOC_DIR/;
system $RM, '-rf', $dest_dir;
system $MKDIR, '-p', $dest_dir;
if ($?) {
my $exit = $? >> 8;
my $signal = $? & 127;
my $core = $? & 128;
die "/bin/mkdir -p $dest_dir failed (exit=$exit signal=$signal core=$core)\n";
}
system $WW_MAKE_DOCS, $source_dir, $dest_dir;#, $BASE_URL;
if ($?) {
my $exit = $? >> 8;
my $signal = $? & 127;
my $core = $? & 128;
die "$WW_MAKE_DOCS $source_dir $dest_dir failed (exit=$exit signal=$signal core=$core)\n";
}
}
sub update_index {
my $dir = shift;
$dir =~ s/^.*\///;
if ($dir =~ /^(.+)_(.+?)(?:--(.*))?$/) {
my ($module, $version, $extra) = ($1, $2, $3);
if ($version =~ /^rel-(\d+)-(\d+)(?:-(\d+))?$/) {
my ($major, $minor, $patch) = ($1, $2, $3);
if (defined $patch) {
$version = "$major.$minor.$patch";
} else {
$version = "$major.$minor.0";
}
} elsif ($version =~ /^rel-(\d+)-(\d)-(?:patches|dev)$/) {
my ($major, $minor) = ($1, $2);
$version = "$major.$minor.x (bugfixes)";
} elsif ($version eq "TRUNK") {
$version = 'trunk';
} else {
warn "unfamiliar version string '$version' for dir '$dir' -- not adding to index.\n";
return;
}
$module =~ s/^pg$/PG/;
$module =~ s/^webwork2$/WeBWorK/;
if (defined $extra) {
$index{$module}{$version}{$extra} = $dir;
} else {
$index{$module}{$version} = $dir;
}
} else {
warn "unfamiliar dir format '$dir' -- not adding to index.\n";
}
}
sub write_index {
my $fh = shift;
print $fh "<html><head><title>WeBWorK Documentation from SVN</title></head><body>\n";
print $fh "<h1>WeBWorK Documentation from SVN</h1>\n";
print $fh "<ul>\n";
print $fh map { "<li><a href=\"#$_\">$_</a></li>\n" } sort keys %index;
print $fh "</ul>\n";
for my $module (sort keys %index) {
print $fh "<hr/>\n";
print $fh "<h2><a name=\"$module\">$module</a></h2>\n";
print $fh "<ul>\n";
for my $version (sort keys %{$index{$module}}) {
if (ref $index{$module}{$version}) {
print $fh "<li>$version<ul>\n";
for my $extra (sort keys %{$index{$module}{$version}}) {
print $fh "<li><a href=\"$index{$module}{$version}{$extra}\">$extra</a></li>\n";
}
print $fh "</ul></li>\n";
} else {
print $fh "<li><a href=\"$index{$module}{$version}\">$version</a></li>\n";
}
}
print $fh "</ul>\n";
print $fh "</body></html>\n";
}
}
sub write_index_new {
my $fh = shift;
write_header($fh, 'WeBWorK Documentation from SVN');
print $fh "<h2>Main Menu</h2>\n";
print $fh '<p>Chose a product and version from the menu to the left.</p>';
write_footer($fh);
}
sub write_header {
my $fh = shift;
my $title = shift;
print $fh qq{
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<!-- <base href="http://webwork.maa.org/" /> -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" href="./favicon.ico" />
<title>$title</title>
<style type="text/css" media="screen,projection">/*<![CDATA[*/ \x40import "/skins/monobook/main.css?42b"; /*]]>*/</style>
<link rel="stylesheet" type="text/css" media="print" href="/skins/common/commonPrint.css?42b" />
<link rel="stylesheet" type="text/css" media="handheld" href="/skins/monobook/handheld.css?42b" />
<!--[if lt IE 5.5000]><style type="text/css">\x40import "/skins/monobook/IE50Fixes.css?42b";</style><![endif]-->
<!--[if IE 5.5000]><style type="text/css">\x40import "/skins/monobook/IE55Fixes.css?42b";</style><![endif]-->
<!--[if IE 6]><style type="text/css">\x40import "/skins/monobook/IE60Fixes.css?42b";</style><![endif]-->
<!--[if IE 7]><style type="text/css">\x40import "/skins/monobook/IE70Fixes.css?42b";</style><![endif]-->
<!--[if lt IE 7]><script type="text/javascript" src="/skins/common/IEFixes.js?42b"></script>
<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
</head>
<body class="mediawiki ns-0 ltr page-Main_Page">
<div id="globalWrapper">
<div id="column-content">
<div id="content">
<a name="top" id="top"></a>
<h1 class="firstHeading">$title</h1>
<div id="bodyContent">
<h3 id="siteSub">From WeBWorK</h3>
<div id="contentSub"></div>
<div id="jump-to-nav">Jump to: <a href="#column-one">navigation</a></div>
<!-- <base href="http://webwork.maa.org/pod/" /> -->
<!-- start content -->
}
}
sub write_footer {
my $fh = shift;
print $fh <<'EOF';
<!-- end content -->
<!-- <base href="http://webwork.maa.org/" /> -->
<div class="visualClear"></div>
</div>
</div>
</div>
<div id="column-one">
<div class="portlet" id="p-logo">
<a style="background-image: url(/pod/webwork_square.png);" href="/wiki/Main_Page" title="Main Page"></a>
</div>
<script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
<div class='portlet' id='p-navigation-$module'>
<h5>Navigation</h5>
<div class='pBody'>
<ul>
<li><a href="/pod/">SVN Docs Home</a></li>
<li><a href="/wiki/Main_Page">WeBWorK Wiki</a></li>
</ul>
</div>
</div>
EOF
for my $module (sort keys %index) {
print $fh "<div class='portlet' id='p-navigation-$module'>\n";
print $fh "<h5>$module</h5>\n";
print $fh "<div class='pBody'>\n";
print $fh "<ul>\n";
for my $version (reverse sort keys %{$index{$module}}) {
if (ref $index{$module}{$version}) {
print $fh "<li>$version<ul>\n";
for my $extra (sort keys %{$index{$module}{$version}}) {
print $fh "<li><a href=\"$BASE_URL/$index{$module}{$version}{$extra}\">$extra</a></li>\n";
}
print $fh "</ul></li>\n";
} else {
print $fh "<li><a href=\"$BASE_URL/$index{$module}{$version}\">$version</a></li>\n";
}
}
print $fh "</ul>\n";
print $fh "</div></div>\n";
}
print $fh <<'EOF';
</div><!-- end of the left (by default at least) column -->
<div class="visualClear"></div>
<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>
</div>
</body>
</html>
EOF
}