Basic POD to twiki converter
[webmin.git] / upload-pod-docs.pl
1 #!/usr/local/bin/perl
2 # Upload all Webmin API docs in TWiki format to doxfer.com
3
4 use Pod::Simple::Wiki;
5
6 $doxfer_host = "doxfer.com";
7 $doxfer_dir = "/home/doxfer/public_html/twiki/data/Webmin";
8 $temp_pod_dir = "/tmp/doxfer-wiki";
9
10 if ($0 =~ /^(.*\/)[^\/]+$/) {
11         chdir($1);
12         }
13 chop($pwd = `pwd`);
14
15 # Build list of modules
16 @mods = ( [ "WebminCore", ".",
17             [ "web-lib-funcs.pl", "web-lib.pl", "ui-lib.pl" ] ] );
18 foreach my $mi (glob("*/module.info")) {
19         # XXX add non-core modules
20         my $mod;
21         ($mod = $mi) =~ s/\/module.info//;
22         next if (-l $mod);
23         my $midata = `cat $mi`;
24         my @modlibs;
25         if ($midata =~ /library=(.*)/) {
26                 @modlibs = split(/\s+/, $1);
27                 }
28         else {
29                 @modlibs = ( $mod."-lib.pl" );
30                 }
31         my @podlibs;
32         foreach my $f (@modlibs) {
33                 if (-r "$mod/$f") {
34                         my $data = `cat $mod/$f`;
35                         if ($data =~ /=head1/) {
36                                 push(@podlibs, $f);
37                                 }
38                         }
39                 }
40         if (@podlibs) {
41                 push(@mods, [ "Module $mod", $mod, \@podlibs ]);
42                 }
43         }
44
45 # For each, run Pod to Wiki conversion
46 system("rm -rf $temp_pod_dir ; mkdir $temp_pod_dir");
47 foreach $m (@mods) {
48         print STDERR "Doing module $m->[0]\n";
49         my $parser = Pod::Simple::Wiki->new('twiki');
50         my $wikiname = $m->[1] eq "." ? "ApiWebminCore"
51                                       : "Api".join("", map { ucfirst($_) }
52                                                 split(/\-/, $m->[1]));
53         my $outfile = "$temp_pod_dir/$wikiname.txt";
54         open(OUTFILE, ">$outfile");
55         if ($m->[1] eq ".") {
56                 print OUTFILE "---+ Core Webmin API\n\n";
57                 }
58         else {
59                 print OUTFILE "---+ Functions from module $m->[1]\n\n";
60                 }
61         foreach $f (@{$m->[2]}) {
62                 # Replace un-decorated =item with =item *
63                 # This is kosher according to the POD docs, but Pod2wiki doesn't
64                 # seem to like it
65                 print STDERR "Doing file $f\n";
66                 my $infile = "/tmp/pod2twiki.in";
67                 open(INFILE, ">$infile");
68                 open(ORIGFILE, "$m->[1]/$f");
69                 while(<ORIGFILE>) {
70                         if (/^=item\s+([^\*].*)/) {
71                                 print INFILE "=item * $1\n";
72                                 }
73                         else {
74                                 print INFILE $_;
75                                 }
76                         }
77                 close(ORIGFILE);
78                 close(INFILE);
79
80                 # Do the conversion
81                 open(INFILE, $infile);
82                 $parser->output_fh(*OUTFILE);
83                 $parser->parse_file(*INFILE);
84                 close(INFILE);
85                 }
86         close(OUTFILE);
87
88         # Remove errors block
89         open(OUT, $outfile);
90         my @lines = <OUT>;
91         close(OUT);
92         open(OUT, ">$outfile");
93         foreach my $l (@lines) {
94                 last if ($l =~ /POD\s+ERRORS/);
95                 print OUT $l;
96                 }
97         close(OUT);
98         }
99
100 # Upload to doxfer
101 print STDERR "Uploading to $doxfer_host\n";
102 system("scp $temp_pod_dir/*.txt doxfer\@$doxfer_host:/home/doxfer/public_html/twiki/data/Webmin/");
103 print STDERR "done\n";