Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
autodoc: initial, director resource directives tables
Browse files Browse the repository at this point in the history
query bareos-dir to get information about all resource and directives.
Use this to create Latex tables.
  • Loading branch information
joergsteffens committed Oct 2, 2014
1 parent d3fbe74 commit 233f852
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 10 deletions.
21 changes: 15 additions & 6 deletions manuals/en/main/Makefile
Expand Up @@ -2,11 +2,14 @@
subdirs = ../../images/

MAKE=make
MKDIR=mkdir -p
LATEX=latex
DVI2PDF=dvipdf
PDFLATEX=pdflatex
MAKEINDEX=makeindex
CONVERT=convert
BAREOS_DIR=/usr/sbin/bareos-dir
GENERATED_RESOURCE_DESCRIPTIONS=../../scripts/generate-resoure-descriptions.py

INDEXES = bareos-manual-main-reference.console.ind \
bareos-manual-main-reference.director.ind \
Expand Down Expand Up @@ -34,7 +37,7 @@ pdf: bareos-manual-main-reference.pdf

html: html/bareos-manual-main-reference.html

html/bareos-manual-main-reference.html: depend *.sty *.tex $(HTINDEXES) bareos-manual-main-reference.toc
html/bareos-manual-main-reference.html: depend *.sty *.tex autogenerated/*.tex $(HTINDEXES) bareos-manual-main-reference.toc
mkdir -p html
htlatex bareos-manual-main-reference "bareos-manual-main-reference.htlatex.cfg" "" -d./html/

Expand All @@ -56,21 +59,27 @@ html/bareos-manual-main-reference.html: depend *.sty *.tex $(HTINDEXES) bareos-m
bareos-manual-main-reference.toc: *.tex
$(LATEX) bareos-manual-main-reference.tex

bareos-manual-main-reference.dvi: depend *.sty *.tex $(INDEXES) bareos-manual-main-reference.toc
bareos-manual-main-reference.dvi: depend *.sty *.tex autogenerated/*.tex $(INDEXES) bareos-manual-main-reference.toc
$(LATEX) bareos-manual-main-reference.tex
$(LATEX) bareos-manual-main-reference.tex

#bareos-manual-main-reference.pdf: bareos-manual-main-reference.dvi
# $(DVI2PDF) bareos-manual-main-reference.dvi bareos-manual-main-reference.pdf

bareos-manual-main-reference.pdf: depend *.sty *.tex $(INDEXES) bareos-manual-main-reference.toc
bareos-manual-main-reference.pdf: depend *.sty *.tex autogenerated/*.tex $(INDEXES) bareos-manual-main-reference.toc
$(PDFLATEX) bareos-manual-main-reference.tex
$(PDFLATEX) bareos-manual-main-reference.tex

autogenerated/bareos-dir-config-schema.json:
$(MKDIR) autogenerated/
$(BAREOS_DIR) -x > autogenerated/bareos-dir-config-schema.json

autogenerated/*.tex: autogenerated/bareos-dir-config-schema.json
# generates all director-resource files, not only director-resource-director-table.tex
$(GENERATED_RESOURCE_DESCRIPTIONS) autogenerated/bareos-dir-config-schema.json

check: bareos-manual-main-reference.pdf
@if ! grep "LaTeX Warning: Hyper reference .* undefined on input\|LaTeX Warning: There were undefined references." $(LOG); then echo "CHECK: OK"; true; else echo "CHECK: FAILED: undefined references"; false; fi

clean:
rm -f *.4ct *.4dx *.4ix *.4tc *.aux *.dvi *.htidx *.htind *.idx *.log *.out *.pdf *.toc *.idv *.lg *.tmp *.xref html/* bareos-manual-main-reference.html bareos-manual-main-reference.css
rm autogenerated/*
@for I in ${subdirs}; \
do (cd $$I; echo "==>Entering directory `pwd`"; $(MAKE) clean || exit 1); done
3 changes: 3 additions & 0 deletions manuals/en/main/bareos.sty
Expand Up @@ -49,6 +49,9 @@
\newcommand{\dtTime}{\ilink{time}{DataTypeTime}}
\newcommand{\dtYesNo}{\ilink{\yesno}{DataTypeYesNo}}

\newcommand{\dt}[1]{\path|#1|}


%%
\newcommand*{\elink}[2]{%
\htmladdnormallink{#1}{#2}%
Expand Down
2 changes: 2 additions & 0 deletions manuals/en/main/dirdconf-fileset.tex
Expand Up @@ -16,6 +16,8 @@ \section{FileSet Resource}
of the Include/Exclude contents). Each time a new FileSet is created,
Bareos will ensure that the next backup is always a Full save.

\input{autogenerated/director-resource-fileset-table.tex}

\begin{description}

\item [FileSet]
Expand Down
20 changes: 18 additions & 2 deletions manuals/en/main/dirdconf.tex
Expand Up @@ -27,7 +27,7 @@ \chapter{Director Configuration}

\begin{itemize}
\item
\ilink{Director}{DirectorResource} -- to define the Director's
\ilink{Director}{DirectorResourceDirector} -- to define the Director's
name and its access password used for authenticating the Console program.
Only a single Director resource definition may appear in the Director's
configuration file. If you have either {\bf /dev/random} or {\bf bc} on your
Expand Down Expand Up @@ -83,6 +83,7 @@ \chapter{Director Configuration}
\end{itemize}

\section{Director Resource}
\label{DirectorResourceDirector}
\label{DirectorResource4}
\index[general]{Director Resource}
\index[general]{Resource!Director}
Expand All @@ -104,6 +105,7 @@ \section{Director Resource}
}
\end{bconfig}

\input{autogenerated/director-resource-director-table.tex}

\begin{description}

Expand Down Expand Up @@ -446,6 +448,7 @@ \section{Job Resource}
FileSet definitions (the names must be different, but the contents of
the FileSets may be the same).

\input{autogenerated/director-resource-job-table.tex}

\begin{description}

Expand Down Expand Up @@ -1988,6 +1991,8 @@ \section{Schedule Resource}
resources. If a Schedule resource is not referenced in a Job, the Job can only
be run manually. In general, you specify an action to be taken and when.

\input{autogenerated/director-resource-schedule-table.tex}

\begin{description}

\item [Schedule] \hfill \\
Expand Down Expand Up @@ -2268,6 +2273,8 @@ \section{Client Resource}
this Director; that is the machines that are to be backed up. You will need
one Client resource definition for each machine to be backed up.

\input{autogenerated/director-resource-client-table.tex}

\begin{description}

\item [Client (or FileDaemon)]
Expand Down Expand Up @@ -2500,6 +2507,8 @@ \section{Storage Resource}
The Storage resource defines which Storage daemons are available for use by
the Director.

\input{autogenerated/director-resource-storage-table.tex}

\begin{description}

\item [Storage]
Expand Down Expand Up @@ -2786,7 +2795,9 @@ \section{Pool Resource}
the Console program.

The Pool Resource defined in the Director's configuration file
(bareos-dir.conf) may contain the following directives:
(\file{bareos-dir.conf}) may contain the following directives:

\input{autogenerated/director-resource-pool-table.tex}

\begin{description}
\item [Pool]
Expand Down Expand Up @@ -3356,6 +3367,7 @@ \section{Catalog Resource}
databases, they may reside either on the same machine as the Director
or on a different machine on the network. See below for more details.

\input{autogenerated/director-resource-catalog-table.tex}

\begin{description}

Expand Down Expand Up @@ -3568,6 +3580,8 @@ \section{Console Resource}
The Console resource is optional and need not be specified. The following
directives are permitted within the Director's configuration resource:

\input{autogenerated/director-resource-console-table.tex}

\begin{description}

\item [Name = {\textless}name{\textgreater}] \hfill \\
Expand Down Expand Up @@ -3687,6 +3701,8 @@ \section{Counter Resource}
\ilink{LabelFormat}{Label} directive in this chapter for more
details.

\input{autogenerated/director-resource-counter-table.tex}

\begin{description}

\item [Counter]
Expand Down
2 changes: 2 additions & 0 deletions manuals/en/main/messagesres.tex
Expand Up @@ -61,6 +61,8 @@ \chapter{Messages Resource}
The following are the list of the possible record definitions that can be used
in a message resource.

\input{autogenerated/director-resource-messages-table.tex}

\begin{description}

\item [Messages] \hfill \\
Expand Down
142 changes: 142 additions & 0 deletions manuals/scripts/generate-resoure-descriptions.py
@@ -0,0 +1,142 @@
#!/usr/bin/env python

import argparse
import logging
import json
from pprint import pprint
import sys

class BareosConfigurationSchema:
def __init__( self, json ):
self.json = json

def getResources(self):
return sorted(filter( None, self.json.keys()) )

def getResource(self, resourcename):
return self.json[resourcename]

def getResourceDirectives(self, resourcename):
return sorted(filter( None, self.getResource(resourcename).keys()) )

def getResourceDirective(self, resourcename, directive, deprecated=None):
# TODO:
# deprecated:
# None: include deprecated
# False: exclude deprecated
# True: only deprecated
return self.json[resourcename][directive]


class BareosConfigurationSchema2Latex:
def __init__( self, json ):
self.json = json
self.schema = BareosConfigurationSchema( json )

def open(self, filename = None, mode = 'r'):
if filename:
self.out=open( filename, mode )
else:
self.out=sys.stdout

def close(self):
if self.out != sys.stdout:
self.out.close()

def getResources(self):
result = "\\begin{itemize}\n"
for i in self.schema.getResources():
if i:
result += " \\item " + i + "\n"
result += "\\end{itemize}\n"
return result

def getResourceDirectivesTable(self, resourcename):
result="\\begin{center}\n"
result+="\\begin{tabular}{l | l | l | l}\n"
result+=" name & type of data & required & default value \\\\ \n"
result+="\\hline \n"
for directive in self.schema.getResourceDirectives(resourcename):
data=self.schema.getResourceDirective(resourcename, directive)

m="{"
extra=""

if data.get( 'equals' ):
datatype="= \\dt{"+data['datatype']+"}"
else:
datatype="\{ \\dt{"+data['datatype']+"} \}"

deprecated=""
if data.get( 'deprecated' ):
extra="deprecated"
m="\\textit{"
required=""
if data.get( 'required' ):
extra="required"
m="\\textbf{"
default=""
if data.get( 'default_value' ):
default=data.get( 'default_value' )

result+=m+directive + "} & " + m + datatype + "} & " + m + default + "} & " + m + extra + "}\\\\ \n"
result+="\\end{tabular}\n"
result+="\\end{center}\n"
result+="\n"
return result

def writeResourceDirectivesTable(self, resourcename, filename=None):
self.open(filename, "w")
self.out.write( self.getResourceDirectivesTable( resourcename ) )
self.close()

def getResourceDirectives(self, resourcename):
result="\\begin{description}\n\n"
for directive in self.schema.getResourceDirectives(resourcename):
data=self.schema.getResourceDirective(resourcename, directive)

datatype="\\dt{"+data['datatype']+"}"
deprecated=""
if data.get( 'deprecated' ):
deprecated="deprecated"
required=""
if data.get( 'required' ):
required="required"
default=""
if data.get( 'default_value' ):
default=data.get( 'default_value' )

result+="\\xdirective{dir}{"+directive+"}{"+datatype+"}{"+required+"}{"+default+"}{"+deprecated+"}{%\n"
result+="}\n\n"
result+="\\end{description}\n\n"
return result

def writeResourceDirectives(self, resourcename, filename=None):
self.open(filename, "w")
self.out.write( self.getResourceDirectives( resourcename ) )
self.close()

if __name__ == '__main__':
logging.basicConfig(format='%(levelname)s %(module)s.%(funcName)s: %(message)s', level=logging.INFO)
logger = logging.getLogger()

parser = argparse.ArgumentParser()
parser.add_argument( '-d', '--debug', action='store_true', help="enable debugging output" )
parser.add_argument("filename", help="load json file")
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.DEBUG)

with open(args.filename) as data_file:
data = json.load(data_file)
#pprint(data)

#print data.keys()

schema = BareosConfigurationSchema( data )
latex = BareosConfigurationSchema2Latex( data )
#print schema.getResources()
for resource in schema.getResources():
logger.info( "resource: " + resource )
latex.writeResourceDirectives(resource, "autogenerated/director-resource-"+resource+"-description.tex")
latex.writeResourceDirectivesTable(resource, "autogenerated/director-resource-"+resource+"-table.tex")
9 changes: 7 additions & 2 deletions packaging/bareos-docs.spec
Expand Up @@ -2,11 +2,11 @@
#
# spec file for package bareos-docs
#
# Copyright (c) 2013-2013 Bareos GmbH & Co. KG
# Copyright (c) 2013-2014 Bareos GmbH & Co. KG
#

Name: bareos-docs
Version: 13.3.0
Version: 14.3.0
Release: 0
License: GFDL-1.3
Summary: Documentation
Expand All @@ -15,6 +15,11 @@ Group: Productivity/Archiving/Backup
Source: %{name}-%version.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
# bareos-database-sqlite3 is the database backend
# that has minimal additional dependencies
BuildRequires: bareos >= 14.3.0
BuildRequires: bareos-database-sqlite3
BuildRequires: python
BuildRequires: texlive-latex
BuildRequires: texlive-tex4ht ImageMagick
%if ( 0%{?rhel_version} || 0%{?fedora_version} )
Expand Down

0 comments on commit 233f852

Please sign in to comment.