diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 3b88c4ab85a..d7386f263ba 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -68,10 +68,10 @@ add_custom_target( add_custom_target( content - # Copy the .rst files in doc/ to the rst folder + # Copy all files in doc/ to the rst folder COMMAND ${CMAKE_COMMAND} -E env ZEPHYR_BUILD=${CMAKE_CURRENT_BINARY_DIR} - ${PYTHON_EXECUTABLE} scripts/extract_content.py ${RST_OUT} doc + ${PYTHON_EXECUTABLE} scripts/extract_content.py -a ${RST_OUT} doc # Copy the .rst files in samples/ and boards/ to the rst folder COMMAND ${CMAKE_COMMAND} -E env ZEPHYR_BUILD=${CMAKE_CURRENT_BINARY_DIR} diff --git a/doc/scripts/extract_content.py b/doc/scripts/extract_content.py index e4cf1969ee4..d694f1abfe4 100755 --- a/doc/scripts/extract_content.py +++ b/doc/scripts/extract_content.py @@ -8,6 +8,7 @@ # Very quick script to move docs from different places into the doc directory # to fix the website and external links +import argparse import errno import filecmp import fnmatch @@ -37,14 +38,15 @@ def copy_if_different(src, dst): return shutil.copyfile(src, dst) -def get_rst_files(dest, dir): +def get_files(all, dest, dir): matches = [] for root, dirnames, filenames in os.walk('%s/%s' %(ZEPHYR_BASE, dir)): if ZEPHYR_BUILD: if os.path.normpath(root).startswith(os.path.normpath(ZEPHYR_BUILD)): # Build folder, skip it continue - for filename in fnmatch.filter(filenames, '*.rst'): + + for filename in fnmatch.filter(filenames, '*' if all else '*.rst'): matches.append(os.path.join(root, filename)) for file in matches: frel = file.replace(ZEPHYR_BASE,"").strip("/") @@ -54,6 +56,11 @@ def get_rst_files(dest, dir): copy_if_different(file, os.path.join(dest, frel)) + # Inspect only .rst files for directives referencing other files + # we'll need to copy (as configured in the DIRECTIVES variable) + if not fnmatch.fnmatch(file, "*.rst"): + continue + try: with open(file, encoding="utf-8") as f: content = f.readlines() @@ -92,15 +99,22 @@ def get_rst_files(dest, dir): def main(): - if len(sys.argv) < 3: - print("usage: {} ", file=sys.stderr) - sys.exit(1) + parser = argparse.ArgumentParser(description='Recursively copy .rst files ' + 'from the origin folder(s) to the ' + 'destination folder, plus files referenced ' + 'in those .rst files by a configurable ' + 'list of directives: {}.'.format(DIRECTIVES)) - dest = sys.argv[1] - content_dirs = sys.argv[2:] + parser.add_argument('-a', '--all', action='store_true', help='Copy all files ' + '(recursively) in the specified source folder(s).') + parser.add_argument('dest', nargs=1) + parser.add_argument('src', nargs='+') + args = parser.parse_args() - for d in content_dirs: - get_rst_files(dest, d) + dest = args.dest[0] + + for d in args.src: + get_files(args.all, dest, d) if __name__ == "__main__": main()