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 # This is a hack, but without modifying the doc LyX refuses to save and stays open
44 # FIXME: Is self-insert a; char-delete-backward always a noop?
45 # What if change-tracking is enabled?
46 cmd = [lyx, '-f', '-x', 'command-sequence self-insert a; char-delete-backward; buffer-write; lyx-quit', i]
53 toolsdir = os.path.dirname(argv[0])
55 # first generate LFUNs.lyx
56 lyxaction = os.path.abspath(os.path.join(toolsdir, "../../src/LyXAction.cpp"))
57 lfunspath = os.path.abspath(os.path.join(toolsdir, "../../lib/doc"))
58 lfuns = os.path.join(lfunspath, "LFUNs.lyx")
59 # genlfuns refuses to overwrite files
60 if os.path.exists(lfuns):
61 os.rename(lfuns, os.path.join(lfunspath, "LFUNs.lyx.old"))
62 # genlfuns requires a trailing slash
63 genlfuns(["genlfuns", lyxaction, lfunspath + os.sep])
65 # then update all docs
66 lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
67 systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
69 sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n')
70 lyx = os.path.abspath(argv[1])
73 docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
74 for docpath in docpaths:
75 docdir = os.path.abspath(os.path.join(toolsdir, docpath))
76 convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
81 if __name__ == "__main__":