2 # -*- coding: utf-8 -*-
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
10 # Full author contact details are available in file CREDITS
12 # This script converts documentation .lyx files to current format
13 # The old files are backuped with extension ".old"
16 import os, re, string, sys, subprocess, shutil
17 from gen_lfuns import main as genlfuns
20 def convertdir(docdir, prefix, lyx2lyx, lyx, systemlyxdir):
23 for i in os.listdir("."):
26 subdir = os.path.join(docdir, i)
27 subprefix = os.path.join(prefix, i)
28 convertdir(subdir, subprefix, lyx2lyx, lyx, systemlyxdir)
30 (base, ext) = os.path.splitext(i)
35 if sys.executable and sys.executable != '':
36 cmd = [sys.executable, lyx2lyx, old, '-s', systemlyxdir, '-o', i]
38 # assume that python is in the path
39 cmd = [lyx2lyx, old, '-s', systemlyxdir, '-o', i]
40 sys.stderr.write('Converting %s\n' % os.path.join(prefix, i))
43 cmd = [lyx, '-f', '-x', 'command-sequence buffer-write force; lyx-quit', i]
50 toolsdir = os.path.dirname(argv[0])
52 # first generate LFUNs.lyx
53 lyxaction = os.path.abspath(os.path.join(toolsdir, "../../src/LyXAction.cpp"))
54 lfunspath = os.path.abspath(os.path.join(toolsdir, "../../lib/doc"))
55 lfuns = os.path.join(lfunspath, "LFUNs.lyx")
56 # genlfuns refuses to overwrite files
57 if os.path.exists(lfuns):
58 os.rename(lfuns, os.path.join(lfunspath, "LFUNs.lyx.old"))
59 # genlfuns requires a trailing slash
60 genlfuns(["genlfuns", lyxaction, lfunspath + os.sep])
62 # then update all docs
63 lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
64 systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
66 sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
67 lyx = os.path.abspath(argv[1])
70 docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
71 for docpath in docpaths:
72 docdir = os.path.abspath(os.path.join(toolsdir, docpath))
73 convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
78 if __name__ == "__main__":