forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: move context back to doc/, fix broken links
Running documentation scripts on the top directory shifted all links one level dowwn and is breaking all incoming links. Use a script to copy all RST files into the doc/ directory before running sphinx and keep structure intact. Jira: ZEP-1579 Change-Id: Iccff068430e2ddb29e172cd8ae920475815d199e Signed-off-by: Anas Nashif <[email protected]>
- Loading branch information
Showing
4 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2017, Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Very quick script to move docs from different places into the doc directory | ||
# to fix the website and external links | ||
|
||
import os | ||
import shutil | ||
import re | ||
import sys | ||
import fnmatch | ||
|
||
|
||
# direcories to search for .rst files | ||
CONTENT_DIRS = ["samples", "boards"] | ||
|
||
# directives to parse for included files | ||
DIRECTIVES = ["figure","include","image","literalinclude"] | ||
|
||
if "ZEPHYR_BASE" not in os.environ: | ||
sys.stderr.write("$ZEPHYR_BASE environment variable undefined.\n") | ||
exit(1) | ||
ZEPHYR_BASE = os.environ["ZEPHYR_BASE"] | ||
|
||
def get_rst_files(dir): | ||
matches = [] | ||
for root, dirnames, filenames in os.walk('%s/%s' %(ZEPHYR_BASE, dir)): | ||
for filename in fnmatch.filter(filenames, '*.rst'): | ||
matches.append(os.path.join(root, filename)) | ||
for file in matches: | ||
frel = file.replace(ZEPHYR_BASE,"").strip("/") | ||
dir=os.path.dirname(frel) | ||
if not os.path.exists(os.path.join(ZEPHYR_BASE, "doc", dir)): | ||
os.makedirs(os.path.join(ZEPHYR_BASE, "doc", dir)) | ||
|
||
shutil.copyfile(file, os.path.join(ZEPHYR_BASE, "doc", frel)) | ||
|
||
with open(file) as f: | ||
content = f.readlines() | ||
content = [x.strip() for x in content] | ||
directives = "|".join(DIRECTIVES) | ||
pattern = re.compile("\s*\.\.\s+(%s)::\s+(.*)" %directives) | ||
for l in content: | ||
m = pattern.match(l) | ||
if m: | ||
inf = m.group(2) | ||
ind = os.path.dirname(inf) | ||
if not os.path.exists(os.path.join(ZEPHYR_BASE, "doc", dir, ind)): | ||
os.makedirs(os.path.join(ZEPHYR_BASE, "doc", dir, ind)) | ||
|
||
shutil.copyfile(os.path.join(ZEPHYR_BASE, dir, inf), | ||
os.path.join(ZEPHYR_BASE, "doc", dir, inf)) | ||
|
||
f.close() | ||
|
||
def main(): | ||
for d in CONTENT_DIRS: | ||
get_rst_files(d) | ||
|
||
if __name__ == "__main__": | ||
main() |