2015-03-08 20:05:41 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
|
|
|
# pg_backrest.pl - Simple Postgres Backup and Restore
|
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
2015-07-06 23:59:44 +02:00
|
|
|
$SIG{__DIE__} = sub { Carp::confess @_ };
|
|
|
|
|
2015-08-07 20:43:53 +02:00
|
|
|
use Cwd qw(abs_path);
|
2015-03-08 20:05:41 +02:00
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Getopt::Long qw(GetOptions);
|
2015-08-07 20:43:53 +02:00
|
|
|
use Pod::Usage qw(pod2usage);
|
2015-11-22 23:44:01 +02:00
|
|
|
use Storable;
|
2015-03-08 20:05:41 +02:00
|
|
|
use XML::Checker::Parser;
|
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
use lib dirname($0) . '/lib';
|
2015-10-28 11:10:36 +02:00
|
|
|
use BackRestDoc::Common::Doc;
|
|
|
|
use BackRestDoc::Common::DocConfig;
|
2015-11-22 23:44:01 +02:00
|
|
|
use BackRestDoc::Common::DocManifest;
|
2015-10-28 11:10:36 +02:00
|
|
|
use BackRestDoc::Common::DocRender;
|
2015-11-22 23:44:01 +02:00
|
|
|
use BackRestDoc::Html::DocHtmlSite;
|
|
|
|
use BackRestDoc::Latex::DocLatex;
|
2015-12-23 18:04:26 +02:00
|
|
|
use BackRestDoc::Markdown::DocMarkdown;
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2015-03-08 20:05:41 +02:00
|
|
|
use lib dirname($0) . '/../lib';
|
2015-08-29 20:20:46 +02:00
|
|
|
use BackRest::Common::Log;
|
|
|
|
use BackRest::Common::String;
|
2015-09-08 13:31:24 +02:00
|
|
|
use BackRest::Config::Config;
|
2015-11-22 23:44:01 +02:00
|
|
|
use BackRest::FileCommon;
|
2015-03-08 20:05:41 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Usage
|
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2015-07-02 16:05:13 +02:00
|
|
|
doc.pl - Generate pgBackRest documentation
|
2015-03-08 20:05:41 +02:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
doc.pl [options] [operation]
|
|
|
|
|
|
|
|
General Options:
|
|
|
|
--help display usage and exit
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-09-03 00:55:04 +02:00
|
|
|
# Operation constants
|
2015-03-08 20:05:41 +02:00
|
|
|
####################################################################################################################################
|
2015-09-03 00:55:04 +02:00
|
|
|
use constant OP_MAIN => 'Main';
|
2015-03-08 20:05:41 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
use constant OP_MAIN_DOC_PROCESS => OP_MAIN . '::docProcess';
|
2015-03-08 20:05:41 +02:00
|
|
|
|
2015-08-07 20:43:53 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Load command line parameters and config
|
|
|
|
####################################################################################################################################
|
2015-09-03 00:55:04 +02:00
|
|
|
my $bHelp = false; # Display usage
|
|
|
|
my $bVersion = false; # Display version
|
|
|
|
my $bQuiet = false; # Sets log level to ERROR
|
|
|
|
my $strLogLevel = 'info'; # Log level for tests
|
2015-10-28 11:10:36 +02:00
|
|
|
my $bNoExe = false; # Should commands be executed when buildng help? (for testing only)
|
2015-11-22 23:44:01 +02:00
|
|
|
my $bUseCache = false; # Use cached data to generate the docs (for testing code changes only)
|
|
|
|
my $oVariableOverride = {}; # Override variables
|
|
|
|
my $strDocPath; # Document path to render
|
|
|
|
my @stryOutput; # Output types
|
|
|
|
my @stryKeyword; # Keyword used to filter output
|
|
|
|
my @stryRequire; # Required sections of the document (to speed testing)
|
2015-08-07 20:43:53 +02:00
|
|
|
|
|
|
|
GetOptions ('help' => \$bHelp,
|
|
|
|
'version' => \$bVersion,
|
|
|
|
'quiet' => \$bQuiet,
|
2015-10-28 11:10:36 +02:00
|
|
|
'log-level=s' => \$strLogLevel,
|
2015-11-22 23:44:01 +02:00
|
|
|
'out=s@' => \@stryOutput,
|
|
|
|
'keyword=s@' => \@stryKeyword,
|
|
|
|
'require=s@' => \@stryRequire,
|
|
|
|
'no-exe', \$bNoExe,
|
|
|
|
'use-cache', \$bUseCache,
|
|
|
|
'var=s%', $oVariableOverride,
|
|
|
|
'doc-path=s', \$strDocPath)
|
2015-08-07 20:43:53 +02:00
|
|
|
or pod2usage(2);
|
|
|
|
|
|
|
|
# Display version and exit if requested
|
|
|
|
if ($bHelp || $bVersion)
|
|
|
|
{
|
|
|
|
print 'pg_backrest ' . version_get() . " doc builder\n";
|
|
|
|
|
|
|
|
if ($bHelp)
|
|
|
|
{
|
|
|
|
print "\n";
|
|
|
|
pod2usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Set no-exe if use-cache is set
|
|
|
|
if ($bUseCache)
|
|
|
|
{
|
|
|
|
$bNoExe = true;
|
|
|
|
}
|
|
|
|
|
2015-08-07 20:43:53 +02:00
|
|
|
# Set console log level
|
|
|
|
if ($bQuiet)
|
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
$strLogLevel = 'error';
|
|
|
|
}
|
|
|
|
|
|
|
|
# If no keyword we passed then use default
|
|
|
|
if (@stryKeyword == 0)
|
|
|
|
{
|
2016-03-23 04:18:33 +02:00
|
|
|
@stryKeyword = ('default');
|
2015-08-07 20:43:53 +02:00
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
logLevelSet(undef, uc($strLogLevel));
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
# Get the base path
|
2015-08-07 20:43:53 +02:00
|
|
|
my $strBasePath = abs_path(dirname($0));
|
2015-12-23 18:04:26 +02:00
|
|
|
|
|
|
|
if (!defined($strDocPath))
|
|
|
|
{
|
|
|
|
$strDocPath = $strBasePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strOutputPath = "${strDocPath}/output";
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
sub docProcess
|
2015-08-07 20:43:53 +02:00
|
|
|
{
|
2015-09-03 00:55:04 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strXmlIn,
|
|
|
|
$strMdOut,
|
2015-11-22 23:44:01 +02:00
|
|
|
$oManifest
|
2015-09-03 00:55:04 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_MAIN_DOC_PROCESS, \@_,
|
|
|
|
{name => 'strXmlIn'},
|
|
|
|
{name => 'strMdOut'},
|
2015-10-28 11:10:36 +02:00
|
|
|
{name => 'oHtmlSite'}
|
2015-09-03 00:55:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Build the document from xml
|
2015-10-28 11:10:36 +02:00
|
|
|
my $oDoc = new BackRestDoc::Common::Doc($strXmlIn);
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
# Write markdown
|
2015-11-22 23:44:01 +02:00
|
|
|
my $oRender = new BackRestDoc::Common::DocRender('markdown', $oManifest);
|
|
|
|
$oRender->save($strMdOut, $oManifest->variableReplace($oRender->process($oDoc)));
|
2015-08-07 20:43:53 +02:00
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Create the out path if it does not exist
|
|
|
|
if (!-e $strOutputPath)
|
|
|
|
{
|
|
|
|
mkdir($strOutputPath)
|
|
|
|
or confess &log(ERROR, "unable to create path ${strOutputPath}");
|
|
|
|
}
|
2015-09-08 13:31:24 +02:00
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Load the manifest
|
|
|
|
my $oManifest;
|
|
|
|
my $strManifestCache = "${strOutputPath}/manifest.cache";
|
|
|
|
|
|
|
|
if ($bUseCache && -e $strManifestCache)
|
|
|
|
{
|
|
|
|
$oManifest = retrieve($strManifestCache);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oManifest = new BackRestDoc::Common::DocManifest(\@stryKeyword, \@stryRequire, $oVariableOverride, $strDocPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
# If no outputs were given
|
|
|
|
if (@stryOutput == 0)
|
|
|
|
{
|
|
|
|
@stryOutput = $oManifest->renderList();
|
|
|
|
|
|
|
|
if ($oManifest->isBackRest())
|
|
|
|
{
|
|
|
|
push(@stryOutput, 'help');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $strOutput (@stryOutput)
|
|
|
|
{
|
|
|
|
if (!(($strOutput eq 'help' || $strOutput eq 'markdown') && $oManifest->isBackRest()))
|
|
|
|
{
|
|
|
|
$oManifest->renderGet($strOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "render ${strOutput} output");
|
|
|
|
|
|
|
|
if ($strOutput eq 'markdown' && $oManifest->isBackRest())
|
|
|
|
{
|
|
|
|
# Generate the markdown
|
|
|
|
docProcess("${strBasePath}/xml/index.xml", "${strBasePath}/../README.md", $oManifest);
|
|
|
|
docProcess("${strBasePath}/xml/change-log.xml", "${strBasePath}/../CHANGELOG.md", $oManifest);
|
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
|
|
|
|
if ($strOutput eq 'markdown')
|
2015-12-23 18:04:26 +02:00
|
|
|
{
|
|
|
|
my $oMarkdown =
|
|
|
|
new BackRestDoc::Markdown::DocMarkdown
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/markdown",
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oMarkdown->process();
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
elsif ($strOutput eq 'help' && $oManifest->isBackRest())
|
|
|
|
{
|
|
|
|
# Generate the command-line help
|
|
|
|
my $oRender = new BackRestDoc::Common::DocRender('text', $oManifest);
|
|
|
|
my $oDocConfig =
|
|
|
|
new BackRestDoc::Common::DocConfig(
|
|
|
|
new BackRestDoc::Common::Doc("${strBasePath}/xml/reference.xml"), $oRender);
|
|
|
|
$oDocConfig->helpDataWrite($oManifest);
|
|
|
|
}
|
|
|
|
elsif ($strOutput eq 'html')
|
|
|
|
{
|
|
|
|
my $oHtmlSite =
|
|
|
|
new BackRestDoc::Html::DocHtmlSite
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/html",
|
|
|
|
"${strBasePath}/resource/html/default.css",
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oHtmlSite->process();
|
|
|
|
}
|
|
|
|
elsif ($strOutput eq 'pdf')
|
|
|
|
{
|
|
|
|
my $oLatex =
|
|
|
|
new BackRestDoc::Latex::DocLatex
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/latex",
|
|
|
|
"${strBasePath}/resource/latex/preamble.tex",
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oLatex->process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cache the manifest (mostly useful for testing rendering changes in the code)
|
|
|
|
if (!$bUseCache)
|
2015-10-28 11:10:36 +02:00
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
store($oManifest, $strManifestCache);
|
2015-10-28 11:10:36 +02:00
|
|
|
}
|