parent
ec487dd6b1
commit
09526ad715
@ -32,29 +32,45 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
|||||||
from scripts import utils
|
from scripts import utils
|
||||||
|
|
||||||
|
|
||||||
def call_asciidoc(src, dst):
|
def _get_asciidoc_cmd(args):
|
||||||
|
"""Try to find out what commandline to use to invoke asciidoc."""
|
||||||
|
if args.asciidoc is not None:
|
||||||
|
return args.asciidoc
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.call(['asciidoc'], stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ['asciidoc']
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.call(['asciidoc.py'], stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ['asciidoc.py']
|
||||||
|
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
|
||||||
|
def call_asciidoc(args, src, dst):
|
||||||
"""Call asciidoc for the given files.
|
"""Call asciidoc for the given files.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
args: The asciidoc binary to use, as a list.
|
||||||
src: The source .asciidoc file.
|
src: The source .asciidoc file.
|
||||||
dst: The destination .html file, or None to auto-guess.
|
dst: The destination .html file, or None to auto-guess.
|
||||||
"""
|
"""
|
||||||
print("Calling asciidoc for {}...".format(os.path.basename(src)))
|
print("Calling asciidoc for {}...".format(os.path.basename(src)))
|
||||||
if os.name == 'nt':
|
args = args[:]
|
||||||
# FIXME this is highly specific to my machine
|
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/106
|
|
||||||
args = [r'C:\Python27\python', r'J:\bin\asciidoc-8.6.9\asciidoc.py']
|
|
||||||
else:
|
|
||||||
args = ['asciidoc']
|
|
||||||
if dst is not None:
|
if dst is not None:
|
||||||
args += ['--out-file', dst]
|
args += ['--out-file', dst]
|
||||||
args.append(src)
|
args.append(src)
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(args)
|
subprocess.check_call(args)
|
||||||
except FileNotFoundError:
|
|
||||||
utils.print_col("asciidoc needs to be installed to use this script!",
|
|
||||||
'red')
|
|
||||||
sys.exit(1)
|
|
||||||
except (subprocess.CalledProcessError, OSError) as e:
|
except (subprocess.CalledProcessError, OSError) as e:
|
||||||
utils.print_col(str(e), 'red')
|
utils.print_col(str(e), 'red')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -67,6 +83,10 @@ def main(colors=False):
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--all', help="Build all documentation into a given "
|
parser.add_argument('--all', help="Build all documentation into a given "
|
||||||
"directory.", nargs=1)
|
"directory.", nargs=1)
|
||||||
|
parser.add_argument('--asciidoc', help="Full path to python and "
|
||||||
|
"asciidoc.py. If not given, it's searched in PATH.",
|
||||||
|
nargs=2, required=False,
|
||||||
|
metavar=('PYTHON', 'ASCIIDOC'))
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
asciidoc_files = [
|
asciidoc_files = [
|
||||||
('doc/FAQ.asciidoc', 'qutebrowser/html/doc/FAQ.html'),
|
('doc/FAQ.asciidoc', 'qutebrowser/html/doc/FAQ.html'),
|
||||||
@ -77,6 +97,13 @@ def main(colors=False):
|
|||||||
os.mkdir('qutebrowser/html/doc')
|
os.mkdir('qutebrowser/html/doc')
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
asciidoc = _get_asciidoc_cmd(args)
|
||||||
|
except FileNotFoundError:
|
||||||
|
utils.print_col("Could not find asciidoc! Please install it, or use "
|
||||||
|
"the --asciidoc argument to point this script to the "
|
||||||
|
"correct python/asciidoc.py location!", 'red')
|
||||||
|
sys.exit(1)
|
||||||
if args.all:
|
if args.all:
|
||||||
for root, _dirs, files in os.walk(os.getcwd()):
|
for root, _dirs, files in os.walk(os.getcwd()):
|
||||||
for filename in files:
|
for filename in files:
|
||||||
@ -92,14 +119,14 @@ def main(colors=False):
|
|||||||
'html')))
|
'html')))
|
||||||
dst = os.path.join(*parts)
|
dst = os.path.join(*parts)
|
||||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||||
call_asciidoc(src, dst)
|
call_asciidoc(asciidoc, src, dst)
|
||||||
else:
|
else:
|
||||||
for src in glob.glob('doc/help/*.asciidoc'):
|
for src in glob.glob('doc/help/*.asciidoc'):
|
||||||
name, _ext = os.path.splitext(os.path.basename(src))
|
name, _ext = os.path.splitext(os.path.basename(src))
|
||||||
dst = 'qutebrowser/html/doc/{}.html'.format(name)
|
dst = 'qutebrowser/html/doc/{}.html'.format(name)
|
||||||
asciidoc_files.append((src, dst))
|
asciidoc_files.append((src, dst))
|
||||||
for src, dst in asciidoc_files:
|
for src, dst in asciidoc_files:
|
||||||
call_asciidoc(src, dst)
|
call_asciidoc(asciidoc, src, dst)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user