RT#18834: Cacti integration [added graph generation]
[freeside.git] / bin / pod2x
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my $mw_username = 'ivan';
6 chomp( my $mw_password = `cat .mw-password` );
7
8 my $site_perl = "./FS";
9 #my $html = "Freeside:1.7:Documentation:Developer";
10 #my $html = "Freeside:1.9:Documentation:Developer";
11 my $html = "Freeside:3:Documentation:Developer";
12
13 foreach my $dir (
14   $html,
15   map "$html/$_", qw( bin FS
16                       FS/cdr FS/cust_main FS/cust_pkg FS/detail_format
17                       FS/part_event FS/part_event/Condition FS/part_event/Action
18                       FS/part_export FS/part_pkg FS/pay_batch
19                       FS/ClientAPI FS/Cron FS/Misc FS/Report FS/Report/Table
20                       FS/TicketSystem FS/UI
21                       FS/SelfService
22                     )
23 ) {
24   -d $dir or mkdir $dir;
25 }
26
27 $|=1;
28
29 die "Can't find $site_perl" unless -d $site_perl;
30 #die "Can't find $catman" unless -d $catman;
31 -d $html or mkdir $html;
32
33 my $count = 0;
34
35 #make some useless links
36 foreach my $file (
37   glob("$site_perl/bin/freeside-*"),
38 ) {
39   next if $file =~ /\.pod$/;
40   #symlink $file, "$file.pod"; # or die "link $file to $file.pod: $!";
41   #system("cp $file $file.pod");
42   -e "$file.pod" or system("cp $file $file.pod");
43 }
44
45 #just for filename_to_pagename for now
46 use WWW::Mediawiki::Client;
47 my $mvs = WWW::Mediawiki::Client->new(
48             'host'           => 'www.freeside.biz',
49             'protocol'       => 'https',
50             'wiki_path'      => 'mediawiki/index.php',
51             'username'       => $mw_username,
52             'password'       => $mw_password,
53             #'commit_message' => 'import from POD'
54           );
55 #$mvs->do_login;
56
57 use MediaWiki;
58
59 my $c = MediaWiki->new;
60 # $is_ok = $c->setup("config.ini");
61 $c->setup({
62   'bot' => { 'user' => $mw_username, 'pass' => $mw_password },
63   'wiki' => {
64     'host' => 'www.freeside.biz',
65     'path' => 'mediawiki',
66     #'has_query' => 1,
67
68   }
69 }) or die "Mediawiki->setup failed";
70
71 my @files;
72 if ( @ARGV ) {
73   @files = @ARGV;
74 } else {
75   @files = (
76     glob("$site_perl/*.pm"),
77     glob("$site_perl/*/*.pm"),
78     glob("$site_perl/*/*/*.pm"),
79     glob("$site_perl/*/*/*/*.pm"),
80     glob("$site_perl/bin/*.pod"),
81     glob("./fs_selfservice/FS-SelfService/*.pm"),
82     glob("./fs_selfservice/FS-SelfService/*/*.pm"),
83   );
84
85 }
86
87 foreach my $file (@files) {
88   next if $file =~ /(^|\/)blib\//;
89   next if $file =~ /(^|\/)CVS\//;
90   #$file =~ /\/([\w\-]+)\.pm$/ or die "oops file $file";
91   my $name;
92   if ( $file =~ /fs_\w+\/FS\-\w+\/(.*)\.pm$/ ) {
93     $name = "FS/$1";
94   } elsif ( $file =~ /$site_perl\/(.*)\.(pm|pod)$/ ) {
95     $name = $1;
96   } else {
97     die "oops file $file";
98   }
99
100   #exit if $count++ == 10;
101
102   my $htmlroot = join('/', map '..',1..(scalar($file =~ tr/\///)-2)) || '.';
103
104   system "pod2wiki  --style mediawiki $file >$html/$name.rawwiki";
105
106   if ( -e "$html/$name.rawwiki" ) {
107     print "processing $name\n";
108   } else {
109     print "skipping $name\n";
110     next;
111   };
112
113 #  $mvs->do_update("$html/$name.wiki");
114
115
116   my $text = '';
117   open(RAW, "<$html/$name.rawwiki") or die $!;
118   while (<RAW>) {
119     s/\[\[([^#p][^\]]*)\]\]/"[[$html\/". w_e($1). "|$1]]"/ge;
120     $text .= $_;
121   }
122   close RAW;
123
124   my $pagename = $mvs->filename_to_pagename("$html/$name.wiki");
125   #print " uploading to $pagename\n";
126
127   $c->text( $pagename, $text );
128
129 }
130
131 sub w_e {
132   my $s = shift;
133   $s =~ s/_/ /g;
134   $s =~ s/::/\//g;
135   $s =~ s/^freeside-/bin\/freeside-/g;
136   $s;
137 }
138
139
140 ##  system "pod2text $file >$catman/$name.txt"; 
141 ##
142 #  system "pod2html --podroot=$site_perl --podpath=./FS:./FS/UI:.:./bin --norecurse --htmlroot=$htmlroot $file >$html/$name.html";
143 #  #system "pod2html --podroot=$site_perl --htmlroot=$htmlroot $file >$html/$name.html";
144 ##  system "pod2html $file >$html/$name.html";
145 ##
146
147 #remove the useless links
148 unlink glob("$site_perl/bin/*.pod");
149