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