Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

docs: generate commands list as internals/VERSION/commands.html

  • Loading branch information...
commit f995e2db3d33df1db1a25bc974bf71a93c314706 1 parent 64800fd
authored July 15, 2010

Showing 1 changed file with 52 additions and 0 deletions. Show diff stats Hide diff stats

  1. 52  buildscripts/docs.py
52  buildscripts/docs.py
@@ -4,7 +4,10 @@
4 4
 from __future__ import with_statement
5 5
 import os
6 6
 import shutil
  7
+import socket
7 8
 import subprocess
  9
+import time
  10
+import urllib2
8 11
 
9 12
 import markdown
10 13
 
@@ -34,6 +37,52 @@ def convert_dir(source, dest):
34 37
             o.write(html)
35 38
 
36 39
 
  40
+def check_mongo():
  41
+    sock = socket.socket()
  42
+    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
  43
+    sock.settimeout(1)
  44
+    sock.connect(("localhost", 31999))
  45
+    sock.close()
  46
+
  47
+def did_mongod_start(timeout=20):
  48
+    while timeout > 0:
  49
+        time.sleep(1)
  50
+        try:
  51
+            check_mongo()
  52
+            return True
  53
+        except Exception,e:
  54
+            print e
  55
+            timeout = timeout - 1
  56
+    return False
  57
+
  58
+def stop(proc):
  59
+    try:
  60
+        proc.terminate()
  61
+    except AttributeError:
  62
+        os.kill(proc.pid, 15)
  63
+
  64
+def commands_list(out):
  65
+    clean_dir("dummy_data_dir")
  66
+    with open("/dev/null") as null:
  67
+        try:
  68
+            p = subprocess.Popen(["./mongod", "--dbpath", "dummy_data_dir",
  69
+                                  "--port", "31999", "--rest"], stdout=null, stderr=null)
  70
+        except:
  71
+            print "No mongod? Skipping..."
  72
+            return
  73
+        if not did_mongod_start():
  74
+            print "Slow mongod? Skipping..."
  75
+            stop(p)
  76
+            return
  77
+        print "Started mongod"
  78
+
  79
+        with open(out, "w") as f:
  80
+            f.write("<base href='http://localhost:28017'/>")
  81
+            f.write(urllib2.urlopen("http://localhost:32999/_commands").read())
  82
+
  83
+        print "Stopping mongod"
  84
+        stop(p)
  85
+
37 86
 def gen_cplusplus(dir):
38 87
     clean_dir(dir)
39 88
     clean_dir("docs/doxygen")
@@ -58,6 +107,9 @@ def main():
58 107
     v = version()
59 108
     print("Generating server docs in docs/html/internal/%s" % v)
60 109
     convert_dir("docs", "docs/html/internal/%s" % v)
  110
+    print("Generating commands list")
  111
+    commands_list("docs/html/internal/%s/commands.html" % v)
  112
+    shutil.rmtree("dummy_data_dir")
61 113
     print("Generating C++ docs in docs/html/cplusplus/%s" % v)
62 114
     gen_cplusplus("docs/html/cplusplus/%s" % v)
63 115
 

0 notes on commit f995e2d

Please sign in to comment.
Something went wrong with that request. Please try again.