#!/usr/bin/python2.7

import os
import subprocess
import fileinput
import time

# run generate_html.py
print("generating html documentation from markdown")
os.system("python generate_html.py")

examples = "../examples/"

'''
# create readme files in examples with 'try it online' badges with permalinks
examples_skip = ["multiprocess"]

for dir in os.listdir(examples):
    if not os.path.isdir(examples + dir):
        continue
    
    # skip folders with more than 1 source file
    sources = [s for s in os.listdir(examples + dir) if ".cpp" in s]
    if dir in examples_skip or len(sources) > 1 or len(sources) == 0:
        continue
    
    print("generating readme for example '" + examples + dir + "'")
    
    proc = subprocess.Popen('python send_to_wandbox.py ../doctest/ ' + examples + dir + "/" + sources[0], stdout = subprocess.PIPE)
    url = proc.stdout.read().strip()
    
    if not url.startswith("http"):
        print("skipping current example because of crappy url: '" + url + "'\n")
        continue
    
    readme = open(examples + dir + "/README.md", "w")
    readme.write("[![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](" + url + ")")
    readme.close()
    os.system("git add " + examples + dir + "/README.md")
'''

# update main readme 'try it online' badge permalink
print("updating main readme")
proc = subprocess.Popen('python send_to_wandbox.py ../doctest/ ' + examples + "hello_world/main.cpp", stdout = subprocess.PIPE)
url = proc.stdout.read().strip()

readme_contents = ""
for line in fileinput.input(["../README.md"]):
    if line.startswith("[![Try it online]"):
        readme_contents += "[![Try it online](https://img.shields.io/badge/try%20it-online-orange.svg)](" + url + ")\n"
    else:
        readme_contents += line

readme = open("../README.md", "w")
readme.write(readme_contents)
readme.close()

os.system("git add ../README.md")
