Commit 124ce0bf authored by David Boddie's avatar David Boddie
Browse files

Include a manifest of extra files and a tool to copy them

parent bf2e9d14
Pipeline #48420 passed with stage
in 1 minute and 13 seconds
......@@ -54,10 +54,9 @@ clean:
.PHONY: html
html: check
# Copy images referenced as image links to suitable destinations.
@mkdir -p $(BUILDDIR)/html/Hardware_Reference/images/Birch
@cp Hardware_Reference/images/Birch/large/* $(BUILDDIR)/html/Hardware_Reference/images/Birch/
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
# Copy images referenced as image links to suitable destinations.
python3 _extensions/copy-extra-files.py extra-files.txt $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
......
#!/usr/bin/env python3
import glob
import os
import shutil
import sys
def process_manifest(manifest, html_dir):
src = None
lineno = 1
try:
for line in open(manifest).readlines():
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
if src is None:
src = line.strip()
else:
dest = line.strip()
copy_files(src, dest, html_dir)
src = None
lineno += 1
except IOError:
raise
sys.stderr.write('Failed to process manifest "%s" at line %i.\n' % (
manifest, lineno))
sys.exit(1)
except OSError:
sys.stderr.write('Failed to create directory given in manifest "%s" '
'at line %i.\n' % (manifest, lineno))
sys.exit(1)
def copy_files(src, dest, html_dir):
pieces = dest.split(os.sep)
new_dir = html_dir
for piece in pieces:
new_dir = os.path.join(new_dir, piece)
if not os.path.exists(new_dir):
print('Creating', new_dir)
os.mkdir(new_dir)
for path in glob.glob(src):
file_name = os.path.split(path)[1]
dest_path = os.path.join(new_dir, file_name)
print('Copying', path, 'to', dest_path)
shutil.copy2(path, dest_path)
if __name__ == '__main__':
if len(sys.argv) != 3:
sys.stderr.write('Usage: %s <manifest> <HTML output directory>\n' % sys.argv[0])
sys.exit(1)
manifest = sys.argv[1]
html_dir = sys.argv[2]
process_manifest(manifest, html_dir)
sys.exit()
# Pairs of lines separated by blank lines. The first line in a pair is the
# source files to copy, the second the destination directory in the output HTML
# file structure. Relative paths from the root of the project are used.
Hardware_Reference/images/Birch/large/*
Hardware_Reference/images/Birch
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment