Skip to content

Commit

Permalink
Addes skeleton scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Apr 29, 2014
1 parent 33202f5 commit 0ee0baf
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/*
*.swp
.#*
\#*#
*__pycache__*
*.pyc
makefile.generated
logo.png
.DS_Store
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

54 changes: 54 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
======================
MongoDB Specifications
======================

This repository holds in progress and completed specification for
features of MongoDB, Drivers, and associated products. Also contained
is a rudimentary system for producing these documents.

Writing Documents
-----------------

Write documents using `reStructuredText`_, following the `MongoDB
Documentation Style Guidelines <https://github.com/mongodb/docs/blob/master/meta.style-guide.rst>`_.

Store all source documents in the ``source/`` directory.

.. _`reStructuredText`: http://docutils.sourceforge.net/rst.html

Building Documents
------------------

To build documents issue the ``make`` command in a local copy of this
repository. The output PDFs end up in the ``build/`` directory. The
build depends on:

- `Python Docutils <http://pypi.python.org/pypi/docutils>`_

- A functioning basic LaTeX/TeX install with ``pdflatex``. If you run
OS X, use `MacTeX`_

``make all`` will build all documents in the ``source/`` folder. The
system builds all targets in ``build/``.

Run ``make setup`` to generate (or regenerate) a ``makefile.generated`
file which provides specific targets for all files in the source file
so you can choose to compile only some of the files that you
need. Once generated, running "``make [file-name-without-extension]``"
will rebuild only those files (if needed.)

Use ``make clean`` to remove the ``build/`` directory and "``make
cleanup``" to remove the LaTeX by-products from ``build/``.

.. _`MacTeX` : http://www.tug.org/mactex/
In the future...
----------------

- Templates will have logos, and templates for authorship, copyright,
disclaimers, etc.

- Non-PDF output targets.

If you have specific feature requests, or need help getting things
running, please contact [email protected].
115 changes: 115 additions & 0 deletions bin/builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/python

import os

input_dirs = ['source/']

build_dir = 'build/'
OUTPUT_FILE = build_dir + 'makefile.generated'

JOB = "\n\t"
TARGET = "\n"

######################################################################

def generate_file_tree(input_dir):
targets = []

for dirname, dirnames, filenames in os.walk(input_dir):
for filename in filenames:
source = os.path.join(dirname, filename)
target = os.path.join('build/', filename).rsplit('.',1)[0]
shortcut = filename.rsplit('.',1)[0]

if source.rsplit('.',1)[1] == "tmpl":
pass
else:
targets.append((source, target, shortcut))

return targets

def generate_converters(input_dir, output_dir):
tex_converter = (JOB + "@$(LATEXCMD) $< >$@" +
JOB + "@echo [rst2latex]: created '$@'")
html_converter = (JOB + "@$(HTMLCMD) $< >$@" +
JOB + "@echo [rst2html]: created '$@'")

converters = (TARGET + output_dir + "%.tex" + ":" + input_dir + "%.rst" + tex_converter +
TARGET + output_dir + "%.tex" + ":" + input_dir + "%.txt" + tex_converter +
TARGET + output_dir + "%.html" + ":" + input_dir + "%.rst" + html_converter +
TARGET + output_dir + "%.html" + ":" + input_dir + "%.txt" + html_converter)

return converters

def generate_builders(output_dir):
pdf_builder = (TARGET + output_dir + "%.pdf" + ":" + output_dir + "%.tex" +
JOB + "@$(PDFCMD) '$<' >|[email protected]" +
JOB + "@echo [pdflatex]: \(1/3\) built '$@'" +
JOB + "@$(PDFCMD) '$<' >>[email protected]" +
JOB + "@echo [pdflatex]: \(2/3\) built '$@'" +
JOB + "@$(PDFCMD) '$<' >>[email protected]" +
JOB + "@echo [pdflatex]: \(3/3\) built '$@'" +
JOB + "@echo [PDF]: see '[email protected]' for a full report of the pdf build process.")

builder = pdf_builder

return builder

def build_latex_targets(source, target):
intermediate = target.rsplit('.',1)[0] + ".tex"

output = (TARGET + target + ".pdf" + ':' + source +
TARGET + intermediate + ":" + source)

return output

def build_html_targets(source, target):
output = (target + ".html" + ':' + source)

return output

def build_shortcut_targets(target, shortcut):
output = (shortcut + ':' + target + ".html" + " " + target + ".pdf")

return output

######################################################################

class GeneratedMakefile(object):
def __init__(self):

self.converters = []
self.targets = []

self.builder = generate_builders(build_dir)

for dir in input_dirs:
self.converters.append(generate_converters(dir, build_dir))

for dir in input_dirs:
for (src, trg, shc) in generate_file_tree(dir):
self.targets.append(build_latex_targets(src, trg))
self.targets.append(build_html_targets(src, trg))
self.targets.append(build_shortcut_targets(trg, shc))

makefile = GeneratedMakefile()

########################################################################

def main():
output = open(OUTPUT_FILE, "w")

for line in makefile.converters:
output.write(line)

output.write(makefile.builder)
output.write('\n\n')

for line in makefile.targets:
output.write(line)
output.write('\n')

output.close()

if __name__ == "__main__":
main()
64 changes: 64 additions & 0 deletions makefile-driver
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
BUILD = build
SOURCE = driver
EXTENSION = rst

MAKEFLAGS += -j

SOURCE_FILES := $(shell find $(SOURCE) -name "*.$(EXTENSION)")
OUTPUT_PDF_FILES = $(subst $(EXTENSION),pdf,$(subst $(SOURCE),$(BUILD),$(SOURCE_FILES)))
OUTPUT_HTML_FILES = $(subst $(EXTENSION),html,$(subst $(SOURCE),$(BUILD),$(SOURCE_FILES)))

HTMLCMD = rst2html.py
LATEXCMD = rst2latex.py --latex-preamble="\usepackage{fullpage} \usepackage{parskip} \usepackage{fancyhdr} \usepackage{graphicx} \pagestyle{fancy} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt}" --documentoptions=letter --documentclass=article
PDFCMD = pdflatex --interaction batchmode --output-directory $(BUILD)/

.PHONY: all clean cleanup builds setup
.DEFAULT_GOAL := help
.SECONDARY:

help:
@echo "PDF, LaTeX and rST generator generator."
@echo "Targets:"
@echo ""
@echo " setup - builds targets for all files in source directory or directories."
@echo " (see bin/builder.py)"
@echo " all - rebuild all PDFs from files in the '$(SOURCE)' directory with"
@echo " the '.$(EXTENSION)' extension."
@echo ""
@echo " (other) - use 'make [filename-without-extension]' to rebuild only this file,"
@echo " after running 'make setup'"

setup:$(BUILD) makefile.generated logo.png
$(BUILD)/makefile.generated:bin/builder.py $(SOURCE_FILES)
@./$<
@echo [builder]: \(re\)generated \"makefile.generated\"
-include $(BUILD)/makefile.generated

all: logo.png $(BUILD) $(OUTPUT_PDF_FILES) $(OUTPUT_HTML_FILES)

logo.png:
curl http://docs.mongodb.org/logo-print.png >| $@

$(BUILD):
@mkdir -p $@
@echo [setup]: '$@' directory created.
$(BUILD)/%.html:$(SOURCE)/%.$(EXTENSION)
@$(HTMLCMD) $< >$@
@echo [rst2html]: converted $<
$(BUILD)/%.tex:$(SOURCE)/%.$(EXTENSION)
@$(LATEXCMD) $< >$@
@echo [rst2latex]: converted $<
$(BUILD)/%.pdf:$(BUILD)/%.tex
@$(PDFCMD) '$<' >|[email protected]
@echo [pdflatex]: \(1/3\) built '$@'
@$(PDFCMD) '$<' >>[email protected]
@echo [pdflatex]: \(2/3\) built '$@'
@$(PDFCMD) '$<' >>[email protected]
@echo [pdflatex]: \(3/3\) built '$@'

cleanup:
rm -f $(BUILD)/*.{aux,log,out}
clean:
rm -rf $(BUILD)/
clean-logo:
rm -f logo.png
64 changes: 64 additions & 0 deletions makefile-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
BUILD = build
SOURCE = server
EXTENSION = rst

MAKEFLAGS += -j

SOURCE_FILES := $(shell find $(SOURCE) -name "*.$(EXTENSION)")
OUTPUT_PDF_FILES = $(subst $(EXTENSION),pdf,$(subst $(SOURCE),$(BUILD),$(SOURCE_FILES)))
OUTPUT_HTML_FILES = $(subst $(EXTENSION),html,$(subst $(SOURCE),$(BUILD),$(SOURCE_FILES)))

HTMLCMD = rst2html.py
LATEXCMD = rst2latex.py --latex-preamble="\usepackage{fullpage} \usepackage{parskip} \usepackage{fancyhdr} \usepackage{graphicx} \pagestyle{fancy} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt}" --documentoptions=letter --documentclass=article
PDFCMD = pdflatex --interaction batchmode --output-directory $(BUILD)/

.PHONY: all clean cleanup builds setup
.DEFAULT_GOAL := help
.SECONDARY:

help:
@echo "PDF, LaTeX and rST generator generator."
@echo "Targets:"
@echo ""
@echo " setup - builds targets for all files in source directory or directories."
@echo " (see bin/builder.py)"
@echo " all - rebuild all PDFs from files in the '$(SOURCE)' directory with"
@echo " the '.$(EXTENSION)' extension."
@echo ""
@echo " (other) - use 'make [filename-without-extension]' to rebuild only this file,"
@echo " after running 'make setup'"

setup:$(BUILD) makefile.generated logo.png
$(BUILD)/makefile.generated:bin/builder.py $(SOURCE_FILES)
@./$<
@echo [builder]: \(re\)generated \"makefile.generated\"
-include $(BUILD)/makefile.generated

all: logo.png $(BUILD) $(OUTPUT_PDF_FILES) $(OUTPUT_HTML_FILES)

logo.png:
curl http://docs.mongodb.org/logo-print.png >| $@

$(BUILD):
@mkdir -p $@
@echo [setup]: '$@' directory created.
$(BUILD)/%.html:$(SOURCE)/%.$(EXTENSION)
@$(HTMLCMD) $< >$@
@echo [rst2html]: converted $<
$(BUILD)/%.tex:$(SOURCE)/%.$(EXTENSION)
@$(LATEXCMD) $< >$@
@echo [rst2latex]: converted $<
$(BUILD)/%.pdf:$(BUILD)/%.tex
@$(PDFCMD) '$<' >|[email protected]
@echo [pdflatex]: \(1/3\) built '$@'
@$(PDFCMD) '$<' >>[email protected]
@echo [pdflatex]: \(2/3\) built '$@'
@$(PDFCMD) '$<' >>[email protected]
@echo [pdflatex]: \(3/3\) built '$@'

cleanup:
rm -f $(BUILD)/*.{aux,log,out}
clean:
rm -rf $(BUILD)/
clean-logo:
rm -f logo.png

0 comments on commit 0ee0baf

Please sign in to comment.