hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame^] | 1 | #!/usr/bin/python2.7 |
| 2 | |
| 3 | import os |
| 4 | import subprocess |
| 5 | import fileinput |
| 6 | import time |
| 7 | |
| 8 | # run generate_html.py |
| 9 | print("generating html documentation from markdown") |
| 10 | os.system("python generate_html.py") |
| 11 | |
| 12 | examples = "../examples/" |
| 13 | |
| 14 | ''' |
| 15 | # create readme files in examples with 'try it online' badges with permalinks |
| 16 | examples_skip = ["multiprocess"] |
| 17 | |
| 18 | for dir in os.listdir(examples): |
| 19 | if not os.path.isdir(examples + dir): |
| 20 | continue |
| 21 | |
| 22 | # skip folders with more than 1 source file |
| 23 | sources = [s for s in os.listdir(examples + dir) if ".cpp" in s] |
| 24 | if dir in examples_skip or len(sources) > 1 or len(sources) == 0: |
| 25 | continue |
| 26 | |
| 27 | print("generating readme for example '" + examples + dir + "'") |
| 28 | |
| 29 | proc = subprocess.Popen('python send_to_wandbox.py ../doctest/ ' + examples + dir + "/" + sources[0], stdout = subprocess.PIPE) |
| 30 | url = proc.stdout.read().strip() |
| 31 | |
| 32 | if not url.startswith("http"): |
| 33 | print("skipping current example because of crappy url: '" + url + "'\n") |
| 34 | continue |
| 35 | |
| 36 | readme = open(examples + dir + "/README.md", "w") |
| 37 | readme.write("[![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](" + url + ")") |
| 38 | readme.close() |
| 39 | os.system("git add " + examples + dir + "/README.md") |
| 40 | ''' |
| 41 | |
| 42 | # update main readme 'try it online' badge permalink |
| 43 | print("updating main readme") |
| 44 | proc = subprocess.Popen('python send_to_wandbox.py ../doctest/ ' + examples + "hello_world/main.cpp", stdout = subprocess.PIPE) |
| 45 | url = proc.stdout.read().strip() |
| 46 | |
| 47 | readme_contents = "" |
| 48 | for line in fileinput.input(["../README.md"]): |
| 49 | if line.startswith("[![Try it online]"): |
| 50 | readme_contents += "[![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](" + url + ")\n" |
| 51 | else: |
| 52 | readme_contents += line |
| 53 | |
| 54 | readme = open("../README.md", "w") |
| 55 | readme.write(readme_contents) |
| 56 | readme.close() |
| 57 | |
| 58 | os.system("git add ../README.md") |