aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSkyler Kaufman <skyler@google.com>2011-04-07 12:30:41 -0700
committerDan Morrill <morrildl@google.com>2011-04-07 13:03:00 -0700
commit991ae4d81f940d665370e3217ec7cf3d7285ec8d (patch)
tree7b3c7e0d492e6940ce2d84ffb0660474bef5ee93 /scripts
parent3ce332f8590920442232fb0a1da9b2fa18be5842 (diff)
downloadsource.android.com-991ae4d81f940d665370e3217ec7cf3d7285ec8d.tar.gz
Adding a slightly reorganized version of skyler's revamped s.a.c.
Change-Id: I19439883c25d887fa4409b33a70c235af3a78eaf
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build.py75
-rwxr-xr-xscripts/micro-httpd.py21
2 files changed, 96 insertions, 0 deletions
diff --git a/scripts/build.py b/scripts/build.py
new file mode 100755
index 00000000..d57762d1
--- /dev/null
+++ b/scripts/build.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+import os
+import glob
+import shutil
+import string
+import subprocess
+
+
+# call markdown as a subprocess, and capture the output
+def markdown(raw_file):
+ extensions = '-x tables' + ' ' + '-x "toc(title=In This Document)"'
+ command = 'markdown' + ' ' + extensions + ' ' + raw_file
+ p = subprocess.Popen(command, stdout = subprocess.PIPE, shell = True)
+ return p.communicate()[0]
+
+
+# read just the title (first heading) from a source page
+def get_title(raw_file):
+ for line in open(raw_file, 'r'):
+ if '#' in line:
+ return line.strip(' #\n')
+ return ""
+
+
+# directory to compile the site to (will be clobbered during build!)
+HTML_DIR = 'out'
+# directory to look in for markdown source files
+SRC_DIR = 'src'
+# directory to look in for html templates
+TEMPLATE_DIR = 'templates'
+
+# filenames of templates to load, in order
+TEMPLATE_LIST = ['includes', 'header', 'sidebar', 'main', 'footer']
+
+t = ""
+for f in TEMPLATE_LIST:
+ t += open(os.path.join(TEMPLATE_DIR, f), 'r').read()
+template = string.Template(t)
+
+if os.path.exists(HTML_DIR):
+ shutil.rmtree(HTML_DIR)
+
+os.mkdir(HTML_DIR)
+
+category = 'home'
+for curdir, subdirs, files in os.walk(SRC_DIR):
+ print 'Processing %s...' % (curdir,),
+ outdir = [x for x in curdir.split(os.path.sep) if x]
+ outdir[0] = HTML_DIR
+ if len(outdir) == 2:
+ category = outdir[-1]
+ outdir = os.path.join(*outdir)
+
+ for subdir in subdirs:
+ os.mkdir(os.path.join(outdir, subdir))
+
+ if 'sidebar.md' in files:
+ sidebar = markdown(os.path.join(curdir, 'sidebar.md'))
+ del files[files.index('sidebar.md')]
+ else:
+ sidebar = ''
+ for f in files:
+ print ' .',
+ if f.endswith('.md'):
+ main = markdown(os.path.join(curdir, f))
+ final = template.safe_substitute(main=main, sidebar=sidebar, category=category, title=get_title(os.path.join(curdir, f)))
+
+ html = file(os.path.join(outdir, f.replace('.md', '.html')), 'w')
+ html.write(final)
+ else:
+ shutil.copy(os.path.join(curdir, f), os.path.join(outdir, f))
+ print
+
+print 'Done.'
diff --git a/scripts/micro-httpd.py b/scripts/micro-httpd.py
new file mode 100755
index 00000000..853c2446
--- /dev/null
+++ b/scripts/micro-httpd.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python2.4
+
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import SimpleHTTPServer, SocketServer, os
+PORT = int(os.environ.get('HTTP_PORT', 8080))
+Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
+httpd = SocketServer.TCPServer(("", PORT), Handler)
+httpd.serve_forever()