Skip to content

Commit b89f9de

Browse files
committed
Merge pull request #662 from dhermes/versions-update
Adding update stage for static versions page in docs.
2 parents 72b6359 + fd0e143 commit b89f9de

File tree

5 files changed

+205
-1
lines changed

5 files changed

+205
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ regression/local_test_setup
4949
# Make sure a generated file isn't accidentally committed.
5050
pylintrc_reduced
5151

52-
# Wheel directory used in Travis builds.
52+
# Travis build directories.
5353
gcloud-python-wheels/
54+
ghpages/

scripts/get_version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Copyright 2014 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
"""Simple script to get the gcloud version."""
16+
217
from pkg_resources import get_distribution
318
print get_distribution('gcloud').version

scripts/update_docs.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ else
5151
# Put the new release in latest and with the actual version.
5252
cp -R ../docs/_build/html/ latest/
5353
cp -R ../docs/_build/html/ "${CURRENT_VERSION}/"
54+
55+
# Also update the versions file.
56+
../.tox/docs/bin/python ../scripts/update_versions.py
57+
# Update the files which were updated in the release.
58+
git add versions.html versions.json
5459
fi
5560

5661
# Update the files push to gh-pages.

scripts/update_versions.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2014 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Simple script to update the gcloud versions list and file."""
16+
17+
import json
18+
import os
19+
from pkg_resources import get_distribution
20+
21+
22+
LI_TEMPLATE = '<li><a href="%s/index.html">%s</a></li>'
23+
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
24+
GH_PAGES_DIR = os.path.abspath(os.path.join(SCRIPTS_DIR, '..', 'ghpages'))
25+
VERSIONS_TMPL = os.path.join(SCRIPTS_DIR, 'versions.html.template')
26+
JSON_VERSIONS = os.path.join(GH_PAGES_DIR, 'versions.json')
27+
VERSIONS_FILE = os.path.join(GH_PAGES_DIR, 'versions.html')
28+
29+
30+
def update_versions(new_version):
31+
"""Updates JSON file with list of versions.
32+
33+
Reads and writes JSON to ``JSON_VERSIONS`` file. Does not write
34+
if ``new_version`` is already contained.
35+
36+
:type new_version: string
37+
:param new_version: New version being added.
38+
39+
:rtype: list of strings
40+
:returns: List of all versions.
41+
"""
42+
with open(JSON_VERSIONS, 'r') as file_obj:
43+
versions = json.load(file_obj)
44+
45+
if new_version not in versions:
46+
versions.insert(0, new_version)
47+
48+
with open(JSON_VERSIONS, 'w') as file_obj:
49+
json.dump(versions, file_obj)
50+
51+
return versions
52+
53+
54+
def render_template(new_version):
55+
"""Renders static versions page.
56+
57+
:type new_version: string
58+
:param new_version: New version being added.
59+
60+
:rtype: string
61+
:returns: Rendered versions page.
62+
"""
63+
versions = update_versions(new_version)
64+
65+
with open(VERSIONS_TMPL, 'r') as file_obj:
66+
page_template = file_obj.read()
67+
68+
versions_list = '\n'.join([LI_TEMPLATE % (version, version)
69+
for version in versions])
70+
71+
return page_template.format(versions=versions_list)
72+
73+
74+
def main():
75+
"""Creates new versions.html template."""
76+
new_version = get_distribution('gcloud').version
77+
rendered = render_template(new_version)
78+
with open(VERSIONS_FILE, 'w') as file_obj:
79+
file_obj.write(rendered)
80+
81+
82+
if __name__ == '__main__':
83+
main()

scripts/versions.html.template

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!DOCTYPE html>
2+
3+
<html xmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
7+
<title>gcloud-python Versions</title>
8+
9+
<link rel="stylesheet" href="_landing-page-static/css/docs-main.css" type="text/css" />
10+
<link rel="stylesheet" href="_landing-page-static/pygments.css" type="text/css" />
11+
<link rel="stylesheet" href="_landing-page-static/css/normalize.css" type="text/css" />
12+
<link rel="stylesheet" href="_landing-page-static/css/github.min.css" type="text/css" />
13+
14+
<script type="text/javascript" src="_landing-page-static/js/vendor/modernizr-2.6.2.min.js"></script>
15+
<link rel="shortcut icon" href="_landing-page-static/favicon.ico"/>
16+
<link rel="top" title="gcloud-python Versions" href="#" />
17+
</head>
18+
<body>
19+
<header class="page-header fixed" role="banner">
20+
<h1 class="logo">
21+
<a href="index.html" title="back to home">
22+
<img src="_landing-page-static/images/logo.svg" alt="Google Cloud Platform" />
23+
<span class="gcloud">gcloud</span>
24+
</a>
25+
</h1>
26+
<nav class="main-nav">
27+
<div class="nav-current">Python</div>
28+
<ul class="menu">
29+
<li>
30+
<a href="
31+
https://googlecloudplatform.github.io/gcloud-node" title="Node.js docs page">
32+
<img src="_landing-page-static/images/icon-lang-nodejs.svg" alt="Node.js icon" class="menu-icon" />
33+
Node.js
34+
</a>
35+
</li>
36+
<li>
37+
<a href="#" title="Python docs page">
38+
<img src="_landing-page-static/images/icon-lang-python-white.svg" alt="Python icon" class="menu-icon" />
39+
Python
40+
</a>
41+
</li>
42+
</ul>
43+
</nav><!-- end of .main-nav -->
44+
</header><!-- end of .page-header -->
45+
46+
<article class="main lang-page" role="main">
47+
48+
<header class="docs-header">
49+
<h1 class="page-title">Versions</h1>
50+
</header>
51+
52+
<section class="content">
53+
54+
<div class="toctree-wrapper compound">
55+
</div>
56+
<ul id="versions">
57+
{versions}
58+
</ul>
59+
60+
</section><!-- end of .content -->
61+
<nav class="side-nav">
62+
<ul><li><a href="latest/index.html">Documentation</a></li></ul>
63+
<ul class="simple">
64+
</ul>
65+
66+
<ul class="external-links">
67+
<li>
68+
<a href="https://github.com/GoogleCloudPlatform/gcloud-python/" title="Python on Github">
69+
<img src="_landing-page-static/images/icon-link-github.svg" alt="Github icon" />
70+
Github
71+
</a>
72+
</li>
73+
<li>
74+
<a href="https://github.com/GoogleCloudPlatform/gcloud-python/issues" title="Python issues on Github">
75+
<img src="_landing-page-static/images/icon-link-github.svg" alt="Github icon" />
76+
Issues
77+
</a>
78+
</li>
79+
<li>
80+
<a href="http://stackoverflow.com/questions/tagged/gcloud-python" title="gcloud on StackOverflow">
81+
<img src="_landing-page-static/images/icon-link-stackoverflow.svg" alt="StackOverflow icon" />
82+
gcloud
83+
</a>
84+
</li>
85+
<li>
86+
<a href="https://pypi.python.org/pypi/gcloud" title="Python package manager">
87+
<img src="_landing-page-static/images/icon-link-package-manager.svg" alt="Package Manager icon" />
88+
Package Manager
89+
</a>
90+
</li>
91+
</ul>
92+
</nav><!-- end of .side-nav -->
93+
</article><!-- end of .main -->
94+
95+
<script src="_landing-page-static/js/vendor/jquery-1.10.2.min.js"></script>
96+
<script src="_landing-page-static/js/plugins.js"></script>
97+
<script src="_landing-page-static/js/main.js"></script>
98+
99+
</body>
100+
</html>

0 commit comments

Comments
 (0)