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