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
19 def convertdir(docdir, prefix, lyx2lyx, lyx, systemlyxdir):
22 for i in os.listdir("."):
25 subdir = os.path.join(docdir, i)
26 subprefix = os.path.join(prefix, i)
27 convertdir(subdir, subprefix, lyx2lyx, lyx, systemlyxdir)
29 (base, ext) = os.path.splitext(i)
34 if sys.executable and sys.executable != '':
35 cmd = [sys.executable, lyx2lyx, old, '-s', systemlyxdir, '-o', i]
37 # assume that python is in the path
38 cmd = [lyx2lyx, old, '-s', systemlyxdir, '-o', i]
39 sys.stderr.write('Converting %s\n' % os.path.join(prefix, i))
42 # This is a hack, but without modifying the doc LyX refuses to save and stays open
43 # FIXME: Is self-insert a; char-delete-backward always a noop?
44 # What if change-tracking is enabled?
45 cmd = [lyx, '-f', '-x', 'command-sequence self-insert a; char-delete-backward; buffer-write; lyx-quit', i]
52 toolsdir = os.path.dirname(argv[0])
53 lyx2lyx = os.path.abspath(os.path.join(toolsdir, "../../lib/lyx2lyx/lyx2lyx"))
54 systemlyxdir = os.path.abspath(os.path.join(toolsdir, "../../lib"))
56 sys.stderr.write('Warning: Converting with LyX is experimental. Check the results carefully.\n'))
57 lyx = os.path.abspath(argv[1])
60 docpaths = ['../../lib/doc', '../../lib/examples', '../../lib/templates', '../../development/MacOSX/ReadMe']
61 for docpath in docpaths:
62 docdir = os.path.abspath(os.path.join(toolsdir, docpath))
63 convertdir(docdir, '', lyx2lyx, lyx, systemlyxdir)
68 if __name__ == "__main__":