2018-12-29 19:14:41 +00:00
|
|
|
#! /usr/bin/python3
|
2015-11-11 19:41:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# file updatedocs.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
|
|
|
# author Georg Baum
|
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS
|
|
|
|
|
|
|
|
# This script converts documentation .lyx files to current format
|
|
|
|
# The old files are backuped with extension ".old"
|
|
|
|
|
|
|
|
|
|
|
|
import os, re, string, sys, subprocess, shutil
|
2016-01-16 10:08:22 +00:00
|
|
|
from gen_lfuns import main as genlfuns
|
2015-11-11 19:41:28 +00:00
|
|
|
|
|
|
|
|
2015-11-14 09:14:59 +00:00
|
|
|
def convertdir(docdir, prefix, lyx2lyx, lyx, systemlyxdir):
|
2015-11-11 19:41:28 +00:00
|
|
|
olddir = os.getcwd()
|
|
|
|
os.chdir(docdir)
|
|
|
|
for i in os.listdir("."):
|
|
|
|
if os.path.isdir(i):
|
2015-11-11 19:50:40 +00:00
|
|
|
if i != 'attic':
|
|
|
|
subdir = os.path.join(docdir, i)
|
|
|
|
subprefix = os.path.join(prefix, i)
|
2015-11-14 09:14:59 +00:00
|
|
|
convertdir(subdir, subprefix, lyx2lyx, lyx, systemlyxdir)
|
2015-11-11 19:41:28 +00:00
|
|
|
continue
|
|
|
|
(base, ext) = os.path.splitext(i)
|
|
|
|
if ext != ".lyx":
|
|
|
|
continue
|
|
|
|
old = i + ".old"
|
|
|
|
shutil.copy(i, old)
|
|
|
|
if sys.executable and sys.executable != '':
|
2015-11-11 20:35:12 +00:00
|
|
|
cmd = [sys.executable, lyx2lyx, old, '-s', systemlyxdir, '-o', i]
|
2015-11-11 19:41:28 +00:00
|
|
|
else:
|
|
|
|
# assume that python is in the path
|
2015-11-11 20:35:12 +00:00
|
|
|
cmd = [lyx2lyx, old, '-s', systemlyxdir, '-o', i]
|
2015-11-11 19:41:28 +00:00
|
|
|
sys.stderr.write('Converting %s\n' % os.path.join(prefix, i))
|
|
|
|
subprocess.call(cmd)
|
2015-11-14 09:14:59 +00:00
|
|
|
if lyx != '':
|
2022-12-20 17:42:34 +00:00
|
|
|
cmd = [lyx, '-f', '-x', 'command-sequence buffer-write force; lyx-quit', i]
|
2015-11-14 09:14:59 +00:00
|
|
|
subprocess.call(cmd)
|
2015-11-11 19:41:28 +00:00
|
|
|
os.chdir(olddir)
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
|
|
|
|
toolsdir = os.path.dirname(argv[0])
|
2016-01-16 10:08:22 +00:00
|
|
|
|
|
|
|
# first generate LFUNs.lyx
|
|
|
|
lyxaction = os.path.abspath(os.path.join(toolsdir, "../../src/LyXAction.cpp"))
|
|
|
|
lfunspath = os.path.abspath(os.path.join(toolsdir, "../../lib/doc"))
|
|
|
|
lfuns = os.path.join(lfunspath, "LFUNs.lyx")
|
|
|
|
# genlfuns refuses to overwrite files
|
|
|
|
if os.path.exists(lfuns):
|
|
|
|
os.rename(lfuns, os.path.join(lfunspath, "LFUNs.lyx.old"))
|
|
|
|
# genlfuns requires a trailing slash
|
|
|
|
genlfuns(["genlfuns", lyxaction, lfunspath + os.sep])
|
|
|
|
|
|
|
|
# then update all docs
|
2015-11-11 19:41:28 +00:00
|
|
|
lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
|
2015-11-11 20:35:12 +00:00
|
|
|
systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
|
2015-11-14 09:14:59 +00:00
|
|
|
if len(argv) > 1:
|
2015-11-27 07:37:27 +00:00
|
|
|
sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
|
2015-11-14 09:14:59 +00:00
|
|
|
lyx = os.path.abspath(argv[1])
|
|
|
|
else:
|
|
|
|
lyx = ''
|
2015-11-13 17:59:28 +00:00
|
|
|
docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
|
|
|
|
for docpath in docpaths:
|
|
|
|
docdir = os.path.abspath(os.path.join(toolsdir, docpath))
|
2015-11-14 09:14:59 +00:00
|
|
|
convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
|
2015-11-11 19:41:28 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv)
|