#!/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 # For running locally using_zuul = False remote = "remotes/origin/" 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 we use zuul, there's no need for filtering if not using_zuul and 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 = '' # Running under Zuul v3, we do not have remotes/origin. # Running locally, it exists. Let's check ZUUL_PROJECT for running under # Zuul. if os.getenv("ZUUL_PROJECT"): remote = "" using_zuul = True for branch in git_branches(): if branch.startswith( remote + 'master'): continue if branch.startswith( remote + 'template'): continue if branch.startswith( remote + '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(remote):] print "Adding branch %s: %s" % (name, title) current += '%s
\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 += '%s: %s
\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()