Check if docs are up to date if running from git repo.

This commit is contained in:
Florian Bruhin 2014-09-21 22:15:56 +02:00
parent ce6778f1d5
commit def417b8a5
2 changed files with 36 additions and 1 deletions

View File

@ -31,7 +31,7 @@ from PyQt5.QtNetwork import QNetworkReply
import qutebrowser
from qutebrowser.network import schemehandler
from qutebrowser.utils import version, utils, jinja, log
from qutebrowser.utils import version, utils, jinja, log, message
pyeval_output = ":pyeval was never called"
@ -137,6 +137,11 @@ def qute_help(request):
urlpath = request.url().path()
if not urlpath or urlpath == '/':
urlpath = 'index.html'
else:
urlpath = urlpath.lstrip('/')
if not utils.docs_up_to_date(urlpath):
message.error("Your documentation is outdated! Please re-run scripts/"
"asciidoc2html.py.")
path = 'html/doc/{}'.format(urlpath)
return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace')

View File

@ -507,6 +507,36 @@ def is_enum(obj):
return False
def is_git_repo():
"""Check if we're running from a git repository."""
gitfolder = os.path.join(qutebrowser.basedir, os.path.pardir, '.git')
return os.path.isdir(gitfolder)
def docs_up_to_date(path):
"""Check if the generated html documentation is up to date.
Args:
path: The path of the document to check.
Return:
True if they are up to date or we couldn't check.
False if they are outdated.
"""
if hasattr(sys, 'frozen') or not is_git_repo():
return True
html_path = os.path.join(qutebrowser.basedir, 'html', 'doc', path)
filename = os.path.splitext(path)[0]
asciidoc_path = os.path.join(qutebrowser.basedir, os.path.pardir,
'doc', 'help', filename + '.asciidoc')
try:
html_time = os.path.getmtime(html_path)
asciidoc_time = os.path.getmtime(asciidoc_path)
except FileNotFoundError:
return True
return asciidoc_time <= html_time
class DocstringParser:
"""Generate documentation based on a docstring of a command handler.