made links work in the downloaded docs in getxcatdocs

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10968 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
bp-sawyers 2011-11-03 22:17:32 +00:00
parent 6588d4c213
commit 902d223fb8

View File

@ -22,10 +22,11 @@ use Getopt::Long;
#my $VERSION;
my $HELP;
my $UPLOAD;
my $UPLOADONLY;
my $usage = sub {
my $exitcode = shift @_;
print "Usage: getxcatdocs [-?|-h|--help] [-u|--upload] [<destination-dir>]\n";
print "Usage: getxcatdocs [-?|-h|--help] [-u|--upload] [--uploadonly] [<destination-dir>]\n";
exit $exitcode;
};
@ -33,7 +34,7 @@ my $usage = sub {
Getopt::Long::Configure("bundling");
#Getopt::Long::Configure("pass_through");
Getopt::Long::Configure("no_pass_through");
if (!GetOptions('h|?|help' => \$HELP, 'u|upload' => \$UPLOAD )) { $usage->(1); }
if (!GetOptions('h|?|help' => \$HELP, 'u|upload' => \$UPLOAD, 'uploadonly' => \$UPLOADONLY )) { $usage->(1); }
if ($HELP) { $usage->(0); }
@ -45,50 +46,68 @@ if ($HELP) { $usage->(0); }
if ($^O =~ /^aix/i) { die "Error: this command is not yet supported on AIX.\n"; }
my $destdir = scalar(@ARGV) ? $ARGV[0] : '.';
chdir($destdir);
chdir($destdir) or die "Can not cd to $destdir: $!\n";
#my $docdir = $ENV{'PWD'};
# Download the HTML
mkdir('html');
chdir('html');
unlink <*>; # delete all the files in the dir, in case they previously ran this
print "Downloading the xCAT wiki documentation...\n";
my $wgetcmd = q(wget -rk -nv --progress=bar -l 1 --page-requisites -np -nH --cut-dirs=3 -e robots=off --post-data='printable=yes' --reject '*title=Special:*,*title=Talk:*,*title=-&*,*title=HowTos,*title=Main_Page,*title=Release_Notes,*title=Wish_List_for_xCAT_2,*&action=edit*,*&action=history*,*&printable=yes*,*&oldid=*,index.html,opensearch_desc.php,xcat' 'https://sourceforge.net/apps/mediawiki/xcat/index.php?title=XCAT_Documentation');
runwget($wgetcmd);
my @dir;
if (!$UPLOADONLY) {
mkdir('html');
chdir('html');
#system('pwd');
unlink <*>; # delete all the files in the dir, in case they previously ran this
#system('rm -rf nfs skins');
#system('ls');
print "Downloading the xCAT wiki documentation...\n";
# --html-extension --restrict-file-names=windows --cut-dirs=3
# options that do not work: --relative
my $wgetcmd = q(wget --recursive --convert-links --no-verbose --progress=bar --level=1 --page-requisites --no-parent --no-host-directories --no-directories --execute robots=off --post-data='printable=yes' --reject '*title=Special:*,*title=Talk:*,*title=-&*,*title=HowTos,*title=Main_Page,*title=MediaWiki:*,*title=Release_Notes,*title=Wish_List_for_xCAT_2,*&action=edit*,*&action=history*,*&printable=yes*,*&oldid=*,index.html,opensearch_desc.php,xcat,login.php,support' 'https://sourceforge.net/apps/mediawiki/xcat/index.php?title=XCAT_Documentation&printable=yes');
runwget($wgetcmd);
# remove the dir portion of links to other docs
#my $sedcmd = q(sed -i 's/<a href="\/apps\/mediawiki\/xcat\/index.php?title/<a href="index.php%3Ftitle/' *);
my $sedcmd = q(sed -i 's/<a href="index.php?title/<a href="index.php%3Ftitle/' *);
print "$sedcmd\n";
system($sedcmd);
# get the list of docs
opendir(DIR, '.') or die "Error: could not read the just created html directory.\n";
@dir = grep /^index.php\?title=/, readdir(DIR); # /
close(DIR);
chdir('..');
}
# Get the list of files and convert to pdf
opendir(DIR, '.') or die "Error: could not read the just created html directory.\n";
my @dir = grep /^index.php\?title=/, readdir(DIR); # /
close(DIR);
mkdir('../pdf');
chdir('../pdf');
unlink <*>; # delete all the files in the dir, in case they previously ran this
if (system('which xhtml2pdf >/dev/null 2>&1')) { die "xhtml2pdf is not installed. See http://sourceforge.net/apps/mediawiki/xcat/index.php?title=Editing_xCAT_Documentation_Pages#Converting_Wiki_Pages_to_HTML_and_PDFs .\n"; }
foreach my $file (@dir) {
if ($file =~ /^index.php\?title=MediaWiki:/ || $file eq 'index.php?title=XCAT_Documentation') { next; }
my ($docname) = $file =~ /^index.php\?title=(.+)$/;
print "Converting $docname to PDF format...\n";
my $url = "https://sourceforge.net/apps/mediawiki/xcat/$file&printable=yes";
my $destfile = "$docname.pdf";
my $cmd = "xhtml2pdf '$url' '$destfile' ";
#print "$cmd\n";
runh2p($cmd);
# Convert to pdf
if (!$UPLOADONLY) {
if (system('which xhtml2pdf >/dev/null 2>&1')) { die "xhtml2pdf is not installed. See http://sourceforge.net/apps/mediawiki/xcat/index.php?title=Editing_xCAT_Documentation_Pages#Converting_Wiki_Pages_to_HTML_and_PDFs .\n"; }
mkdir('pdf');
chdir('pdf');
unlink <*>; # delete all the files in the dir, in case they previously ran this
foreach my $file (@dir) {
if ($file =~ /^index.php\?title=MediaWiki:/ || $file eq 'index.php?title=XCAT_Documentation') { next; }
my ($docname) = $file =~ /^index.php\?title=(.+)$/;
print "Converting $docname to PDF format...\n";
my $url = "https://sourceforge.net/apps/mediawiki/xcat/$file&printable=yes";
my $destfile = "$docname.pdf";
my $cmd = "xhtml2pdf '$url' '$destfile' ";
#print "$cmd\n";
runh2p($cmd);
}
chdir('..');
}
# tar/compress
chdir('..');
my $date=`date +%Y%m%d%H%M`;
chop $date;
my $docname="xcat-docs-snap$date.tar.gz";
#system('pwd');
system("tar -zcf $docname html pdf 2>&1");
# Optionally upload the tarball to sourceforge
if ($UPLOAD) {
if ($UPLOAD || $UPLOADONLY) {
my $UPLOADUSER = 'bp-sawyers';
my $count = 1;
my $cmd = "rsync -v $docname $UPLOADUSER," . 'xcat@web.sourceforge.net:htdocs/doc/ 2>&1';
my $cmd = "rsync -v $docname $UPLOADUSER," . 'xcat@web.sourceforge.net:htdocs/doc/';
print "$cmd\n";
while ($count<=5 && system($cmd)) { $count++; }
while ($count<=5 && system("$cmd 2>&1")) { $count++; }
}
exit 0;