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