Add small webserver for development
authorMichael Hanselmann <hansmi@google.com>
Mon, 7 Jan 2013 16:59:12 +0000 (17:59 +0100)
committerMichael Hanselmann <hansmi@google.com>
Mon, 7 Jan 2013 18:56:25 +0000 (19:56 +0100)
When working on documentation it can be helpful to use a browser. In
some environments it's not possible to access the files directly from a
graphical browser. This trivial webserver exports all files in the
current directory and unlike alternatives such as thttpd, doesn't check
for world-readable permissions.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

Makefile.am
devel/webserver [new file with mode: 0755]

index 45260a1..aa27d76 100644 (file)
@@ -814,6 +814,7 @@ EXTRA_DIST = \
        daemons/ganeti-cleaner.in \
        $(pkglib_python_scripts) \
        devel/upload \
+       devel/webserver \
        tools/kvm-ifup.in \
        tools/vcluster-setup.in \
        $(docdot) \
diff --git a/devel/webserver b/devel/webserver
new file mode 100755 (executable)
index 0000000..1b5aca5
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+#
+
+# Copyright (C) 2013 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+import sys
+import BaseHTTPServer
+import SimpleHTTPServer
+
+
+def main():
+  if len(sys.argv) == 2:
+    host = "127.0.0.1"
+
+    (_, port) = sys.argv
+
+  elif len(sys.argv) == 3:
+    (_, port, host) = sys.argv
+
+  else:
+    sys.stderr.write("Usage: %s <port> [<host>]\n" % sys.argv[0])
+    sys.stderr.write("\n")
+    sys.stderr.write("Provides an HTTP server on the specified TCP port")
+    sys.stderr.write(" exporting the current working directory. Binds to")
+    sys.stderr.write(" localhost by default.\n")
+    sys.exit(1)
+
+  try:
+    port = int(port)
+  except (ValueError, TypeError), err:
+    sys.stderr.write("Invalid port '%s': %s\n" % (port, err))
+    sys.exit(1)
+
+  handler = SimpleHTTPServer.SimpleHTTPRequestHandler
+
+  server = BaseHTTPServer.HTTPServer((host, port), handler)
+  server.serve_forever()
+
+
+if __name__ == "__main__":
+  main()