Skip to content

Commit

Permalink
Adding update stage for static versions page in docs.
Browse files Browse the repository at this point in the history
Relates to googleapis#472
  • Loading branch information
dhermes committed Feb 18, 2015
1 parent 9eb8cd4 commit bee3745
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ regression/local_test_setup
# Make sure a generated file isn't accidentally committed.
pylintrc_reduced

# Wheel directory used in Travis builds.
# Travis build directories.
gcloud-python-wheels/
ghpages/
5 changes: 5 additions & 0 deletions scripts/update_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ else
# Put the new release in latest and with the actual version.
cp -R ../docs/_build/html/ latest/
cp -R ../docs/_build/html/ "${CURRENT_VERSION}/"

# Also update the versions file.
.tox/docs/bin/python ../scripts/update_versions.py
# Update the files which were updated in the release.
git add versions.html versions.json
fi

# Update the files push to gh-pages.
Expand Down
49 changes: 49 additions & 0 deletions scripts/update_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json
import os
from pkg_resources import get_distribution


LI_TEMPLATE = '<li><a href="%s/index.html">%s</a></li>'
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
GH_PAGES_DIR = os.path.abspath(os.path.join(SCRIPTS_DIR, '..', 'ghpages'))
VERSIONS_TMPL = os.path.join(SCRIPTS_DIR, 'versions.html.template')
JSON_VERSIONS = os.path.join(GH_PAGES_DIR, 'versions.json')
VERSIONS_FILE = os.path.join(GH_PAGES_DIR, 'versions.html')


def update_versions(new_version):
with open(JSON_VERSIONS, 'r') as file_obj:
versions = json.load(file_obj)

if new_version in versions:
return versions

versions.insert(0, new_version)

with open(JSON_VERSIONS, 'w') as file_obj:
json.dump(versions, file_obj)

return versions


def render_template(new_version):
versions = update_versions(new_version)

with open(VERSIONS_TMPL, 'r') as file_obj:
page_template = file_obj.read()

versions_list = '\n'.join([LI_TEMPLATE % (version, version)
for version in versions])

return page_template.format(versions=versions_list)


def main():
new_version = get_distribution('gcloud').version
rendered = render_template(new_version)
with open(VERSIONS_FILE, 'w') as file_obj:
file_obj.write(rendered)


if __name__ == '__main__':
main()
100 changes: 100 additions & 0 deletions scripts/versions.html.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>gcloud-python Versions</title>

<link rel="stylesheet" href="_landing-page-static/css/docs-main.css" type="text/css" />
<link rel="stylesheet" href="_landing-page-static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_landing-page-static/css/normalize.css" type="text/css" />
<link rel="stylesheet" href="_landing-page-static/css/github.min.css" type="text/css" />

<script type="text/javascript" src="_landing-page-static/js/vendor/modernizr-2.6.2.min.js"></script>
<link rel="shortcut icon" href="_landing-page-static/favicon.ico"/>
<link rel="top" title="gcloud-python Versions" href="#" />
</head>
<body>
<header class="page-header fixed" role="banner">
<h1 class="logo">
<a href="index.html" title="back to home">
<img src="_landing-page-static/images/logo.svg" alt="Google Cloud Platform" />
<span class="gcloud">gcloud</span>
</a>
</h1>
<nav class="main-nav">
<div class="nav-current">Python</div>
<ul class="menu">
<li>
<a href="
https://googlecloudplatform.github.io/gcloud-node" title="Node.js docs page">
<img src="_landing-page-static/images/icon-lang-nodejs.svg" alt="Node.js icon" class="menu-icon" />
Node.js
</a>
</li>
<li>
<a href="#" title="Python docs page">
<img src="_landing-page-static/images/icon-lang-python-white.svg" alt="Python icon" class="menu-icon" />
Python
</a>
</li>
</ul>
</nav><!-- end of .main-nav -->
</header><!-- end of .page-header -->

<article class="main lang-page" role="main">

<header class="docs-header">
<h1 class="page-title">Versions</h1>
</header>

<section class="content">

<div class="toctree-wrapper compound">
</div>
<ul id="versions">
{versions}
</ul>

</section><!-- end of .content -->
<nav class="side-nav">
<ul><li><a href="latest/index.html">Documentation</a></li></ul>
<ul class="simple">
</ul>

<ul class="external-links">
<li>
<a href="https://github.com/GoogleCloudPlatform/gcloud-python/" title="Python on Github">
<img src="_landing-page-static/images/icon-link-github.svg" alt="Github icon" />
Github
</a>
</li>
<li>
<a href="https://github.com/GoogleCloudPlatform/gcloud-python/issues" title="Python issues on Github">
<img src="_landing-page-static/images/icon-link-github.svg" alt="Github icon" />
Issues
</a>
</li>
<li>
<a href="http://stackoverflow.com/questions/tagged/gcloud-python" title="gcloud on StackOverflow">
<img src="_landing-page-static/images/icon-link-stackoverflow.svg" alt="StackOverflow icon" />
gcloud
</a>
</li>
<li>
<a href="https://pypi.python.org/pypi/gcloud" title="Python package manager">
<img src="_landing-page-static/images/icon-link-package-manager.svg" alt="Package Manager icon" />
Package Manager
</a>
</li>
</ul>
</nav><!-- end of .side-nav -->
</article><!-- end of .main -->

<script src="_landing-page-static/js/vendor/jquery-1.10.2.min.js"></script>
<script src="_landing-page-static/js/plugins.js"></script>
<script src="_landing-page-static/js/main.js"></script>

</body>
</html>

0 comments on commit bee3745

Please sign in to comment.