From d1cfd87939764b395c3f32c0090d51a6ebce97cd Mon Sep 17 00:00:00 2001 From: bp-sawyers Date: Mon, 22 Nov 2010 13:19:14 +0000 Subject: [PATCH] Added command to download/convert xcat wiki docs git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8230 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/bin/getxcatdocs | 93 +++++++++++++++++++++++++ xCAT-client/pods/man1/getxcatdocs.1.pod | 69 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100755 xCAT-client/bin/getxcatdocs create mode 100644 xCAT-client/pods/man1/getxcatdocs.1.pod diff --git a/xCAT-client/bin/getxcatdocs b/xCAT-client/bin/getxcatdocs new file mode 100755 index 000000000..6076c5f27 --- /dev/null +++ b/xCAT-client/bin/getxcatdocs @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html + +# Downloads/converts the xCAT docs on the sourceforge wiki to HTML and PDF + +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; +} +use strict; +use lib "$::XCATROOT/lib/perl"; +#use xCAT::Utils; +use Getopt::Long; +use Data::Dumper; + +my $VERSION; +my $HELP; + +my $usage = sub { + my $exitcode = shift @_; + print "Usage: getxcatdocs [-v|--version] [-?|-h|--help] []\n"; + exit $exitcode; +}; + +# Process the cmd line args +Getopt::Long::Configure("bundling"); +#Getopt::Long::Configure("pass_through"); +Getopt::Long::Configure("no_pass_through"); +if (!GetOptions('h|?|help' => \$HELP, 'v|version' => \$VERSION) ) { $usage->(1); } + +if ($HELP || (scalar(@ARGV)==0 && !$VERSION)) { $usage->(0); } + +if ($VERSION) { + #print xCAT::Utils->Version(), "\n"; + exit; +} + +#if (xCAT::Utils->isAIX()) { die "Error: this command is not yet supported on AIX.\n"; } +if ($^O =~ /^aix/i) { die "Error: this command is not yet supported on AIX.\n"; } + +my $destdir = scalar(@ARGV) ? $ARGV[0] : '.'; +chdir($destdir); + +# Download the HTML +mkdir('html'); +chdir('html'); +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); + +# 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'); +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"; + my $destfile = "$docname.pdf"; + my $cmd = "xhtml2pdf $url $destfile"; + runh2p($cmd); +} + +# Run the wget cmd and filter out some of the silly output +sub runwget { + my $cmd = shift; + #print "$cmd\n"; + open(OUT, "$cmd 2>&1 |") || die "can't fork $cmd: $!\n"; + while () { + if (/URL:https*:\/\/sourceforge\.net.+\s+->\s+\"(\S+)\"\s+\[/) { print "Downloaded $1.\n"; } + else { print; } + } + close OUT || die "Error running $cmd: $! $?"; +} + +# Run the xhtml2pdf cmd and filter out some of the silly output +sub runh2p { + my $cmd = shift; + #print "$cmd\n"; + open(OUT, "$cmd 2>&1 |") || die "can't fork $cmd: $!\n"; + while () { + next if /DeprecationWarning:\sthe sets module is deprecated/; + next if /from sets import ImmutableSet/; + next if /^Converting\ssourceforge.net/; + print; + } + close OUT || die "Error running $cmd: $! $?"; +} diff --git a/xCAT-client/pods/man1/getxcatdocs.1.pod b/xCAT-client/pods/man1/getxcatdocs.1.pod new file mode 100644 index 000000000..08c5ad28c --- /dev/null +++ b/xCAT-client/pods/man1/getxcatdocs.1.pod @@ -0,0 +1,69 @@ +=head1 NAME + +B - downloads the xCAT documentation and converts to HTML and PDF + +=head1 SYNOPSIS + +B [B<-?> | B<-h> | B<--help> | B<-v> | B<--version>] [I] + +=head1 DESCRIPTION + +The B command downloads the xCAT documentation from the wiki and converts it to both HTML and PDF. +This enables reading the documentation when you do not have internet access. Note that this command does not +download/convert the entire xCAT wiki - only the "official" xCAT documentation linked from https://sourceforge.net/apps/mediawiki/xcat/index.php?title=XCAT_Documentation . + +If I is specified, B will put the converted documentation in that directory, in 2 sub-directories: html, pdf. +Otherwise, it will put it in the current directory (in the same two sub-directories). + +B uses wget to do the download the documents and xhtml2pdf to convert them to PDF. To install xhtml2pdf, see: +https://sourceforge.net/apps/mediawiki/xcat/index.php?title=Editing_xCAT_Documentation_Pages#Converting_Wiki_Pages_to_HTML_and_PDFs . + +=head2 Limitations: + +=over 3 + +=item * + +This command does not run on AIX or Windows. + +=item * + +The conversion to HTML does not yet honor the xCAT wiki style sheet. + +=back + +=head1 OPTIONS + +=over 10 + +=item B<-v|--version> + +Command Version. + +=item B<-?|-h|--help> + +Display usage message. + +=back + +=head1 RETURN VALUE + +0 The command completed successfully. + +1 An error has occurred. + +=head1 EXAMPLES + +=over 3 + +=item 1. + +To download/convert the documentation and put it in ~/tmp: + + getxcatdocs ~/tmp + +=back + +=head1 FILES + +/opt/xcat/bin/getxcatdocs