Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
"""
Aggregate other documentations.
"""
__version__ = "1.0"
__date__ = "20200402"
__author__ = "kthoden@mpiwg-berlin.mpg.de"
import argparse
import configparser
import logging
import os
import sys
import shutil
from pathlib import Path
from distutils.dir_util import copy_tree
from sphinx.cmd.build import main as sphinx_main
logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
SCRIPT_DIR = Path( os.path.realpath(__file__) ).parent
# not included
# eoa-class
# what is in the trac wiki
def make_clean(path):
"""Clean a directory of its children."""
try:
build_contents = os.listdir(path)
except FileNotFoundError:
build_contents = []
for item in build_contents:
try:
shutil.rmtree(path / item)
except NotADirectoryError:
os.unlink(path / item)
# def make_clean ends here
def build_documentation(docpath, buildpath):
"""Call sphinx-build to build documentation."""
sys.argv = ["-M", "html", str(docpath), str(buildpath)]
sphinx_main(sys.argv)
# def build_documentation ends here
def build_and_deploy(base_path, path, docserver, main=False):
"""Create HTML files and copy them to the web directory"""
if main:
docpath = base_path
else:
docpath = base_path / path / "docs"
serverpath = docserver / path
buildpath = docpath / "_build"
htmlpath = buildpath / "html"
logging.info("Removing old build of single documentation.")
make_clean(buildpath)
logging.info("Building HTML documentation for %s.", path)
build_documentation(docpath, buildpath)
logging.info("Copy HTML files to server.")
if main:
copy_tree(htmlpath, str(docserver))
else:
shutil.copytree(htmlpath, serverpath)
# def build_and_deploy ends here
def main():
"""The main bit"""
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--config", help="Config file.", default = SCRIPT_DIR / "config.cfg",)
args = parser.parse_args()
CONFIG = configparser.ConfigParser()
try:
CONFIG.read(args.config)
except:
logging.error("Config file missing. Exiting.")
sys.exit()
BASE_DIR = Path(CONFIG["general"]["base_dir"])
DOCSERVER = Path(CONFIG["general"]["docserver"])
DOCSERVER_TMP = Path(f"{DOCSERVER}_tmp")
paths_from_config = CONFIG["general"]["subprojects"].replace("\n", "")
SUBPROJECTS = paths_from_config.split(",")
for project in SUBPROJECTS:
build_and_deploy(BASE_DIR, project, DOCSERVER_TMP)
logging.info("\n\n====================\n\nBuilding main documentation.")
build_and_deploy(Path(os.path.abspath('.')), Path(os.path.abspath('.')), DOCSERVER_TMP, main=True)
logging.info("Removing old build from server")
shutil.rmtree(DOCSERVER)
shutil.move(DOCSERVER_TMP, DOCSERVER)
# def main ends here
if __name__ == '__main__':
main()
# finis