2017-12-22 22:18:46 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-12-23 22:11:34 +00:00
|
|
|
import sys, os, shutil, re
|
2017-12-22 22:18:46 +00:00
|
|
|
|
|
|
|
blacklist = []
|
|
|
|
|
2017-12-22 22:50:30 +00:00
|
|
|
port_item = """
|
|
|
|
- [PORT_TITLE](#sec:PORT_LABELPort)"""
|
2017-12-22 22:18:46 +00:00
|
|
|
|
|
|
|
def get_readme_title(example_path):
|
|
|
|
title = ''
|
|
|
|
with open(example_path, 'rb') as fin:
|
|
|
|
for line in fin:
|
|
|
|
parts = re.match('(##\s)(.*)\n',line)
|
|
|
|
if parts:
|
|
|
|
title = parts.group(2)
|
|
|
|
continue
|
|
|
|
return title
|
|
|
|
|
|
|
|
# write list of examples
|
2017-12-23 21:52:31 +00:00
|
|
|
def process_readmes(intro_file, port_folder, ports_file, ports_folder):
|
2017-12-22 22:18:46 +00:00
|
|
|
matches = {}
|
2017-12-23 21:52:31 +00:00
|
|
|
images = {}
|
|
|
|
|
2017-12-23 22:11:34 +00:00
|
|
|
# iterate over port folders
|
|
|
|
ports = os.listdir(port_folder)
|
|
|
|
for port in ports:
|
|
|
|
if port not in blacklist:
|
|
|
|
readme_file = port_folder + "/" + port + "/" + "README.md"
|
|
|
|
if os.path.exists(readme_file):
|
|
|
|
matches[port] = readme_file
|
|
|
|
for file in os.listdir(port_folder + "/" + port):
|
|
|
|
if file.endswith('.jpg'):
|
|
|
|
images[file] = port_folder + "/" + port + "/" + file
|
2017-12-22 22:18:46 +00:00
|
|
|
|
|
|
|
with open(ports_file, 'w') as ports:
|
|
|
|
with open(intro_file, 'rb') as fin:
|
|
|
|
for line in fin:
|
|
|
|
ports.write(line)
|
|
|
|
fin.close()
|
|
|
|
|
2017-12-23 22:17:07 +00:00
|
|
|
for readme_dir, readme_file in sorted(matches.items()):
|
2017-12-22 22:18:46 +00:00
|
|
|
with open(readme_file, 'rb') as fin:
|
|
|
|
for line in fin:
|
2017-12-22 22:50:30 +00:00
|
|
|
# find title, add reference
|
|
|
|
title_parts = re.match('(#\s+)(.*)\n',line)
|
|
|
|
if title_parts:
|
|
|
|
title = title_parts.group(2)
|
|
|
|
ports.write(port_item.replace("PORT_TITLE", title).replace("PORT_LABEL", readme_dir))
|
2017-12-22 22:18:46 +00:00
|
|
|
break
|
|
|
|
fin.close()
|
|
|
|
ports.write("\n\n")
|
|
|
|
|
2017-12-23 22:17:07 +00:00
|
|
|
for readme_dir, readme_file in sorted(matches.items()):
|
2017-12-22 22:18:46 +00:00
|
|
|
with open(readme_file, 'rb') as fin:
|
|
|
|
for line in fin:
|
2017-12-23 23:35:42 +00:00
|
|
|
#increase level of indentation
|
2017-12-22 22:50:30 +00:00
|
|
|
parts = re.match('#(.*)\n',line)
|
|
|
|
title_parts = re.match('(#\s+)(.*)\n',line)
|
2017-12-23 23:35:42 +00:00
|
|
|
if parts and title_parts:
|
|
|
|
ports.write("# " + title_parts.group(2) + " {" + "#sec:" + readme_dir + "Port}\n" )
|
2017-12-22 22:18:46 +00:00
|
|
|
else:
|
|
|
|
ports.write(line)
|
2017-12-22 22:50:30 +00:00
|
|
|
|
2017-12-23 21:52:31 +00:00
|
|
|
# copy images
|
|
|
|
for image_filename, image_path in images.items():
|
|
|
|
print('copy %s as %s' % (image_path, ports_folder + image_filename))
|
|
|
|
shutil.copy(image_path, ports_folder + image_filename)
|
2017-12-22 22:50:30 +00:00
|
|
|
|
2017-12-22 22:18:46 +00:00
|
|
|
fin.close()
|
|
|
|
ports.close()
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
btstackfolder = "../../"
|
|
|
|
docsfolder = "docs/"
|
|
|
|
|
|
|
|
inputfolder = btstackfolder + "port/"
|
2017-12-23 21:52:31 +00:00
|
|
|
portsfolder = docsfolder + "ports/"
|
|
|
|
introfile = portsfolder + "intro.md"
|
|
|
|
outputfile = portsfolder + "existing_ports.md"
|
|
|
|
process_readmes(introfile, inputfolder, outputfile, portsfolder)
|
2017-12-22 22:18:46 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv[1:])
|