forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-pod-docs.pl
executable file
·145 lines (132 loc) · 3.31 KB
/
upload-pod-docs.pl
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
#!/usr/local/bin/perl
# Upload all Webmin API docs in TWiki format to doxfer.com
use Pod::Simple::Wiki;
$doxfer_host = "doxfer.com";
$doxfer_dir = "/home/doxfer/public_html/twiki/data/Webmin";
$temp_pod_dir = "/tmp/doxfer-wiki";
if ($0 =~ /^(.*\/)[^\/]+$/) {
chdir($1);
}
chop($pwd = `pwd`);
# Build list of modules
@mods = ( [ "WebminCore", ".",
[ "web-lib-funcs.pl", "web-lib.pl", "ui-lib.pl" ],
"Core Webmin API" ] );
foreach my $mi (glob("*/module.info")) {
my $mod;
($mod = $mi) =~ s/\/module.info//;
next if (-l $mod);
my $midata = `cat $mi`;
my @modlibs;
if ($midata =~ /library=(.*)/) {
@modlibs = split(/\s+/, $1);
}
else {
@modlibs = ( $mod."-lib.pl" );
}
my $desc = $midata =~ /desc=(.*)/ ? $1 : $mod;
$desc .= " module";
my @podlibs;
foreach my $f (@modlibs) {
if (-r "$mod/$f") {
my $data = `cat $mod/$f`;
if ($data =~ /=head1/) {
push(@podlibs, $f);
}
}
}
if (@podlibs) {
push(@mods, [ "Module $mod", $mod, \@podlibs, $desc ]);
}
}
# For each, run Pod to Wiki conversion
system("rm -rf $temp_pod_dir ; mkdir $temp_pod_dir");
foreach $m (@mods) {
print STDERR "Doing module $m->[0]\n";
my $wikiname = $m->[1] eq "." ? "ApiWebminCore"
: "Api".join("", map { ucfirst($_) }
split(/\-/, $m->[1]));
push(@$m, $wikiname);
my $infile = "/tmp/pod2twiki.in";
open(INFILE, ">$infile");
foreach $f (@{$m->[2]}) {
# Replace un-decorated =item with =item *
# This is kosher according to the POD docs, but Pod2wiki doesn't
# seem to like it
print STDERR "Doing file $f\n";
open(ORIGFILE, "$m->[1]/$f");
while(<ORIGFILE>) {
if (/^=item\s+([^\*].*)/) {
print INFILE "=item * $1\n";
}
else {
print INFILE $_;
}
}
close(ORIGFILE);
}
close(INFILE);
# Do the conversion
my $outfile = "$temp_pod_dir/$wikiname.txt";
open(OUTFILE, ">$outfile");
print OUTFILE "%TOC%\n\n";
if ($m->[1] eq ".") {
print OUTFILE "---+ Core Webmin API\n\n";
}
else {
print OUTFILE "---+ Functions from module $m->[1]\n\n";
}
open(INFILE, $infile);
my $parser = Pod::Simple::Wiki->new('twiki');
$parser->output_fh(*OUTFILE);
$parser->parse_file(*INFILE);
close(INFILE);
close(OUTFILE);
# Remove errors block
open(OUT, $outfile);
my @lines = <OUT>;
close(OUT);
open(OUT, ">$outfile");
my $verbatim = 0;
foreach my $l (@lines) {
last if ($l =~ /POD\s+ERRORS/);
if ($l =~ /<verbatim>/) {
$verbatim = 1;
}
elsif ($l =~ /<\/verbatim>/) {
$verbatim = 0;
}
elsif (!$verbatim) {
$l = &html_escape($l);
}
print OUT $l;
}
close(OUT);
}
# Create summary page
open(SUMM, ">$temp_pod_dir/TheWebminAPI.txt");
print SUMM "---+ The Webmin API\n\n";
print SUMM <<EOF;
The Webmin API has a set of core functions that are available to all modules,
and functions exported by other modules that yours can optionally use. The APIs
for which documentation is available are linked to below :
EOF
foreach my $m (@mods) {
print SUMM " * [[$m->[4]][$m->[3]]]\n";
}
close(SUMM);
# Upload to doxfer
print STDERR "Uploading to $doxfer_host\n";
system("scp $temp_pod_dir/*.txt doxfer\@$doxfer_host:/home/doxfer/public_html/twiki/data/Webmin/");
print STDERR "done\n";
sub html_escape
{
my ($tmp) = @_;
$tmp =~ s/&/&/g;
$tmp =~ s/</</g;
$tmp =~ s/>/>/g;
$tmp =~ s/\"/"/g;
$tmp =~ s/\'/'/g;
$tmp =~ s/=/=/g;
return $tmp;
}