hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 1 | #!/usr/bin/python2.7 |
| 2 | |
| 3 | import os |
onqtam | 90d95de | 2016-05-22 04:17:34 +0300 | [diff] [blame] | 4 | import sys |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 5 | import subprocess |
| 6 | import fileinput |
| 7 | import time |
| 8 | |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 9 | # the version of the release |
onqtam | e8bdda4 | 2016-06-01 15:12:36 +0300 | [diff] [blame] | 10 | with open("version.txt") as f: version = f.read() |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 11 | |
onqtam | e8bdda4 | 2016-06-01 15:12:36 +0300 | [diff] [blame] | 12 | def getVersionTuple(v): |
| 13 | return tuple(map(int, (v.split(".")))) |
| 14 | |
| 15 | version_major = str(getVersionTuple(version)[0]) |
| 16 | version_minor = str(getVersionTuple(version)[1]) |
| 17 | version_patch = str(getVersionTuple(version)[2]) |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 18 | |
| 19 | # update version in the header file |
onqtam | e8bdda4 | 2016-06-01 15:12:36 +0300 | [diff] [blame] | 20 | print("updating the version in the header file") |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 21 | doctest_contents = "" |
onqtam | e8bdda4 | 2016-06-01 15:12:36 +0300 | [diff] [blame] | 22 | for line in fileinput.input(["../doctest/parts/doctest_fwd.h"]): |
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 23 | if line.startswith("#define DOCTEST_VERSION_MAJOR "): |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 24 | doctest_contents += "#define DOCTEST_VERSION_MAJOR " + version_major + "\n" |
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 25 | elif line.startswith("#define DOCTEST_VERSION_MINOR "): |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 26 | doctest_contents += "#define DOCTEST_VERSION_MINOR " + version_minor + "\n" |
onqtam | f3a680f | 2016-04-30 03:15:07 +0300 | [diff] [blame] | 27 | elif line.startswith("#define DOCTEST_VERSION_PATCH "): |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 28 | doctest_contents += "#define DOCTEST_VERSION_PATCH " + version_patch + "\n" |
onqtam | d1737e4 | 2016-08-01 19:05:07 +0300 | [diff] [blame^] | 29 | elif line.startswith("#define DOCTEST_VERSION_STR "): |
| 30 | doctest_contents += "#define DOCTEST_VERSION_STR \"" + version + "\"\n" |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 31 | else: |
| 32 | doctest_contents += line |
| 33 | |
onqtam | e8bdda4 | 2016-06-01 15:12:36 +0300 | [diff] [blame] | 34 | readme = open("../doctest/parts/doctest_fwd.h", "w") |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 35 | readme.write(doctest_contents) |
| 36 | readme.close() |
| 37 | |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 38 | # run generate_html.py |
onqtam | 8126b56 | 2016-05-27 17:01:15 +0300 | [diff] [blame] | 39 | print("generating html documentation from markdown") |
| 40 | os.system("python generate_html.py") |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 41 | |
onqtam | e6d0d51 | 2016-04-27 23:23:16 +0300 | [diff] [blame] | 42 | examples = "../examples/" |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 43 | ''' |
| 44 | # create readme files in examples with 'try it online' badges with permalinks |
| 45 | examples_skip = ["multiprocess"] |
| 46 | |
| 47 | for dir in os.listdir(examples): |
| 48 | if not os.path.isdir(examples + dir): |
| 49 | continue |
| 50 | |
| 51 | # skip folders with more than 1 source file |
| 52 | sources = [s for s in os.listdir(examples + dir) if ".cpp" in s] |
| 53 | if dir in examples_skip or len(sources) > 1 or len(sources) == 0: |
| 54 | continue |
| 55 | |
| 56 | print("generating readme for example '" + examples + dir + "'") |
| 57 | |
| 58 | proc = subprocess.Popen('python send_to_wandbox.py ../doctest/ ' + examples + dir + "/" + sources[0], stdout = subprocess.PIPE) |
| 59 | url = proc.stdout.read().strip() |
| 60 | |
| 61 | if not url.startswith("http"): |
| 62 | print("skipping current example because of crappy url: '" + url + "'\n") |
| 63 | continue |
| 64 | |
| 65 | readme = open(examples + dir + "/README.md", "w") |
| 66 | readme.write("[![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](" + url + ")") |
| 67 | readme.close() |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 68 | ''' |
| 69 | |
| 70 | # update main readme 'try it online' badge permalink |
| 71 | print("updating main readme") |
| 72 | proc = subprocess.Popen('python send_to_wandbox.py ../doctest/ ' + examples + "hello_world/main.cpp", stdout = subprocess.PIPE) |
| 73 | url = proc.stdout.read().strip() |
| 74 | |
| 75 | readme_contents = "" |
| 76 | for line in fileinput.input(["../README.md"]): |
onqtam | 90d95de | 2016-05-22 04:17:34 +0300 | [diff] [blame] | 77 | if line.startswith("[![Try it online]"): |
| 78 | readme_contents += "[![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](" + url + ")\n" |
hardly | b1e7e14 | 2014-08-06 00:43:51 +0300 | [diff] [blame] | 79 | else: |
| 80 | readme_contents += line |
| 81 | |
| 82 | readme = open("../README.md", "w") |
| 83 | readme.write(readme_contents) |
| 84 | readme.close() |