publications/make-index
Clark Boylan b90c8d8cd5 Make make-index ignore template branch.
The template branch is used to create new publications. It is not a
publication on its own. Ignore this branch when making the root
publications index.

Change-Id: I90098c120b958025568b942c9f4132faa2a10079
2013-09-12 14:08:59 -07:00

78 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright 2013 OpenStack Foundation
#
# 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 os
import subprocess
def run_local(cmd, cwd='.', env={}):
print "Running:", cmd
newenv = os.environ
newenv.update(env)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=cwd,
stderr=subprocess.STDOUT, env=newenv)
(out, nothing) = p.communicate()
return (p.returncode, out.strip())
def git_branches():
branches = []
r, branch_list = run_local(['git', 'branch', '-a'])
for branch in branch_list.split("\n"):
branch = branch.strip()
if not branch.startswith('remotes/origin'):
continue
branches.append(branch)
return branches
def git_tags():
r, tag_list = run_local(['git', 'tag', '-n'])
return [x for x in tag_list.split('\n') if x]
current = ''
previous = ''
for branch in git_branches():
if branch.startswith('remotes/origin/master'):
continue
if branch.startswith('remotes/origin/template'):
continue
if branch.startswith('remotes/origin/HEAD'):
continue
if '->' in branch:
continue
r,o = run_local(['git', 'show', branch+':README.rst'])
if not r:
title = o.split('\n')[0]
name = branch[len('remotes/origin/'):]
print "Adding branch %s: %s" % (name, title)
current += '<a href="%s/">%s</a><br/>\n' % (name, title)
for tagline in git_tags():
tag, tag_title = [x.strip() for x in tagline.split(' ', 1)]
r,o = run_local(['git', 'show', tag+':README.rst'])
if not r:
title = o.split('\n')[0]
print "Adding tag %s: %s: %s" % (tag, tag_title, title)
previous += '<a href="%s/">%s: %s</a><br/>\n' % (tag, tag_title, title)
if not os.path.exists('output'):
os.mkdir('output')
out = open('output/index.html', 'w')
out.write(open('index.html').read().format(current=current, previous=previous))
out.close()