forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding update stage for static versions page in docs.
Relates to googleapis#472
- Loading branch information
Showing
5 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
# Copyright 2014 Google Inc. All rights reserved. | ||
# | ||
# 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. | ||
|
||
"""Simple script to get the gcloud version.""" | ||
|
||
from pkg_resources import get_distribution | ||
print get_distribution('gcloud').version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2014 Google Inc. All rights reserved. | ||
# | ||
# 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. | ||
|
||
"""Simple script to update the gcloud versions list and file.""" | ||
|
||
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): | ||
"""Updates JSON file with list of versions. | ||
Reads and writes JSON to ``JSON_VERSIONS`` file. Does not write | ||
if ``new_version`` is already contained. | ||
:type new_version: string | ||
:param new_version: New version being added. | ||
:rtype: list of strings | ||
:returns: List of all versions. | ||
""" | ||
with open(JSON_VERSIONS, 'r') as file_obj: | ||
versions = json.load(file_obj) | ||
|
||
if new_version not in 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): | ||
"""Renders static versions page. | ||
:type new_version: string | ||
:param new_version: New version being added. | ||
:rtype: string | ||
:returns: Rendered versions page. | ||
""" | ||
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(): | ||
"""Creates new versions.html template.""" | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |