Skip to content

Instantly share code, notes, and snippets.

@bmbouter
Created July 26, 2017 17:09
Show Gist options
  • Select an option

  • Save bmbouter/dc4871b87456e427dbb697c4bb82102e to your computer and use it in GitHub Desktop.

Select an option

Save bmbouter/dc4871b87456e427dbb697c4bb82102e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python26
# python26 docs-fixer.py /path/to/docs/html
# originally made by github user werwty.
import os
import sys
inserted_html="""
<script>
$( document ).ready( function() {
// gets version number minus whitespace and bugfix version
var $version_number = $('.version').text().trim().split('.', 2).join('.')
// div mirroring the admonition-warning generated by sphinx if added to .rst
var warning = '\
<div class="admonition warning"> \
<p class="first admonition-title">Warning</p> \
<p class="last">You are looking at the docs for an unsupported version of Pulp. \
Consider switching to a \
<a href="http://pulpproject.org/docs/">supported version</a></p> \
</div>'
// get JSON from server and load supported_versions
$.getJSON("https://raw.githubusercontent.com/pulp/pulp_packaging/master/ci/config/releases/supported-releases.json" , function(data) {
if ($.inArray($version_number, data) === -1) {
$('.rst-content').prepend(warning)
}
})
})
</script>
</html>
"""
def replace_html(root_dir):
for directory, subdirectories, files in os.walk(root_dir):
for file in files:
extension = os.path.splitext(file)[1]
if extension == '.html':
print(file)
f = open(os.path.join(directory, file), 'r')
filedata = f.read()
f.close()
if filedata.find('</html>') == -1:
raise Exception("didn't match html")
if filedata.find('supported-releases') != -1:
raise Exception("already matched this")
newdata = filedata.replace('</html>',inserted_html)
f = open(os.path.join(directory, file), 'w')
f.write(newdata)
f.close()
replace_html(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment