From f995e2db3d33df1db1a25bc974bf71a93c314706 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 15 Jul 2010 16:01:46 -0400 Subject: [PATCH] docs: generate commands list as internals/VERSION/commands.html --- buildscripts/docs.py | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/buildscripts/docs.py b/buildscripts/docs.py index 10bf5af55e9..719b5af86b8 100644 --- a/buildscripts/docs.py +++ b/buildscripts/docs.py @@ -4,7 +4,10 @@ from __future__ import with_statement import os import shutil +import socket import subprocess +import time +import urllib2 import markdown @@ -34,6 +37,52 @@ def convert_dir(source, dest): o.write(html) +def check_mongo(): + sock = socket.socket() + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + sock.settimeout(1) + sock.connect(("localhost", 31999)) + sock.close() + +def did_mongod_start(timeout=20): + while timeout > 0: + time.sleep(1) + try: + check_mongo() + return True + except Exception,e: + print e + timeout = timeout - 1 + return False + +def stop(proc): + try: + proc.terminate() + except AttributeError: + os.kill(proc.pid, 15) + +def commands_list(out): + clean_dir("dummy_data_dir") + with open("/dev/null") as null: + try: + p = subprocess.Popen(["./mongod", "--dbpath", "dummy_data_dir", + "--port", "31999", "--rest"], stdout=null, stderr=null) + except: + print "No mongod? Skipping..." + return + if not did_mongod_start(): + print "Slow mongod? Skipping..." + stop(p) + return + print "Started mongod" + + with open(out, "w") as f: + f.write("") + f.write(urllib2.urlopen("http://localhost:32999/_commands").read()) + + print "Stopping mongod" + stop(p) + def gen_cplusplus(dir): clean_dir(dir) clean_dir("docs/doxygen") @@ -58,6 +107,9 @@ def main(): v = version() print("Generating server docs in docs/html/internal/%s" % v) convert_dir("docs", "docs/html/internal/%s" % v) + print("Generating commands list") + commands_list("docs/html/internal/%s/commands.html" % v) + shutil.rmtree("dummy_data_dir") print("Generating C++ docs in docs/html/cplusplus/%s" % v) gen_cplusplus("docs/html/cplusplus/%s" % v)